Skip to content

Commit 8ac8a07

Browse files
committed
[API] Add API for Dear ImGui v1.79
1 parent 598bfdf commit 8ac8a07

File tree

10 files changed

+91
-105
lines changed

10 files changed

+91
-105
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,6 @@ public ImFontGlyph getFallbackGlyph() {
7373
return (intptr_t)IM_FONT->FallbackGlyph;
7474
*/
7575

76-
/**
77-
* Offset font rendering by xx pixels
78-
*/
79-
public native void getDisplayOffset(ImVec2 dstImVec2); /*
80-
Jni::ImVec2Cpy(env, &IM_FONT->DisplayOffset, dstImVec2);
81-
*/
82-
83-
/**
84-
* Offset font rendering by xx pixels
85-
*/
86-
public native float getDisplayOffsetX(); /*
87-
return IM_FONT->DisplayOffset.x;
88-
*/
89-
90-
/**
91-
* Offset font rendering by xx pixels
92-
*/
93-
public native float getDisplayOffsetY(); /*
94-
return IM_FONT->DisplayOffset.y;
95-
*/
96-
97-
/**
98-
* Offset font rendering by xx pixels
99-
*/
100-
public native void setDisplayOffset(float x, float y); /*
101-
IM_FONT->DisplayOffset.x = x;
102-
IM_FONT->DisplayOffset.y = y;
103-
*/
104-
10576
// TODO ContainerAtlas, ConfigData
10677

10778
/**

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

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4018,29 +4018,29 @@ public static boolean beginPopupModal(String name, ImBoolean pOpen, int imGuiWin
40184018
/**
40194019
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
40204020
*/
4021-
public static native void openPopupContextItem(); /*
4022-
ImGui::OpenPopupContextItem();
4021+
public static native void openPopupOnItemClick(); /*
4022+
ImGui::OpenPopupOnItemClick();
40234023
*/
40244024

40254025
/**
40264026
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
40274027
*/
4028-
public static native void openPopupContextItem(String strId); /*
4029-
ImGui::OpenPopupContextItem(strId);
4028+
public static native void openPopupOnItemClick(String strId); /*
4029+
ImGui::OpenPopupOnItemClick(strId);
40304030
*/
40314031

40324032
/**
40334033
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
40344034
*/
4035-
public static native void openPopupContextItem(int imGuiPopupFlags); /*
4036-
ImGui::OpenPopupContextItem(NULL, imGuiPopupFlags);
4035+
public static native void openPopupOnItemClick(int imGuiPopupFlags); /*
4036+
ImGui::OpenPopupOnItemClick(NULL, imGuiPopupFlags);
40374037
*/
40384038

40394039
/**
40404040
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
40414041
*/
4042-
public static native void openPopupContextItem(String strId, int imGuiPopupFlags); /*
4043-
ImGui::OpenPopupContextItem(strId, imGuiPopupFlags);
4042+
public static native void openPopupOnItemClick(String strId, int imGuiPopupFlags); /*
4043+
ImGui::OpenPopupOnItemClick(strId, imGuiPopupFlags);
40444044
*/
40454045

40464046
/**
@@ -4050,44 +4050,11 @@ public static boolean beginPopupModal(String name, ImBoolean pOpen, int imGuiWin
40504050
ImGui::CloseCurrentPopup();
40514051
*/
40524052

4053-
/**
4054-
* Helper to open popup when clicked on last item (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors).
4055-
* return true when just opened.
4056-
*
4057-
* @deprecated use {@link ImGui#openPopupContextItem()}
4058-
* @since 1.77
4059-
*/
4060-
public static native boolean openPopupOnItemClick(); /*
4061-
return ImGui::OpenPopupOnItemClick();
4062-
*/
4063-
4064-
/**
4065-
* Helper to open popup when clicked on last item (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors).
4066-
* return true when just opened.
4067-
*
4068-
* @deprecated use {@link ImGui#openPopupContextItem(String)}
4069-
* @since 1.77
4070-
*/
4071-
public static native boolean openPopupOnItemClick(String strId); /*
4072-
return ImGui::OpenPopupOnItemClick(strId);
4073-
*/
4074-
4075-
/**
4076-
* Helper to open popup when clicked on last item (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors).
4077-
* return true when just opened.
4078-
*
4079-
* @deprecated use {@link ImGui#openPopupContextItem(String, int)}
4080-
* @since 1.77
4081-
*/
4082-
public static native boolean openPopupOnItemClick(String strId, int mouseButton); /*
4083-
return ImGui::OpenPopupOnItemClick(strId, mouseButton);
4084-
*/
4085-
40864053
// Popups: open+begin combined functions helpers
40874054
// - Helpers to do OpenPopup+BeginPopup where the Open action is triggered by e.g. hovering an item and right-clicking.
40884055
// - They are convenient to easily create context menus, hence the name.
40894056
// - IMPORTANT: Notice that BeginPopupContextXXX takes ImGuiPopupFlags just like OpenPopup() and unlike BeginPopup(). For full consistency, we may add ImGuiWindowFlags to the BeginPopupContextXXX functions in the future.
4090-
// - We exceptionally default their flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter. Passing a mouse button to ImGuiPopupFlags is guaranteed to be legal.
4057+
// - IMPORTANT: we exceptionally default their flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter, so if you add other flags remember to re-add the ImGuiPopupFlags_MouseButtonRight.
40914058

40924059
/**
40934060
* Open+begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id.
@@ -4329,23 +4296,23 @@ public static boolean beginTabItem(String label, ImBoolean pOpen) {
43294296
/**
43304297
* Create a Tab. Returns true if the Tab is selected.
43314298
*/
4332-
public static boolean beginTabItem(String label, int imGuiTabBarFlags) {
4333-
return nBeginTabItem(label, imGuiTabBarFlags);
4299+
public static boolean beginTabItem(String label, int imGuiTabItemFlags) {
4300+
return nBeginTabItem(label, imGuiTabItemFlags);
43344301
}
43354302

43364303
/**
43374304
* Create a Tab. Returns true if the Tab is selected.
43384305
*/
4339-
public static boolean beginTabItem(String label, ImBoolean pOpen, int imGuiTabBarFlags) {
4340-
return nBeginTabItem(label, pOpen.getData(), imGuiTabBarFlags);
4306+
public static boolean beginTabItem(String label, ImBoolean pOpen, int imGuiTabItemFlags) {
4307+
return nBeginTabItem(label, pOpen.getData(), imGuiTabItemFlags);
43414308
}
43424309

4343-
private static native boolean nBeginTabItem(String label, int imGuiTabBarFlags); /*
4344-
return ImGui::BeginTabItem(label, NULL, imGuiTabBarFlags);
4310+
private static native boolean nBeginTabItem(String label, int imGuiTabItemFlags); /*
4311+
return ImGui::BeginTabItem(label, NULL, imGuiTabItemFlags);
43454312
*/
43464313

4347-
private static native boolean nBeginTabItem(String label, boolean[] pOpen, int imGuiTabBarFlags); /*
4348-
return ImGui::BeginTabItem(label, &pOpen[0], imGuiTabBarFlags);
4314+
private static native boolean nBeginTabItem(String label, boolean[] pOpen, int imGuiTabItemFlags); /*
4315+
return ImGui::BeginTabItem(label, &pOpen[0], imGuiTabItemFlags);
43494316
*/
43504317

43514318
/**
@@ -4355,6 +4322,20 @@ public static boolean beginTabItem(String label, ImBoolean pOpen, int imGuiTabBa
43554322
ImGui::EndTabItem();
43564323
*/
43574324

4325+
/**
4326+
* Create a Tab behaving like a button. return true when clicked. cannot be selected in the tab bar.
4327+
*/
4328+
public static native boolean tabItemButton(String label); /*
4329+
return ImGui::TabItemButton(label);
4330+
*/
4331+
4332+
/**
4333+
* Create a Tab behaving like a button. return true when clicked. cannot be selected in the tab bar.
4334+
*/
4335+
public static native boolean tabItemButton(String label, int imGuiTabItemFlags); /*
4336+
return ImGui::TabItemButton(label, imGuiTabItemFlags);
4337+
*/
4338+
43584339
/**
43594340
* Notify TabBar or Docking system of a closed tab/window ahead (useful to reduce visual flicker on reorderable tab bars).
43604341
* For tab-bar: call after BeginTabBar() and before Tab submissions. Otherwise call with a window name.

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44

55
/**
66
* Helper: Manually clip large list of items.
7-
* If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all.
7+
* If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse
8+
* clipping based on visibility to save yourself from processing those items at all.
89
* The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
9-
* ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null.
10-
* Usage:
10+
* (Dear ImGui already clip items based on their bounds but it needs to measure text size to do so, whereas manual coarse clipping before submission makes this cost and your own data fetching/submission cost almost null)
1111
* <pre>
12-
* ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced.
13-
* while (clipper.Step())
14-
* for (int i = clipper.DisplayStart; i {@code <} clipper.DisplayEnd; i++)
15-
* ImGui::Text("line number %d", i);
12+
* ImGuiListClipper clipper;
13+
* clipper.Begin(1000); // We have 1000 elements, evenly spaced.
14+
* while (clipper.Step())
15+
* for (int i = clipper.DisplayStart; i {@code <} clipper.DisplayEnd; i++)
16+
* ImGui::Text("line number %d", i);
1617
* </pre>
17-
* - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor).
18-
* - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
19-
* - (Step 2: empty step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.)
20-
* - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
18+
* Generally what happens is:
19+
* - Clipper lets you process the first element (DisplayStart = 0, DisplayEnd = 1) regardless of it being visible or not.
20+
* - User code submit one element.
21+
* - Clipper can measure the height of the first element
22+
* - Clipper calculate the actual range of elements to display based on the current clipping rectangle, position the cursor before the first visible element.
23+
* - User code submit visible elements.
2124
* <p>
2225
* BINDING NOTICE:
2326
* It's impossible to implement the same API like in the original. Method {@link #forEach(int, int, ImListClipperCallback)} could be used instead.
@@ -55,7 +58,8 @@ public static void forEach(final int itemsCount, final ImListClipperCallback cal
5558
* @param callback action to do in iterations
5659
*/
5760
public static native void forEach(int itemsCount, int itemsHeight, ImListClipperCallback callback); /*
58-
ImGuiListClipper clipper(itemsCount);
61+
ImGuiListClipper clipper;
62+
clipper.Begin(itemsCount, itemsHeight);
5963
while (clipper.Step()) {
6064
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
6165
Jni::CallImListClipperCallback(env, callback, i);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,16 @@ protected long create() {
512512
* Minimum width for close button to appears on an unselected tab when hovered.
513513
* Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
514514
*/
515-
public native float getTabMinWidthForUnselectedCloseButton(); /*
516-
return IMGUI_STYLE->TabMinWidthForUnselectedCloseButton;
515+
public native float getTabMinWidthForCloseButton(); /*
516+
return IMGUI_STYLE->TabMinWidthForCloseButton;
517517
*/
518518

519519
/**
520520
* Minimum width for close button to appears on an unselected tab when hovered.
521521
* Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
522522
*/
523-
public native void setTabMinWidthForUnselectedCloseButton(float tabMinWidthForUnselectedCloseButton); /*
524-
IMGUI_STYLE->TabMinWidthForUnselectedCloseButton = tabMinWidthForUnselectedCloseButton;
523+
public native void setTabMinWidthForCloseButton(float tabMinWidthForCloseButton); /*
524+
IMGUI_STYLE->TabMinWidthForCloseButton = tabMinWidthForCloseButton;
525525
*/
526526

527527
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private ImGuiConfigFlags() {
4747
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
4848

4949
/**
50-
* Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends)
50+
* Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective back-ends)
5151
*/
5252
public static final int ViewportsEnable = 1 << 10;
5353
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ private ImGuiPopupFlags() {
1414

1515
public static final int None = 0;
1616
/**
17-
* For BeginPopupContext*(): open on Left Mouse release. Guaranted to always be == 0 (same as ImGuiMouseButton_Left)
17+
* For BeginPopupContext*(): open on Left Mouse release. Guaranteed to always be == 0 (same as ImGuiMouseButton_Left)
1818
*/
1919
public static final int MouseButtonLeft = 0;
2020
/**
21-
* For BeginPopupContext*(): open on Right Mouse release. Guaranted to always be == 1 (same as ImGuiMouseButton_Right)
21+
* For BeginPopupContext*(): open on Right Mouse release. Guaranteed to always be == 1 (same as ImGuiMouseButton_Right)
2222
*/
2323
public static final int MouseButtonRight = 1;
2424
/**
25-
* For BeginPopupContext*(): open on Middle Mouse release. Guaranted to always be == 2 (same as ImGuiMouseButton_Middle)
25+
* For BeginPopupContext*(): open on Middle Mouse release. Guaranteed to always be == 2 (same as ImGuiMouseButton_Middle)
2626
*/
2727
public static final int MouseButtonMiddle = 2;
2828
public static final int MouseButtonMask = 0x1F;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private ImGuiSliderFlags() {
88
/**
99
* Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
1010
*/
11-
public static final int ClampOnInput = 1 << 4;
11+
public static final int AlwaysClamp = 1 << 4;
1212
/**
1313
* Make the widget logarithmic (linear otherwise).
1414
* Consider using ImGuiSliderFlags_NoRoundToFormat with this if using a format-string with small amount of digits.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ private ImGuiTabItemFlags() {
3030
* Disable tooltip for the given tab
3131
*/
3232
public static final int NoTooltip = 1 << 4;
33+
/**
34+
* Disable reordering this tab or having another tab cross over this tab
35+
*/
36+
public static final int NoReorder = 1 << 5;
37+
/**
38+
* Enforce the tab position to the left of the tab bar (after the tab list popup button)
39+
*/
40+
public static final int Leading = 1 << 6;
41+
/**
42+
* Enforce the tab position to the right of the tab bar (before the scrolling buttons)
43+
*/
44+
public static final int Trailing = 1 << 7;
3345
}

imgui-binding/src/main/java/imgui/internal/ImRect.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Helper: ImRect (2D axis aligned bounding-box)
99
* NB: we can't rely on ImVec2 math operators being available here!
1010
*/
11-
public final class ImRect {
11+
public final class ImRect implements Cloneable {
1212
/**
1313
* Upper-left
1414
*/
@@ -35,6 +35,10 @@ public ImRect(final float x1, final float y1, final float x2, final float y2)
3535
max.y = y2;
3636
}
3737

38+
public ImRect(final ImRect imRect) {
39+
this(imRect.min, imRect.max);
40+
}
41+
3842
@Override
3943
public String toString() {
4044
return "ImRect{"
@@ -61,4 +65,9 @@ public boolean equals(final Object o) {
6165
public int hashCode() {
6266
return Objects.hash(min, max);
6367
}
68+
69+
@Override
70+
public ImRect clone() {
71+
return new ImRect(this);
72+
}
6473
}

imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,19 @@ private void updateMonitors() {
460460
final float mainSizeY = vidMode.height();
461461

462462
glfwGetMonitorWorkarea(monitor, monitorWorkAreaX, monitorWorkAreaY, monitorWorkAreaWidth, monitorWorkAreaHeight);
463-
final float workPosX = monitorWorkAreaX[0];
464-
final float workPosY = monitorWorkAreaY[0];
465-
final float workSizeX = monitorWorkAreaWidth[0];
466-
final float workSizeY = monitorWorkAreaHeight[0];
463+
464+
float workPosX = 0;
465+
float workPosY = 0;
466+
float workSizeX = 0;
467+
float workSizeY = 0;
468+
469+
// Workaround a small GLFW issue reporting zero on monitor changes: https://github.com/glfw/glfw/pull/1761
470+
if (monitorWorkAreaWidth[0] > 0 && monitorWorkAreaHeight[0] > 0) {
471+
workPosX = monitorWorkAreaX[0];
472+
workPosY = monitorWorkAreaY[0];
473+
workSizeX = monitorWorkAreaWidth[0];
474+
workSizeY = monitorWorkAreaHeight[0];
475+
}
467476

468477
// Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings,
469478
// which generally needs to be set in the manifest or at runtime.

0 commit comments

Comments
 (0)