Skip to content

Commit 7ddf242

Browse files
committed
Natively mapped ImGuiStyle class
1 parent 1833ab5 commit 7ddf242

File tree

2 files changed

+385
-209
lines changed

2 files changed

+385
-209
lines changed

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public final class ImGui {
1919

2020
private static final ImDrawData DRAW_DATA;
2121
private static final ImGuiIO IMGUI_IO;
22-
private static final ImGuiStyle IMGUI_STYLE;
2322

2423
private static final ImDrawList IM_DRAW_LIST_WINDOW = new ImDrawList(ImDrawList.TYPE_WINDOW);
2524
private static final ImDrawList IM_DRAW_LIST_BACKGROUND = new ImDrawList(ImDrawList.TYPE_BACKGROUND);
2625
private static final ImDrawList IM_DRAW_LIST_FOREGROUND = new ImDrawList(ImDrawList.TYPE_FOREGROUND);
2726

2827
private static ImFont font;
28+
private static ImGuiStyle style;
2929

3030
static {
3131
final String libPath = System.getProperty(LIB_PATH_PROP);
@@ -44,7 +44,6 @@ public final class ImGui {
4444

4545
DRAW_DATA = new ImDrawData(100_000, 100_000, 1000);
4646
IMGUI_IO = new ImGuiIO();
47-
IMGUI_STYLE = new ImGuiStyle();
4847

4948
nInitJni();
5049
ImDrawList.nInit();
@@ -53,6 +52,7 @@ public final class ImGui {
5352
ImFontConfig.nInit();
5453
ImFontGlyph.nInit();
5554
ImFont.nInit();
55+
ImGuiStyle.nInit();
5656
nInitInputTextData();
5757
}
5858

@@ -150,9 +150,16 @@ public static ImGuiIO getIO() {
150150
* Access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame.
151151
*/
152152
public static ImGuiStyle getStyle() {
153-
return IMGUI_STYLE;
153+
if (style == null) {
154+
style = new ImGuiStyle(nGetStyle());
155+
}
156+
return style;
154157
}
155158

159+
private static native long nGetStyle(); /*
160+
return (long)(intptr_t)&ImGui::GetStyle();
161+
*/
162+
156163
/**
157164
* Start a new Dear ImGui frame, you can submit any command from this point until Render()/EndFrame().
158165
*/
@@ -248,6 +255,14 @@ public static void showMetricsWindow(ImBool pOpen) {
248255
ImGui::ShowStyleEditor();
249256
*/
250257

258+
public static void showStyleEditor(ImGuiStyle ref) {
259+
nShowStyleEditor(ref.ptr);
260+
}
261+
262+
private static native void nShowStyleEditor(long ref); /*
263+
ImGui::ShowStyleEditor((ImGuiStyle*)ref);
264+
*/
265+
251266
/**
252267
* Add style selector block (not a window), essentially a combo listing the default styles.
253268
*/
@@ -285,20 +300,44 @@ public static void showMetricsWindow(ImBool pOpen) {
285300
ImGui::StyleColorsDark();
286301
*/
287302

303+
public static void styleColorsDark(ImGuiStyle ref) {
304+
nStyleColorsDark(ref.ptr);
305+
}
306+
307+
private static native void nStyleColorsDark(long ref); /*
308+
ImGui::StyleColorsDark((ImGuiStyle*)ref);
309+
*/
310+
288311
/**
289312
* Classic imgui style
290313
*/
291314
public static native void styleColorsClassic(); /*
292315
ImGui::StyleColorsClassic();
293316
*/
294317

318+
public static void styleColorsClassic(ImGuiStyle ref) {
319+
nStyleColorsClassic(ref.ptr);
320+
}
321+
322+
private static native void nStyleColorsClassic(long ref); /*
323+
ImGui::StyleColorsClassic((ImGuiStyle*)ref);
324+
*/
325+
295326
/**
296327
* Best used with borders and a custom, thicker font
297328
*/
298329
public static native void styleColorsLight(); /*
299330
ImGui::StyleColorsLight();
300331
*/
301332

333+
public static void styleColorsLight(ImGuiStyle ref) {
334+
nStyleColorsLight(ref.ptr);
335+
}
336+
337+
private static native void nStyleColorsLight(long ref); /*
338+
ImGui::StyleColorsLight((ImGuiStyle*)ref);
339+
*/
340+
302341
// Windows
303342
// - Begin() = push window to the stack and start appending to it. End() = pop window from the stack.
304343
// - You may append multiple times to the same window during the same frame.

0 commit comments

Comments
 (0)