From 01b7bec5b2d9aed4d0b6f821a9f4c7b1b568044b Mon Sep 17 00:00:00 2001 From: SpaiR Date: Sun, 9 Feb 2020 19:35:11 +0300 Subject: [PATCH] [fonts] Remove TODO's with font stuff --- imgui-binding/src/main/java/imgui/ImGui.java | 33 +++++++++++++-- .../src/main/java/imgui/ImGuiIO.java | 40 +++++++++++++++++-- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/imgui-binding/src/main/java/imgui/ImGui.java b/imgui-binding/src/main/java/imgui/ImGui.java index 0d8e60c..3c6c7cc 100644 --- a/imgui-binding/src/main/java/imgui/ImGui.java +++ b/imgui-binding/src/main/java/imgui/ImGui.java @@ -25,6 +25,8 @@ public final class ImGui { private static final ImDrawList IM_DRAW_LIST_BACKGROUND = new ImDrawList(ImDrawList.TYPE_BACKGROUND); private static final ImDrawList IM_DRAW_LIST_FOREGROUND = new ImDrawList(ImDrawList.TYPE_FOREGROUND); + private static ImFont font; + static { final String libPath = System.getProperty(LIB_PATH_PROP); final String libName = System.getProperty(LIB_NAME_PROP, LIB_NAME_DEFAULT); @@ -123,7 +125,13 @@ public final class ImGui { ImGui::CreateContext(); */ - // public static void CreateContext(ImFontAtlas sharedFontAtlas) TODO create context with fonts + public static void createContext(ImFontAtlas sharedFontAtlas) { + nCreateContext(sharedFontAtlas.ptr); + } + + private static native void nCreateContext(long sharedFontAtlasPtr); /* + ImGui::CreateContext((ImFontAtlas*)sharedFontAtlasPtr); + */ public static native void destroyContext(); /* ImGui::DestroyContext(); @@ -785,7 +793,13 @@ public final class ImGui { // Parameters stacks (shared) - // TODO void PushFont(ImFont* font); + public static void pushFont(ImFont font) { + nPushFont(font.ptr); + } + + private static native void nPushFont(long fontPtr); /* + ImGui::PushFont((ImFont*)fontPtr); + */ public static native void popFont(); /* ImGui::PopFont(); @@ -831,7 +845,19 @@ public final class ImGui { Jni::ImVec4Cpy(env, ImGui::GetStyleColorVec4(imGuiStyleVar), dstImVec4); */ - // TODO ImFont* GetFont(); + /** + * Get current font. + */ + public static ImFont getFont() { + if (font == null) { + font = new ImFont(nGetFont()); + } + return font; + } + + private static native long nGetFont(); /* + return (long)ImGui::GetFont(); + */ /** * Get current font size (= height in pixels) of current font with current scale applied @@ -3367,7 +3393,6 @@ public final class ImGui { */ // Widgets: List Boxes - // - FIXME: To be consistent with all the newer API, ListBoxHeader/ListBoxFooter should in reality be called BeginListBox/EndListBox. Will rename them. public static void listBox(String label, ImInt currentItem, String[] items, int itemsCount) { nListBox(label, currentItem.data, items, itemsCount, -1); diff --git a/imgui-binding/src/main/java/imgui/ImGuiIO.java b/imgui-binding/src/main/java/imgui/ImGuiIO.java index dc4b58b..256b0a4 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiIO.java +++ b/imgui-binding/src/main/java/imgui/ImGuiIO.java @@ -177,14 +177,48 @@ public final class ImGuiIO { */ public void setFonts(final ImFontAtlas imFontAtlas) { this.imFontAtlas = imFontAtlas; - nSetImFontAtlas(imFontAtlas.ptr); + nSetFonts(imFontAtlas.ptr); } - private native void nSetImFontAtlas(long imFontAtlasPtr); /* + private native void nSetFonts(long imFontAtlasPtr); /* ImGui::GetIO().Fonts = (ImFontAtlas*)imFontAtlasPtr; */ - // TODO fonts configuration + /** + * Global scale all fonts + */ + public native float getFontGlobalScale(); /* + return ImGui::GetIO().FontGlobalScale; + */ + + /** + * Global scale all fonts + */ + public native void setFontGlobalScale(float fontGlobalScale); /* + ImGui::GetIO().FontGlobalScale = fontGlobalScale; + */ + + /** + * Allow user scaling text of individual window with CTRL+Wheel. + */ + public native boolean getFontAllowUserScaling(); /* + return ImGui::GetIO().FontAllowUserScaling; + */ + + /** + * Allow user scaling text of individual window with CTRL+Wheel. + */ + public native void setFontAllowUserScaling(boolean fontAllowUserScaling); /* + ImGui::GetIO().FontAllowUserScaling = fontAllowUserScaling; + */ + + public void setFontDefault(final ImFont fontDefault) { + nSetFontDefault(fontDefault.ptr); + } + + private native void nSetFontDefault(long fontDefaultPtr); /* + ImGui::GetIO().FontDefault = (ImFont*)fontDefaultPtr; + */ // Miscellaneous options