Skip to content

Commit cd6432b

Browse files
committed
[API] Add ImFont methods
Added: - FindGlyph - FindGlyphNoFallback - GetCharAdvance - IsLoaded - GetDebugName - CalcTextSizeA - CalcWordWrapPositionA - RenderChar - RenderText
1 parent a2444c6 commit cd6432b

File tree

1 file changed

+93
-2
lines changed

1 file changed

+93
-2
lines changed

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

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
public final class ImFont extends ImGuiStructDestroyable {
1010
private ImFontGlyph fallbackGlyph = null;
11+
private ImFontGlyph foundGlyph = new ImFontGlyph(0);
1112

1213
public ImFont() {
1314
}
@@ -100,7 +101,7 @@ public ImFontGlyph getFallbackGlyph() {
100101
/**
101102
* Character used for ellipsis rendering.
102103
*/
103-
public native void setEllipsisChar(short ellipsisChar); /*
104+
public native void setEllipsisChar(int ellipsisChar); /*
104105
IM_FONT->EllipsisChar = (ImWchar)ellipsisChar;
105106
*/
106107

@@ -168,5 +169,95 @@ public ImFontGlyph getFallbackGlyph() {
168169
IM_FONT->MetricsTotalSurface = metricsTotalSurface;
169170
*/
170171

171-
// TODO methods
172+
// Methods
173+
174+
public ImFontGlyph findGlyph(int c) {
175+
final long ptr = nFindGlyph(c);
176+
if (ptr == 0) {
177+
return null;
178+
}
179+
foundGlyph.ptr = ptr;
180+
return foundGlyph;
181+
}
182+
183+
private native long nFindGlyph(int c); /*
184+
return (intptr_t)IM_FONT->FindGlyph((ImWchar)c);
185+
*/
186+
187+
public ImFontGlyph findGlyphNoFallback(int c) {
188+
final long ptr = nFindGlyphNoFallback(c);
189+
if (ptr == 0) {
190+
return null;
191+
}
192+
foundGlyph.ptr = ptr;
193+
return foundGlyph;
194+
}
195+
196+
private native long nFindGlyphNoFallback(int c); /*
197+
return (intptr_t)IM_FONT->FindGlyphNoFallback((ImWchar)c);
198+
*/
199+
200+
public native float getCharAdvance(int c); /*
201+
return IM_FONT->GetCharAdvance((ImWchar)c);
202+
*/
203+
204+
public native boolean isLoaded(); /*
205+
return IM_FONT->IsLoaded();
206+
*/
207+
208+
public native String getDebugName(); /*
209+
return env->NewStringUTF(IM_FONT->GetDebugName());
210+
*/
211+
212+
/**
213+
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
214+
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
215+
*/
216+
public native void calcTextSizeA(ImVec2 dstImVec2, float size, float maxWidth, float wrapWidth, String text); /*
217+
Jni::ImVec2Cpy(env, IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text), dstImVec2);
218+
*/
219+
220+
/**
221+
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
222+
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
223+
*/
224+
public native float calcTextSizeAX(float size, float maxWidth, float wrapWidth, String text); /*
225+
return IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text).x;
226+
*/
227+
228+
/**
229+
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
230+
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
231+
*/
232+
public native float calcTextSizeAY(float size, float maxWidth, float wrapWidth, String text); /*
233+
return IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text).y;
234+
*/
235+
236+
public native String calcWordWrapPositionA(float scale, String text, String textEnd, float wrapWidth); /*
237+
return env->NewStringUTF(IM_FONT->CalcWordWrapPositionA(scale, text, textEnd, wrapWidth));
238+
*/
239+
240+
public void renderChar(ImDrawList drawList, float size, float posX, float posY, int col, int c) {
241+
nRenderChar(drawList.ptr, size, posX, posY, col, c);
242+
}
243+
244+
private native void nRenderChar(long drawListPtr, float size, float posX, float posY, int col, int c); /*
245+
IM_FONT->RenderChar((ImDrawList*)drawListPtr, size, ImVec2(posX, posY), col, (ImWchar)c);
246+
*/
247+
248+
public void renderText(ImDrawList drawList, float size, float posX, float posY, int col, float clipRectX, float clipRectY, float clipRectW, float clipRectZ, String text, String textEnd) {
249+
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, 0, false);
250+
}
251+
252+
public void renderText(ImDrawList drawList, float size, float posX, float posY, int col, float clipRectX, float clipRectY, float clipRectW, float clipRectZ, String text, String textEnd, float wrapWidth) {
253+
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, wrapWidth, false);
254+
}
255+
256+
public void renderText(ImDrawList drawList, float size, float posX, float posY, int col, float clipRectX, float clipRectY, float clipRectW, float clipRectZ, String text, String textEnd, float wrapWidth, boolean cpuFineClip) {
257+
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, wrapWidth, cpuFineClip);
258+
}
259+
260+
private native void nRenderText(long drawListPtr, float size, float posX, float posY, int col, float clipRectX, float clipRectY, float clipRectW, float clipRectZ, String text, String textEnd, float wrapWidth, boolean cpuFineClip); /*
261+
IM_FONT->RenderText((ImDrawList*)drawListPtr, size, ImVec2(posX, posY), col, ImVec4(clipRectX, clipRectY, clipRectW, clipRectZ), text, textEnd, wrapWidth, cpuFineClip);
262+
*/
172263
}

0 commit comments

Comments
 (0)