[API] Move extensions into separate package

This commit is contained in:
SpaiR committed 2021-01-23 16:28:41 +02:00
1 parent 70ac8e70c5
commit 9e8f9ee025
17 files changed
+70 -69

No files matched your search

@@ -1,6 +1,7 @@
package imgui.imnodes; package imgui.extension.imnodes;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.extension.imnodes.flag.ImNodesPinShape;
import imgui.type.ImBoolean; import imgui.type.ImBoolean;
import imgui.type.ImInt; import imgui.type.ImInt;
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
import imgui.binding.ImGuiStructDestroyable; import imgui.binding.ImGuiStructDestroyable;
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
import imgui.binding.ImGuiStruct; import imgui.binding.ImGuiStruct;
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
/** /**
* This enum controls the way the attribute pins behave. * This enum controls the way the attribute pins behave.
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
public final class ImNodesColorStyle { public final class ImNodesColorStyle {
private ImNodesColorStyle() { private ImNodesColorStyle() {
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
/** /**
* This enum controls the way attribute pins look. * This enum controls the way attribute pins look.
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
public final class ImNodesStyleFlags { public final class ImNodesStyleFlags {
private ImNodesStyleFlags() { private ImNodesStyleFlags() {
@@ -1,4 +1,4 @@
package imgui.imnodes; package imgui.extension.imnodes;
public final class ImNodesStyleVar { public final class ImNodesStyleVar {
private ImNodesStyleVar() { private ImNodesStyleVar() {
@@ -1,4 +1,4 @@
package imgui.nodeditor; package imgui.extension.nodeditor;
import imgui.ImDrawList; import imgui.ImDrawList;
import imgui.ImVec2; import imgui.ImVec2;
@@ -20,14 +20,14 @@ import imgui.type.ImLong;
* Binding notice: instead of special types for ids of nodes, links and pins which used in native library * Binding notice: instead of special types for ids of nodes, links and pins which used in native library
* we use longs to reduce boilerplate and garbage production * we use longs to reduce boilerplate and garbage production
*/ */
public final class ImNodeEditor { public final class NodeEditor {
private static final ImDrawList HINT_FOREGROUND_DRAW_LIST = new ImDrawList(0); private static final ImDrawList HINT_FOREGROUND_DRAW_LIST = new ImDrawList(0);
private static final ImDrawList HINT_BACKGROUND_DRAW_LIST = new ImDrawList(0); private static final ImDrawList HINT_BACKGROUND_DRAW_LIST = new ImDrawList(0);
private static final ImDrawList NODE_BACKGROUND_DRAW_LIST = new ImDrawList(0); private static final ImDrawList NODE_BACKGROUND_DRAW_LIST = new ImDrawList(0);
private static ImNodeEditorStyle style; private static NodeEditorStyle style;
private ImNodeEditor() { private NodeEditor() {
} }
/*JNI /*JNI
@@ -43,22 +43,22 @@ public final class ImNodeEditor {
/** /**
* This method exists for api consistency and you can just call NodeEditorContext manually * This method exists for api consistency and you can just call NodeEditorContext manually
*/ */
public static ImNodeEditorContext createEditor() { public static NodeEditorContext createEditor() {
return new ImNodeEditorContext(); return new NodeEditorContext();
} }
public static ImNodeEditorContext createEditor(final ImNodeEditorConfig config) { public static NodeEditorContext createEditor(final NodeEditorConfig config) {
return new ImNodeEditorContext(config); return new NodeEditorContext(config);
} }
/** /**
* This method exists for api consistency and you can just call NodeEditorContext.destroy() manually * This method exists for api consistency and you can just call NodeEditorContext.destroy() manually
*/ */
public static void destroyEditor(final ImNodeEditorContext editorContext) { public static void destroyEditor(final NodeEditorContext editorContext) {
editorContext.destroy(); editorContext.destroy();
} }
public static void setCurrentEditor(final ImNodeEditorContext editorContext) { public static void setCurrentEditor(final NodeEditorContext editorContext) {
nSetCurrentEditor(editorContext.ptr); nSetCurrentEditor(editorContext.ptr);
} }
@@ -127,9 +127,9 @@ public final class ImNodeEditor {
return ed::CanvasToScreen(ImVec2(0.0f, canvasSpacePosY)).y; return ed::CanvasToScreen(ImVec2(0.0f, canvasSpacePosY)).y;
*/ */
public static ImNodeEditorStyle getStyle() { public static NodeEditorStyle getStyle() {
if (style == null) { if (style == null) {
style = new ImNodeEditorStyle(nGetStyle()); style = new NodeEditorStyle(nGetStyle());
} }
return style; return style;
} }
@@ -1,12 +1,12 @@
package imgui.nodeditor; package imgui.extension.nodeditor;
import imgui.binding.ImGuiStructDestroyable; import imgui.binding.ImGuiStructDestroyable;
public final class ImNodeEditorConfig extends ImGuiStructDestroyable { public final class NodeEditorConfig extends ImGuiStructDestroyable {
public ImNodeEditorConfig() { public NodeEditorConfig() {
} }
public ImNodeEditorConfig(final long ptr) { public NodeEditorConfig(final long ptr) {
super(ptr); super(ptr);
} }
@@ -1,16 +1,16 @@
package imgui.nodeditor; package imgui.extension.nodeditor;
import imgui.binding.ImGuiStructDestroyable; import imgui.binding.ImGuiStructDestroyable;
public final class ImNodeEditorContext extends ImGuiStructDestroyable { public final class NodeEditorContext extends ImGuiStructDestroyable {
public ImNodeEditorContext() { public NodeEditorContext() {
} }
public ImNodeEditorContext(final ImNodeEditorConfig config) { public NodeEditorContext(final NodeEditorConfig config) {
this(nCreate(config.ptr)); this(nCreate(config.ptr));
} }
public ImNodeEditorContext(final long ptr) { public NodeEditorContext(final long ptr) {
super(ptr); super(ptr);
} }
@@ -1,11 +1,11 @@
package imgui.nodeditor; package imgui.extension.nodeditor;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.ImVec4; import imgui.ImVec4;
import imgui.binding.ImGuiStruct; import imgui.binding.ImGuiStruct;
public final class ImNodeEditorStyle extends ImGuiStruct { public final class NodeEditorStyle extends ImGuiStruct {
public ImNodeEditorStyle(final long ptr) { public NodeEditorStyle(final long ptr) {
super(ptr); super(ptr);
} }
@@ -1,4 +1,4 @@
package imgui.nodeditor; package imgui.extension.nodeditor.flag;
public final class ImNodeEditorPinKind { public final class ImNodeEditorPinKind {
private ImNodeEditorPinKind() { private ImNodeEditorPinKind() {
@@ -1,4 +1,4 @@
package imgui.nodeditor; package imgui.extension.nodeditor.flag;
public final class ImNodeEditorStyleColor { public final class ImNodeEditorStyleColor {
private ImNodeEditorStyleColor() { private ImNodeEditorStyleColor() {
@@ -1,4 +1,4 @@
package imgui.nodeditor; package imgui.extension.nodeditor.flag;
public final class ImNodeEditorStyleVar { public final class ImNodeEditorStyleVar {
private ImNodeEditorStyleVar() { private ImNodeEditorStyleVar() {
+33 -33
View File
@@ -5,15 +5,15 @@ import imgui.flag.ImGuiDir;
import imgui.flag.ImGuiInputTextFlags; import imgui.flag.ImGuiInputTextFlags;
import imgui.flag.ImGuiStyleVar; import imgui.flag.ImGuiStyleVar;
import imgui.flag.ImGuiWindowFlags; import imgui.flag.ImGuiWindowFlags;
import imgui.imnodes.ImNodes; import imgui.extension.imnodes.ImNodes;
import imgui.imnodes.ImNodesContext; import imgui.extension.imnodes.ImNodesContext;
import imgui.imnodes.ImNodesPinShape; import imgui.extension.imnodes.flag.ImNodesPinShape;
import imgui.nodeditor.ImNodeEditor; import imgui.extension.nodeditor.NodeEditor;
import imgui.internal.ImGui; import imgui.internal.ImGui;
import imgui.internal.flag.ImGuiDockNodeFlags; import imgui.internal.flag.ImGuiDockNodeFlags;
import imgui.nodeditor.ImNodeEditorConfig; import imgui.extension.nodeditor.NodeEditorConfig;
import imgui.nodeditor.ImNodeEditorContext; import imgui.extension.nodeditor.NodeEditorContext;
import imgui.nodeditor.ImNodeEditorPinKind; import imgui.extension.nodeditor.flag.NodeEditorPinKind;
import imgui.type.ImBoolean; import imgui.type.ImBoolean;
import imgui.ImColor; import imgui.ImColor;
import imgui.type.ImInt; import imgui.type.ImInt;
@@ -76,7 +76,7 @@ final class ExampleUi {
private ImNodesContext imNodesContext; private ImNodesContext imNodesContext;
// Context for imgui-node-editor example // Context for imgui-node-editor example
private ImNodeEditorContext imNodeEditorContext; private NodeEditorContext nodeEditorContext;
// Graph used both for imnodes and imgui-node-editor demo // Graph used both for imnodes and imgui-node-editor demo
private final Graph graph = new Graph(); private final Graph graph = new Graph();
@@ -85,10 +85,10 @@ final class ExampleUi {
if (imNodesContext == null) { if (imNodesContext == null) {
imNodesContext = new ImNodesContext(); imNodesContext = new ImNodesContext();
} }
if (imNodeEditorContext == null) { if (nodeEditorContext == null) {
final ImNodeEditorConfig config = new ImNodeEditorConfig(); final NodeEditorConfig config = new NodeEditorConfig();
config.setSettingsFile(null); config.setSettingsFile(null);
imNodeEditorContext = new ImNodeEditorContext(config); nodeEditorContext = new NodeEditorContext(config);
} }
final int dockspaceId = ImGui.getID("MyDockSpace"); final int dockspaceId = ImGui.getID("MyDockSpace");
@@ -333,52 +333,52 @@ final class ExampleUi {
ImGui.text("This a demo graph editor for imgui-node-editor"); ImGui.text("This a demo graph editor for imgui-node-editor");
if (ImGui.button("Navigate to content")) { if (ImGui.button("Navigate to content")) {
ImNodeEditor.navigateToContent(1F); NodeEditor.navigateToContent(1F);
} }
ImNodeEditor.setCurrentEditor(imNodeEditorContext); NodeEditor.setCurrentEditor(nodeEditorContext);
ImNodeEditor.begin("Node Editor"); NodeEditor.begin("Node Editor");
for (Graph.GraphNode node : graph.nodes.values()) { for (Graph.GraphNode node : graph.nodes.values()) {
ImNodeEditor.beginNode(node.nodeId); NodeEditor.beginNode(node.nodeId);
ImGui.text(node.getName()); ImGui.text(node.getName());
ImNodeEditor.beginPin(node.getInputPinId(), ImNodeEditorPinKind.Input); NodeEditor.beginPin(node.getInputPinId(), NodeEditorPinKind.Input);
ImGui.text("-> In"); ImGui.text("-> In");
ImNodeEditor.endPin(); NodeEditor.endPin();
ImGui.sameLine(); ImGui.sameLine();
ImNodeEditor.beginPin(node.getOutputPinId(), ImNodeEditorPinKind.Output); NodeEditor.beginPin(node.getOutputPinId(), NodeEditorPinKind.Output);
ImGui.text("Out ->"); ImGui.text("Out ->");
ImNodeEditor.endPin(); NodeEditor.endPin();
ImNodeEditor.endNode(); NodeEditor.endNode();
} }
if (ImNodeEditor.beginCreate()) { if (NodeEditor.beginCreate()) {
final ImLong a = new ImLong(); final ImLong a = new ImLong();
final ImLong b = new ImLong(); final ImLong b = new ImLong();
if (ImNodeEditor.queryNewLink(a, b)) { if (NodeEditor.queryNewLink(a, b)) {
final Graph.GraphNode source = graph.findByOutput(a.get()); final Graph.GraphNode source = graph.findByOutput(a.get());
final Graph.GraphNode target = graph.findByInput(b.get()); final Graph.GraphNode target = graph.findByInput(b.get());
if (source != null && target != null && source.outputNodeId != target.nodeId && ImNodeEditor.acceptNewItem()) { if (source != null && target != null && source.outputNodeId != target.nodeId && NodeEditor.acceptNewItem()) {
source.outputNodeId = target.nodeId; source.outputNodeId = target.nodeId;
} }
} }
} }
ImNodeEditor.endCreate(); NodeEditor.endCreate();
int uniqueLinkId = 1; int uniqueLinkId = 1;
for (Graph.GraphNode node : graph.nodes.values()) { for (Graph.GraphNode node : graph.nodes.values()) {
if (graph.nodes.containsKey(node.outputNodeId)) { if (graph.nodes.containsKey(node.outputNodeId)) {
ImNodeEditor.link(uniqueLinkId++, node.getOutputPinId(), graph.nodes.get(node.outputNodeId).getInputPinId()); NodeEditor.link(uniqueLinkId++, node.getOutputPinId(), graph.nodes.get(node.outputNodeId).getInputPinId());
} }
} }
ImNodeEditor.suspend(); NodeEditor.suspend();
final long nodeWithContextMenu = ImNodeEditor.getNodeWithContextMenu(); final long nodeWithContextMenu = NodeEditor.getNodeWithContextMenu();
if (nodeWithContextMenu != -1) { if (nodeWithContextMenu != -1) {
ImGui.openPopup("node-context"); ImGui.openPopup("node-context");
ImGui.getStateStorage().setInt(ImGui.getID("delete-node-id"), (int) nodeWithContextMenu); ImGui.getStateStorage().setInt(ImGui.getID("delete-node-id"), (int) nodeWithContextMenu);
@@ -395,22 +395,22 @@ final class ExampleUi {
} }
} }
if (ImNodeEditor.showBackgroundContextMenu()) { if (NodeEditor.showBackgroundContextMenu()) {
ImGui.openPopup("node-editor-context"); ImGui.openPopup("node-editor-context");
} }
if (ImGui.beginPopup("node-editor-context")) { if (ImGui.beginPopup("node-editor-context")) {
if (ImGui.button("Create new node")) { if (ImGui.button("Create new node")) {
final Graph.GraphNode node = graph.createGraphNode(); final Graph.GraphNode node = graph.createGraphNode();
final float canvasX = ImNodeEditor.toCanvasX(ImGui.getMousePosX()); final float canvasX = NodeEditor.toCanvasX(ImGui.getMousePosX());
final float canvasY = ImNodeEditor.toCanvasY(ImGui.getMousePosY()); final float canvasY = NodeEditor.toCanvasY(ImGui.getMousePosY());
ImNodeEditor.setNodePosition(node.nodeId, canvasX, canvasY); NodeEditor.setNodePosition(node.nodeId, canvasX, canvasY);
ImGui.closeCurrentPopup(); ImGui.closeCurrentPopup();
} }
ImGui.endPopup(); ImGui.endPopup();
} }
ImNodeEditor.resume(); NodeEditor.resume();
ImNodeEditor.end(); NodeEditor.end();
ImGui.end(); ImGui.end();
} }
@@ -48,7 +48,7 @@ import java.io.UncheckedIOException;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.Objects; import java.util.Objects;
import imgui.imnodes.ImNodes; import imgui.extension.imnodes.ImNodes;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;