Skip to content

Commit 5458a03

Browse files
committed
Expose docking API
1 parent af83619 commit 5458a03

File tree

8 files changed

+360
-15
lines changed

8 files changed

+360
-15
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void destroy() {
2828
/*JNI
2929
#include <stdint.h>
3030
#include <imgui.h>
31-
#include "jni_common.h"
3231
3332
jfieldID imFontGlyphPtrID;
3433

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class ImGui {
5050
ImFontGlyph.nInit();
5151
ImFont.nInit();
5252
ImGuiStyle.nInit();
53+
ImGuiWindowClass.nInit();
5354
nInitInputTextData();
5455
}
5556

@@ -474,6 +475,13 @@ public static ImDrawList getWindowDrawList() {
474475
return (intptr_t)ImGui::GetWindowDrawList();
475476
*/
476477

478+
/**
479+
* Get DPI scale currently associated to the current window's viewport.
480+
*/
481+
public static native float getWindowDpiScale(); /*
482+
return ImGui::GetWindowDpiScale();
483+
*/
484+
477485
/**
478486
* Get current window position in screen space (useful if you want to do your own drawing via the DrawList API)
479487
*/
@@ -3989,6 +3997,7 @@ public static boolean beginPopupModal(String name, ImBool pOpen, int imGuiWindow
39893997
*/
39903998

39913999
// Tab Bars, Tabs
4000+
// Note: Tabs are automatically created by the docking system. Use this to create tab bars/tabs yourself without docking being involved.
39924001

39934002
/**
39944003
* Create and append into a TabBar
@@ -4062,6 +4071,73 @@ public static boolean beginTabItem(String label, ImBool pOpen, int imGuiTabBarFl
40624071
ImGui::SetTabItemClosed(tabOrDockedWindowLabel);
40634072
*/
40644073

4074+
// Docking
4075+
// [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable.
4076+
// Note: You can use most Docking facilities without calling any API. You DO NOT need to call DockSpace() to use Docking!
4077+
// - To dock windows: if io.ConfigDockingWithShift == false (default) drag window from their title bar.
4078+
// - To dock windows: if io.ConfigDockingWithShift == true: hold SHIFT anywhere while moving windows.
4079+
// About DockSpace:
4080+
// - Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details.
4081+
// - DockSpace() needs to be submitted _before_ any window they can host. If you use a dockspace, submit it early in your app.
4082+
4083+
public static void dockSpace(int imGuiID) {
4084+
nDockSpace(imGuiID, 0, 0, 0, 0);
4085+
}
4086+
4087+
public static void dockSpace(int imGuiID, float sizeX, float sizeY) {
4088+
nDockSpace(imGuiID, sizeX, sizeY, 0, 0);
4089+
}
4090+
4091+
public static void dockSpace(int imGuiID, float sizeX, float sizeY, int imGuiDockNodeFlags) {
4092+
nDockSpace(imGuiID, sizeX, sizeY, imGuiDockNodeFlags, 0);
4093+
}
4094+
4095+
public static void dockSpace(int imGuiID, float sizeX, float sizeY, int imGuiDockNodeFlags, ImGuiWindowClass imGuiWindowClass) {
4096+
nDockSpace(imGuiID, sizeX, sizeY, imGuiDockNodeFlags, imGuiWindowClass.ptr);
4097+
}
4098+
4099+
private static native void nDockSpace(int imGuiID, float sizeX, float sizeY, int imGuiDockNodeFlags, long windowClassPtr); /*
4100+
ImGui::DockSpace(imGuiID, ImVec2(sizeX, sizeY), imGuiDockNodeFlags, windowClassPtr != 0 ? (ImGuiWindowClass*)windowClassPtr : NULL);
4101+
*/
4102+
4103+
// TODO: DockSpaceOverViewport
4104+
4105+
/**
4106+
* Set next window dock id
4107+
*/
4108+
public static native void setNextWindowDockID(int dockId); /*
4109+
ImGui::SetNextWindowDockID(dockId);
4110+
*/
4111+
4112+
/**
4113+
* Set next window dock id
4114+
*/
4115+
public static native void setNextWindowDockID(int dockId, int imGuiCond); /*
4116+
ImGui::SetNextWindowDockID(dockId, imGuiCond);
4117+
*/
4118+
4119+
/**
4120+
* set next window class (rare/advanced uses: provide hints to the platform back-end via altered viewport flags and parent/child info)
4121+
*/
4122+
public static void setNextWindowClass(ImGuiWindowClass windowClass) {
4123+
nSetNextWindowClass(windowClass.ptr);
4124+
}
4125+
4126+
private static native void nSetNextWindowClass(long windowClassPtr); /*
4127+
ImGui::SetNextWindowClass((ImGuiWindowClass*)windowClassPtr);
4128+
*/
4129+
4130+
public static native int getWindowDockID(); /*
4131+
return ImGui::GetWindowDockID();
4132+
*/
4133+
4134+
/**
4135+
* Is current window docked into another window?
4136+
*/
4137+
public static native boolean isWindowDocked(); /*
4138+
return ImGui::IsWindowDocked();
4139+
*/
4140+
40654141
// Logging/Capture
40664142
// - All text output from the interface can be captured into tty/file/clipboard. By default, tree nodes are automatically opened during logging.
40674143

@@ -4432,6 +4508,7 @@ public static byte[] acceptDragDropPayload(String type, int imGuiDragDropFlags)
44324508
*/
44334509

44344510
/**
4511+
* Get background draw list for the viewport associated to the current window.
44354512
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
44364513
*/
44374514
public static ImDrawList getBackgroundDrawList() {
@@ -4446,7 +4523,8 @@ public static ImDrawList getBackgroundDrawList() {
44464523
*/
44474524

44484525
/**
4449-
* This draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
4526+
* Get foreground draw list for the viewport associated to the current window.
4527+
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
44504528
*/
44514529
public static ImDrawList getForegroundDrawList() {
44524530
if (foregroundDrawList == null) {

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,68 @@ void setClipboardTextStub(void* userData, const char* text) {
465465
ImGui::GetIO().DisplayFramebufferScale.y = y;
466466
*/
467467

468+
// Docking options (when ImGuiConfigFlags_DockingEnable is set)
469+
470+
/**
471+
* Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars.
472+
*/
473+
public native boolean getConfigDockingNoSplit(); /*
474+
return ImGui::GetIO().ConfigDockingNoSplit;
475+
*/
476+
477+
/**
478+
* Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars.
479+
*/
480+
public native void setConfigDockingNoSplit(boolean value); /*
481+
ImGui::GetIO().ConfigDockingNoSplit = value;
482+
*/
483+
484+
/**
485+
* Enable docking with holding Shift key (reduce visual noise, allows dropping in wider space)
486+
*/
487+
public native boolean getConfigDockingWithShift(); /*
488+
return ImGui::GetIO().ConfigDockingWithShift;
489+
*/
490+
491+
/**
492+
* Enable docking with holding Shift key (reduce visual noise, allows dropping in wider space)
493+
*/
494+
public native void setConfigDockingWithShift(boolean value); /*
495+
ImGui::GetIO().ConfigDockingWithShift = value;
496+
*/
497+
498+
/**
499+
* [BETA] [FIXME: This currently creates regression with auto-sizing and general overhead]
500+
* Make every single floating window display within a docking node.
501+
*/
502+
public native boolean getConfigDockingAlwaysTabBar(); /*
503+
return ImGui::GetIO().ConfigDockingAlwaysTabBar;
504+
*/
505+
506+
/**
507+
* [BETA] [FIXME: This currently creates regression with auto-sizing and general overhead]
508+
* Make every single floating window display within a docking node.
509+
*/
510+
public native void setConfigDockingAlwaysTabBar(boolean value); /*
511+
ImGui::GetIO().ConfigDockingAlwaysTabBar = value;
512+
*/
513+
514+
/**
515+
* [BETA] Make window or viewport transparent when docking and only display docking boxes on the target viewport.
516+
* Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge.
517+
*/
518+
public native boolean getConfigDockingTransparentPayload(); /*
519+
return ImGui::GetIO().ConfigDockingTransparentPayload;
520+
*/
521+
522+
/**
523+
* [BETA] Make window or viewport transparent when docking and only display docking boxes on the target viewport.
524+
* Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge.
525+
*/
526+
public native void setConfigDockingTransparentPayload(boolean value); /*
527+
ImGui::GetIO().ConfigDockingTransparentPayload = value;
528+
*/
529+
468530
/**
469531
* Time elapsed since last frame, in seconds.
470532
* <p>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package imgui;
2+
3+
/**
4+
* [ALPHA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions.
5+
* Important: the content of this class is still highly WIP and likely to change and be refactored
6+
* before we stabilize Docking features. Please be mindful if using this.
7+
* Provide hints:
8+
* - To the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.)
9+
* - To the platform back-end for OS level parent/child relationships of viewport.
10+
* - To the docking system for various options and filtering.
11+
*/
12+
public final class ImGuiWindowClass implements ImDestroyable {
13+
final long ptr;
14+
15+
/**
16+
* This class will create a native structure.
17+
* Call {@link #destroy()} method to manually free used memory.
18+
*/
19+
public ImGuiWindowClass() {
20+
ImGui.touch();
21+
ptr = nCreate();
22+
}
23+
24+
ImGuiWindowClass(final long ptr) {
25+
this.ptr = ptr;
26+
}
27+
28+
@Override
29+
public void destroy() {
30+
nDestroy(ptr);
31+
}
32+
33+
/*JNI
34+
#include <stdint.h>
35+
#include <imgui.h>
36+
37+
jfieldID imGuiWindowClassPtrID;
38+
39+
#define IMGUI_WINDOW_CLASS ((ImGuiWindowClass*)env->GetLongField(object, imGuiWindowClassPtrID))
40+
*/
41+
42+
static native void nInit(); /*
43+
jclass jImGuiWindowClassClass = env->FindClass("imgui/ImGuiWindowClass");
44+
imGuiWindowClassPtrID = env->GetFieldID(jImGuiWindowClassClass, "ptr", "J");
45+
*/
46+
47+
private native long nCreate(); /*
48+
ImGuiWindowClass* imGuiWindowClass = new ImGuiWindowClass();
49+
return (intptr_t)imGuiWindowClass;
50+
*/
51+
52+
private native void nDestroy(long ptr); /*
53+
delete (ImGuiWindowClass*)ptr;
54+
*/
55+
56+
/**
57+
* User data. 0 = Default class (unclassed). Windows of different classes cannot be docked with each others.
58+
*/
59+
public native int geClassId(); /*
60+
return IMGUI_WINDOW_CLASS->ClassId;
61+
*/
62+
63+
/**
64+
* User data. 0 = Default class (unclassed). Windows of different classes cannot be docked with each others.
65+
*/
66+
public native void setClassId(int classId); /*
67+
IMGUI_WINDOW_CLASS->ClassId = classId;
68+
*/
69+
70+
/**
71+
* Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows.
72+
* Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not.
73+
*/
74+
public native int getParentViewportId(); /*
75+
return IMGUI_WINDOW_CLASS->ParentViewportId;
76+
*/
77+
78+
/**
79+
* Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows.
80+
* Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not.
81+
*/
82+
public native void setParentViewportId(int parentViewportId); /*
83+
IMGUI_WINDOW_CLASS->ParentViewportId = parentViewportId;
84+
*/
85+
86+
// TODO: ViewportFlagsOverrideSet, ViewportFlagsOverrideClear
87+
88+
/**
89+
* [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!)
90+
*/
91+
public native int getDockNodeFlagsOverrideSet(); /*
92+
return IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideSet;
93+
*/
94+
95+
/**
96+
* [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!)
97+
*/
98+
public native void setDockNodeFlagsOverrideSet(int dockNodeFlagsOverrideSet); /*
99+
IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideSet = dockNodeFlagsOverrideSet;
100+
*/
101+
102+
/**
103+
* [EXPERIMENTAL]
104+
*/
105+
public native int getDockNodeFlagsOverrideClear(); /*
106+
return IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideClear;
107+
*/
108+
109+
/**
110+
* [EXPERIMENTAL]
111+
*/
112+
public native void setDockNodeFlagsOverrideClear(int dockNodeFlagsOverrideClear); /*
113+
IMGUI_WINDOW_CLASS->DockNodeFlagsOverrideClear = dockNodeFlagsOverrideClear;
114+
*/
115+
116+
/**
117+
* Set to true to enforce single floating windows of this class always having their own docking node
118+
* (equivalent of setting the global io.ConfigDockingAlwaysTabBar)
119+
*/
120+
public native boolean getDockingAlwaysTabBar(); /*
121+
return IMGUI_WINDOW_CLASS->DockingAlwaysTabBar;
122+
*/
123+
124+
/**
125+
* Set to true to enforce single floating windows of this class always having their own docking node
126+
* (equivalent of setting the global io.ConfigDockingAlwaysTabBar)
127+
*/
128+
public native void setDockingAlwaysTabBar(boolean dockingAlwaysTabBar); /*
129+
IMGUI_WINDOW_CLASS->DockingAlwaysTabBar = dockingAlwaysTabBar;
130+
*/
131+
132+
/**
133+
* Set to true to allow windows of this class to be docked/merged with an unclassed window.
134+
*/
135+
public native boolean getDockingAllowUnclassed(); /*
136+
return IMGUI_WINDOW_CLASS->DockingAllowUnclassed;
137+
*/
138+
139+
/**
140+
* Set to true to allow windows of this class to be docked/merged with an unclassed window.
141+
*/
142+
public native void setDockingAllowUnclassed(boolean dockingAllowUnclassed); /*
143+
IMGUI_WINDOW_CLASS->DockingAllowUnclassed = dockingAllowUnclassed;
144+
*/
145+
}

0 commit comments

Comments
 (0)