Skip to content

Commit 01b7bec

Browse files
committed
[fonts] Remove TODO's with font stuff
1 parent 0589288 commit 01b7bec

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public final class ImGui {
2525
private static final ImDrawList IM_DRAW_LIST_BACKGROUND = new ImDrawList(ImDrawList.TYPE_BACKGROUND);
2626
private static final ImDrawList IM_DRAW_LIST_FOREGROUND = new ImDrawList(ImDrawList.TYPE_FOREGROUND);
2727

28+
private static ImFont font;
29+
2830
static {
2931
final String libPath = System.getProperty(LIB_PATH_PROP);
3032
final String libName = System.getProperty(LIB_NAME_PROP, LIB_NAME_DEFAULT);
@@ -123,7 +125,13 @@ private ImGui() {
123125
ImGui::CreateContext();
124126
*/
125127

126-
// public static void CreateContext(ImFontAtlas sharedFontAtlas) TODO create context with fonts
128+
public static void createContext(ImFontAtlas sharedFontAtlas) {
129+
nCreateContext(sharedFontAtlas.ptr);
130+
}
131+
132+
private static native void nCreateContext(long sharedFontAtlasPtr); /*
133+
ImGui::CreateContext((ImFontAtlas*)sharedFontAtlasPtr);
134+
*/
127135

128136
public static native void destroyContext(); /*
129137
ImGui::DestroyContext();
@@ -785,7 +793,13 @@ public static ImDrawList getWindowDrawList() {
785793

786794
// Parameters stacks (shared)
787795

788-
// TODO void PushFont(ImFont* font);
796+
public static void pushFont(ImFont font) {
797+
nPushFont(font.ptr);
798+
}
799+
800+
private static native void nPushFont(long fontPtr); /*
801+
ImGui::PushFont((ImFont*)fontPtr);
802+
*/
789803

790804
public static native void popFont(); /*
791805
ImGui::PopFont();
@@ -831,7 +845,19 @@ public static ImDrawList getWindowDrawList() {
831845
Jni::ImVec4Cpy(env, ImGui::GetStyleColorVec4(imGuiStyleVar), dstImVec4);
832846
*/
833847

834-
// TODO ImFont* GetFont();
848+
/**
849+
* Get current font.
850+
*/
851+
public static ImFont getFont() {
852+
if (font == null) {
853+
font = new ImFont(nGetFont());
854+
}
855+
return font;
856+
}
857+
858+
private static native long nGetFont(); /*
859+
return (long)ImGui::GetFont();
860+
*/
835861

836862
/**
837863
* Get current font size (= height in pixels) of current font with current scale applied
@@ -3367,7 +3393,6 @@ public static boolean selectable(String label, ImBool selected, int imGuiSelecta
33673393
*/
33683394

33693395
// Widgets: List Boxes
3370-
// - FIXME: To be consistent with all the newer API, ListBoxHeader/ListBoxFooter should in reality be called BeginListBox/EndListBox. Will rename them.
33713396

33723397
public static void listBox(String label, ImInt currentItem, String[] items, int itemsCount) {
33733398
nListBox(label, currentItem.data, items, itemsCount, -1);

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,48 @@ public ImFontAtlas getFonts() {
177177
*/
178178
public void setFonts(final ImFontAtlas imFontAtlas) {
179179
this.imFontAtlas = imFontAtlas;
180-
nSetImFontAtlas(imFontAtlas.ptr);
180+
nSetFonts(imFontAtlas.ptr);
181181
}
182182

183-
private native void nSetImFontAtlas(long imFontAtlasPtr); /*
183+
private native void nSetFonts(long imFontAtlasPtr); /*
184184
ImGui::GetIO().Fonts = (ImFontAtlas*)imFontAtlasPtr;
185185
*/
186186

187-
// TODO fonts configuration
187+
/**
188+
* Global scale all fonts
189+
*/
190+
public native float getFontGlobalScale(); /*
191+
return ImGui::GetIO().FontGlobalScale;
192+
*/
193+
194+
/**
195+
* Global scale all fonts
196+
*/
197+
public native void setFontGlobalScale(float fontGlobalScale); /*
198+
ImGui::GetIO().FontGlobalScale = fontGlobalScale;
199+
*/
200+
201+
/**
202+
* Allow user scaling text of individual window with CTRL+Wheel.
203+
*/
204+
public native boolean getFontAllowUserScaling(); /*
205+
return ImGui::GetIO().FontAllowUserScaling;
206+
*/
207+
208+
/**
209+
* Allow user scaling text of individual window with CTRL+Wheel.
210+
*/
211+
public native void setFontAllowUserScaling(boolean fontAllowUserScaling); /*
212+
ImGui::GetIO().FontAllowUserScaling = fontAllowUserScaling;
213+
*/
214+
215+
public void setFontDefault(final ImFont fontDefault) {
216+
nSetFontDefault(fontDefault.ptr);
217+
}
218+
219+
private native void nSetFontDefault(long fontDefaultPtr); /*
220+
ImGui::GetIO().FontDefault = (ImFont*)fontDefaultPtr;
221+
*/
188222

189223
// Miscellaneous options
190224

0 commit comments

Comments
 (0)