Skip to content

Commit 4e56424

Browse files
committed
[API] Add support for DockBuilder
1 parent b3b26e9 commit 4e56424

File tree

11 files changed

+1057
-14
lines changed

11 files changed

+1057
-14
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
def inputTxt = new File(args[0]).text
2+
def outputFile = new File(args[1])
3+
def jStructName = args[2] as String
4+
5+
outputFile.text = ''
6+
7+
inputTxt = inputTxt
8+
.replace('ImGuiID', 'int')
9+
.replace('bool', 'boolean')
10+
.replace('char*', 'String')
11+
.replace('const char*', 'String')
12+
13+
def regex = ~'(\\w+)\\s+(\\w+)(?:.*?//(.+))?'
14+
15+
inputTxt.eachLine { line ->
16+
def trimmedLine = line.trim()
17+
18+
if (!trimmedLine.contains(';') || trimmedLine.startsWith('#'))
19+
return
20+
21+
def m = regex.matcher(trimmedLine)
22+
23+
def fieldType
24+
def fieldName
25+
def fieldComment
26+
27+
m.find()
28+
29+
fieldType = m.group(1)
30+
fieldName = m.group(2)
31+
fieldComment = m.group(3)?.trim()
32+
33+
def javadoc = null
34+
35+
if (fieldComment) {
36+
javadoc = """ /**
37+
| * $fieldComment
38+
| */""".stripMargin()
39+
}
40+
41+
def classTxt
42+
43+
if (fieldType == 'ImVec2') {
44+
classTxt = """
45+
|${javadoc ? javadoc : ''}
46+
| public native void get${fieldName.capitalize()}(ImVec2 dstImVec2); /*
47+
| Jni::ImVec2Cpy(env, &$jStructName->$fieldName, dstImVec2);
48+
| */
49+
|
50+
|${javadoc ? javadoc : ''}
51+
| public native float get${fieldName.capitalize()}X(); /*
52+
| return $jStructName->${fieldName}.x;
53+
| */
54+
|
55+
|${javadoc ? javadoc : ''}
56+
| public native float get${fieldName.capitalize()}Y(); /*
57+
| return $jStructName->${fieldName}.y;
58+
| */
59+
|
60+
|${javadoc ? javadoc : ''}
61+
| public native void set${fieldName.capitalize()}(float x, float y); /*
62+
| $jStructName->${fieldName}.x = x;
63+
| $jStructName->${fieldName}.y = y;
64+
| */
65+
""".stripMargin()
66+
} else {
67+
classTxt = """
68+
|${javadoc ? javadoc : ''}
69+
| public native $fieldType get${fieldName.capitalize()}(); /*
70+
| return $jStructName->$fieldName;
71+
| */
72+
|
73+
|${javadoc ? javadoc : ''}
74+
| public native void set${fieldName.capitalize()}($fieldType ${fieldName.uncapitalize()}); /*
75+
| $jStructName->$fieldName = ${fieldName.uncapitalize()};
76+
| */
77+
""".stripMargin()
78+
}
79+
80+
outputFile << classTxt
81+
}

imgui-binding/src/main/java/imgui/ImGui.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.nio.file.Paths;
1919
import java.nio.file.StandardCopyOption;
2020

21-
public final class ImGui {
21+
public class ImGui {
2222
private static final String LIB_PATH_PROP = "imgui.library.path";
2323
private static final String LIB_NAME_PROP = "imgui.library.name";
2424
private static final String LIB_NAME_DEFAULT = System.getProperty("os.arch").contains("64") ? "imgui-java64" : "imgui-java";
@@ -114,9 +114,6 @@ private static String tryLoadFromClasspath(final String fullLibName) {
114114
public static void init() {
115115
}
116116

117-
private ImGui() {
118-
}
119-
120117
/*JNI
121118
#include <stdint.h>
122119
#include <imgui.h>
@@ -650,6 +647,13 @@ public static ImGuiViewport getWindowViewport() {
650647
ImGui::SetNextWindowBgAlpha(alpha);
651648
*/
652649

650+
/**
651+
* Set next window viewport.
652+
*/
653+
public static native void setNextWindowViewport(int viewportId); /*
654+
ImGui::SetNextWindowViewport(viewportId);
655+
*/
656+
653657
/**
654658
* (not recommended) set current window position - call within Begin()/End().
655659
* Prefer using SetNextWindowPos(), as this may incur tearing and side-effects.

imgui-binding/src/main/java/imgui/ImGuiViewport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public ImGuiViewport(final long ptr) {
2626
/**
2727
* Unique identifier for the viewport.
2828
*/
29-
public native int getImGuiId(); /*
29+
public native int getID(); /*
3030
return IMGUI_VIEWPORT->ID;
3131
*/
3232

3333
/**
3434
* Unique identifier for the viewport.
3535
*/
36-
public native void setImGuiId(int imGuiID); /*
36+
public native void setID(int imGuiID); /*
3737
IMGUI_VIEWPORT->ID = imGuiID;
3838
*/
3939

imgui-binding/src/main/java/imgui/flag/ImGuiDockNodeFlags.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
* Flags for ImGui::DockSpace(), shared/inherited by child nodes.
55
* (Some flags can be applied to individual nodes directly)
66
*/
7-
public final class ImGuiDockNodeFlags {
8-
private ImGuiDockNodeFlags() {
9-
}
10-
7+
@SuppressWarnings("HideUtilityClassConstructor")
8+
public class ImGuiDockNodeFlags {
119
public static final int None = 0;
1210
/**
1311
* Don't display the dockspace node but keep it alive. Windows docked into this dockspace node won't be undocked.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package imgui.internal;
2+
3+
import imgui.type.ImInt;
4+
5+
public final class ImGui extends imgui.ImGui {
6+
private static final ImGuiDockNode DOCK_NODE = new ImGuiDockNode(0);
7+
8+
/*JNI
9+
#include <stdint.h>
10+
#include <imgui.h>
11+
#include <imgui_internal.h>
12+
*/
13+
14+
// Docking - Builder function needs to be generally called before the node is used/submitted.
15+
// - The DockBuilderXXX functions are designed to _eventually_ become a public API, but it is too early to expose it and guarantee stability.
16+
// - Do not hold on ImGuiDockNode* pointers! They may be invalidated by any split/merge/remove operation and every frame.
17+
// - To create a DockSpace() node, make sure to set the ImGuiDockNodeFlags_DockSpace flag when calling DockBuilderAddNode().
18+
// You can create dockspace nodes (attached to a window) _or_ floating nodes (carry its own window) with this API.
19+
// - DockBuilderSplitNode() create 2 child nodes within 1 node. The initial node becomes a parent node.
20+
// - If you intend to split the node immediately after creation using DockBuilderSplitNode(), make sure
21+
// to call DockBuilderSetNodeSize() beforehand. If you don't, the resulting split sizes may not be reliable.
22+
// - Call DockBuilderFinish() after you are done.
23+
24+
public static native void dockBuilderDockWindow(String windowName, int nodeId); /*
25+
ImGui::DockBuilderDockWindow(windowName, nodeId);
26+
*/
27+
28+
public static ImGuiDockNode dockBuilderGetNode(final int nodeId) {
29+
final long ptr = nDockBuilderGetNode(nodeId);
30+
if (ptr == 0) {
31+
return null;
32+
} else {
33+
DOCK_NODE.ptr = ptr;
34+
return DOCK_NODE;
35+
}
36+
}
37+
38+
private static native long nDockBuilderGetNode(int nodeId); /*
39+
return (intptr_t)ImGui::DockBuilderGetNode(nodeId);
40+
*/
41+
42+
public static ImGuiDockNode dockBuilderGetCentralNode(final int nodeId) {
43+
final long ptr = nDockBuilderGetCentralNode(nodeId);
44+
if (ptr == 0) {
45+
return null;
46+
} else {
47+
DOCK_NODE.ptr = ptr;
48+
return DOCK_NODE;
49+
}
50+
}
51+
52+
private static native long nDockBuilderGetCentralNode(int nodeId); /*
53+
return (intptr_t)ImGui::DockBuilderGetCentralNode(nodeId);
54+
*/
55+
56+
public static native int dockBuilderAddNode(); /*
57+
return ImGui::DockBuilderAddNode();
58+
*/
59+
60+
public static native int dockBuilderAddNode(int nodeId); /*
61+
return ImGui::DockBuilderAddNode(nodeId);
62+
*/
63+
64+
public static native int dockBuilderAddNode(int nodeId, int flags); /*
65+
return ImGui::DockBuilderAddNode(nodeId, flags);
66+
*/
67+
68+
/**
69+
* Remove node and all its child, undock all windows.
70+
*/
71+
public static native void dockBuilderRemoveNode(int nodeId); /*
72+
ImGui::DockBuilderRemoveNode(nodeId);
73+
*/
74+
75+
public static native void dockBuilderRemoveNodeDockedWindows(int nodeId); /*
76+
ImGui::DockBuilderRemoveNodeDockedWindows(nodeId);
77+
*/
78+
79+
public static native void dockBuilderRemoveNodeDockedWindows(int nodeId, boolean clearSettingsRefs); /*
80+
ImGui::DockBuilderRemoveNodeDockedWindows(nodeId, clearSettingsRefs);
81+
*/
82+
83+
/**
84+
* Remove all split/hierarchy. All remaining docked windows will be re-docked to the remaining root node (node_id).
85+
*/
86+
public static native void dockBuilderRemoveNodeChildNodes(int nodeId); /*
87+
ImGui::DockBuilderRemoveNodeChildNodes(nodeId);
88+
*/
89+
90+
public static native void dockBuilderSetNodePos(int nodeId, float posX, float posY); /*
91+
ImGui::DockBuilderSetNodePos(nodeId, ImVec2(posX, posY));
92+
*/
93+
94+
public static native void dockBuilderSetNodeSize(int nodeId, float sizeX, float sizeY); /*
95+
ImGui::DockBuilderSetNodeSize(nodeId, ImVec2(sizeX, sizeY));
96+
*/
97+
98+
/**
99+
* Create 2 child nodes in this parent node.
100+
*/
101+
public static int dockBuilderSplitNode(int nodeId, int splitDir, float sizeRationForNodeAtDir, ImInt outIdAtDir, ImInt outIdAtOppositeDir) {
102+
if (outIdAtDir == null && outIdAtOppositeDir != null) {
103+
return nDockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, null, outIdAtOppositeDir.getData());
104+
} else if (outIdAtDir != null && outIdAtOppositeDir == null) {
105+
return nDockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, outIdAtDir.getData());
106+
} else if (outIdAtDir != null) {
107+
return nDockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, outIdAtDir.getData(), outIdAtOppositeDir.getData());
108+
} else {
109+
return nDockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir);
110+
}
111+
}
112+
113+
private static native int nDockBuilderSplitNode(int nodeId, int splitDir, float sizeRationForNodeAtDir, int[] outIdAtDir, int[] outIdAtOppositeDir); /*
114+
return ImGui::DockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, (ImGuiID*)&outIdAtDir[0], (ImGuiID*)&outIdAtOppositeDir[0]);
115+
*/
116+
117+
private static native int nDockBuilderSplitNode(int nodeId, int splitDir, float sizeRationForNodeAtDir); /*
118+
return ImGui::DockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, NULL, NULL);
119+
*/
120+
121+
private static native int nDockBuilderSplitNode(int nodeId, int splitDir, float sizeRationForNodeAtDir, int[] outIdAtDir); /*
122+
return ImGui::DockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, (ImGuiID*)&outIdAtDir[0], NULL);
123+
*/
124+
125+
private static native int nDockBuilderSplitNode(int nodeId, int splitDir, float sizeRationForNodeAtDir, Object o, int[] outIdAtOppositeDir); /*
126+
return ImGui::DockBuilderSplitNode(nodeId, splitDir, sizeRationForNodeAtDir, NULL, (ImGuiID*)&outIdAtOppositeDir[0]);
127+
*/
128+
129+
// TODO DockBuilderCopyDockSpace, DockBuilderCopyNode
130+
131+
public static native void dockBuilderCopyWindowSettings(String srcName, String dstName); /*
132+
ImGui::DockBuilderCopyWindowSettings(srcName, dstName);
133+
*/
134+
135+
public static native void dockBuilderFinish(int nodeId); /*
136+
ImGui::DockBuilderFinish(nodeId);
137+
*/
138+
}

0 commit comments

Comments
 (0)