diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/AbstractImComponentDataˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/AbstractImComponentDataˣᴹᴵ.java new file mode 100644 index 00000000..2a75818a --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/AbstractImComponentDataˣᴹᴵ.java @@ -0,0 +1,29 @@ +package love.distributedrebirth.imxmi.lang; + +import java.util.function.Function; + +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +abstract public class AbstractImComponentDataˣᴹᴵ implements ImComponentDataˣᴹᴵ { + + private Function dataExtractor; + + @Override + public void setDataExtractor(Function dataExtractor) { + this.dataExtractor = dataExtractor; + } + + @Override + public Function getDataExtractor() { + return dataExtractor; + } + + @Override + public void renderBegin() { + } + + @Override + public void renderEnd() { + } +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImButtonˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImButtonˣᴹᴵ.java index e63cf4a5..97f4ef28 100644 --- a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImButtonˣᴹᴵ.java +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImButtonˣᴹᴵ.java @@ -1,8 +1,41 @@ package love.distributedrebirth.imxmi.lang; +import imgui.ImGui; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") -public class ImButtonˣᴹᴵ { - +public class ImButtonˣᴹᴵ extends AbstractImComponentˣᴹᴵ { + + private String label; + private Runnable callback; + + public ImButtonˣᴹᴵ() { + } + + public ImButtonˣᴹᴵ(String label) { + setLabel(label); + } + + @Override + public void renderComponent() { + if (ImGui.button(label) && callback != null) { + callback.run(); + } + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Runnable getCallback() { + return callback; + } + + public void setCallback(Runnable callback) { + this.callback = callback; + } } diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComboˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComboˣᴹᴵ.java new file mode 100644 index 00000000..fc3e4099 --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComboˣᴹᴵ.java @@ -0,0 +1,56 @@ +package love.distributedrebirth.imxmi.lang; + +import imgui.ImGui; +import imgui.type.ImInt; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class ImComboˣᴹᴵ extends AbstractImComponentˣᴹᴵ { + + private String label; + private final ImInt currentItem = new ImInt(); + private String[] items; + private Runnable callback; + + public ImComboˣᴹᴵ() { + } + + public ImComboˣᴹᴵ(String label) { + setLabel(label); + } + + @Override + public void renderComponent() { + if (ImGui.combo(label, currentItem, items) && callback != null) { + callback.run(); + } + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Runnable getCallback() { + return callback; + } + + public void setCallback(Runnable callback) { + this.callback = callback; + } + + public ImInt getCurrentItem() { + return currentItem; + } + + public String[] getItems() { + return items; + } + + public void setItems(String[] items) { + this.items = items; + } +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComponentDataˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComponentDataˣᴹᴵ.java new file mode 100644 index 00000000..4e18f1e5 --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImComponentDataˣᴹᴵ.java @@ -0,0 +1,15 @@ +package love.distributedrebirth.imxmi.lang; + +import java.util.function.Function; + +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public interface ImComponentDataˣᴹᴵ extends ImComponentˣᴹᴵ { + + void setDataExtractor(Function dataExtractor); + + Function getDataExtractor(); + + void setData(Object value); +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSameLineˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSameLineˣᴹᴵ.java new file mode 100644 index 00000000..c4e51468 --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSameLineˣᴹᴵ.java @@ -0,0 +1,16 @@ +package love.distributedrebirth.imxmi.lang; + +import imgui.ImGui; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class ImSameLineˣᴹᴵ extends AbstractImComponentˣᴹᴵ { + + public ImSameLineˣᴹᴵ() { + } + + @Override + public void renderComponent() { + ImGui.sameLine(); + } +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSeparatorˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSeparatorˣᴹᴵ.java new file mode 100644 index 00000000..9a1d1c3a --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImSeparatorˣᴹᴵ.java @@ -0,0 +1,16 @@ +package love.distributedrebirth.imxmi.lang; + +import imgui.ImGui; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class ImSeparatorˣᴹᴵ extends AbstractImComponentˣᴹᴵ { + + public ImSeparatorˣᴹᴵ() { + } + + @Override + public void renderComponent() { + ImGui.separator(); + } +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTableˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTableˣᴹᴵ.java new file mode 100644 index 00000000..b0733c98 --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTableˣᴹᴵ.java @@ -0,0 +1,71 @@ +package love.distributedrebirth.imxmi.lang; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +import imgui.ImGui; +import imgui.flag.ImGuiTableFlags; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class ImTableˣᴹᴵ extends AbstractImComponentˣᴹᴵ { + + private String id; + private int flags; + private List columns; + private Supplier> dataSupplier; + private List components = new ArrayList<>(); + + + public ImTableˣᴹᴵ() { + this(null); + } + + public ImTableˣᴹᴵ(String id) { + this.id = id; + this.columns = new ArrayList<>(); + this.flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; + } + + @Override + public void renderBegin() { + ImGui.beginTable(id, columns.size(), flags); + for (String column:columns) { + ImGui.tableSetupColumn(column); + } + ImGui.tableHeadersRow(); + } + + @Override + public void renderComponent() { + List rows = dataSupplier.get(); + for (Object row:rows) { + ImGui.tableNextRow(); + for (ImComponentDataˣᴹᴵ comp:getComponents()) { + ImGui.tableNextColumn(); + comp.setData(row); + comp.renderBegin(); + comp.renderComponent(); + comp.renderEnd(); + } + } + } + + @Override + public void renderEnd() { + ImGui.endTable(); + } + + public void addComponent(ImComponentDataˣᴹᴵ comp) { + components.add(comp); + } + + public void removeComponent(ImComponentDataˣᴹᴵ comp) { + components.remove(comp); + } + + public List getComponents() { + return components; + } +} diff --git a/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTextDataˣᴹᴵ.java b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTextDataˣᴹᴵ.java new file mode 100644 index 00000000..b5e962a5 --- /dev/null +++ b/lib-imxmi/src/main/love/distributedrebirth/imxmi/lang/ImTextDataˣᴹᴵ.java @@ -0,0 +1,29 @@ +package love.distributedrebirth.imxmi.lang; + +import java.util.function.Function; + +import imgui.ImGui; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class ImTextDataˣᴹᴵ extends AbstractImComponentDataˣᴹᴵ { + + private String text; + + public ImTextDataˣᴹᴵ() { + } + + public ImTextDataˣᴹᴵ(Function dataExtractor) { + setDataExtractor(dataExtractor); + } + + @Override + public void renderComponent() { + ImGui.text(text); + } + + @Override + public void setData(Object value) { + text = String.class.cast(getDataExtractor().apply(value)); + } +}