feat: introduce binding generator
A squash of hundreds of commits with a binding API generator. The API generator works with a hybrid model: 1. We define methods and fields in the code. 2. Mark them with API annotations. 3. For specific use cases, we use the old approach with JNI generation comments. There is also an API to generate an AST tree, which is saved to JSON. This JSON can be used for full API generation by declaring only field/method names. Currently, it is used to generate constants. By eyeballing, 95% of the API has been converted to the new approach. This is sufficient for the current moment. Only edge cases with specific API calls are left. fix: ambiguous call for ImGui::GetColorU32 build: disable checkstyle for imgui-binding module Since the module is heavily generated, checkstyle for it doesn't make sense. build: make buildSrc to use JDK 11 build: make generateApi optional when compiling project Initially generated module was not included to the project VCS. Since it's now in the separate src folder, we don't need to call generator every time. Only when a new generation result is required.
This commit is contained in:
1 parent
e64df5a433
commit
8a8cd22ed6
323 files changed
+113518
-15318
No files matched your search
@@ -1,15 +1,19 @@
|
||||
package imgui;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
import imgui.binding.annotation.ArgValue;
|
||||
import imgui.binding.annotation.BindingField;
|
||||
import imgui.binding.annotation.BindingMethod;
|
||||
import imgui.binding.annotation.BindingSource;
|
||||
import imgui.binding.annotation.OptArg;
|
||||
import imgui.binding.annotation.ReturnValue;
|
||||
|
||||
/**
|
||||
* Font runtime data and rendering
|
||||
* ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
||||
*/
|
||||
@BindingSource
|
||||
public final class ImFont extends ImGuiStructDestroyable {
|
||||
private final ImFontGlyph fallbackGlyph = new ImFontGlyph(0);
|
||||
private final ImFontGlyph foundGlyph = new ImFontGlyph(0);
|
||||
|
||||
public ImFont() {
|
||||
}
|
||||
|
||||
@@ -17,17 +21,16 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include "_common.h"
|
||||
|
||||
#define IM_FONT ((ImFont*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
/*JNI
|
||||
#include "_common.h"
|
||||
#define THIS ((ImFont*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
private native long nCreate(); /*
|
||||
return (intptr_t)(new ImFont());
|
||||
*/
|
||||
@@ -37,37 +40,23 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
/**
|
||||
* = FallbackGlyph.AdvanceX
|
||||
*/
|
||||
public native float getFallbackAdvanceX(); /*
|
||||
return IM_FONT->FallbackAdvanceX;
|
||||
*/
|
||||
|
||||
/**
|
||||
* = FallbackGlyph.AdvanceX
|
||||
*/
|
||||
public native void setFallbackAdvanceX(float fallbackAdvanceX); /*
|
||||
IM_FONT->FallbackAdvanceX = fallbackAdvanceX;
|
||||
*/
|
||||
@BindingField
|
||||
public float FallbackAdvanceX;
|
||||
|
||||
/**
|
||||
* Height of characters/line, set during loading (don't change after loading)
|
||||
*/
|
||||
public native float getFontSize(); /*
|
||||
return IM_FONT->FontSize;
|
||||
*/
|
||||
@BindingField
|
||||
public float FontSize;
|
||||
|
||||
// TODO IndexLookup, Glyphs
|
||||
|
||||
/**
|
||||
* = FindGlyph(FontFallbackChar)
|
||||
*/
|
||||
public ImFontGlyph getFallbackGlyph() {
|
||||
fallbackGlyph.ptr = nGetFallbackGlyphPtr();
|
||||
return fallbackGlyph;
|
||||
}
|
||||
|
||||
private native long nGetFallbackGlyphPtr(); /*
|
||||
return (intptr_t)IM_FONT->FallbackGlyph;
|
||||
*/
|
||||
@BindingField
|
||||
@ReturnValue(isStatic = true)
|
||||
public ImFontGlyph FallbackGlyph;
|
||||
|
||||
// TODO ContainerAtlas, ConfigData
|
||||
|
||||
@@ -75,196 +64,79 @@ public final class ImFont extends ImGuiStructDestroyable {
|
||||
* Number of ImFontConfig involved in creating this font.
|
||||
* Bigger than 1 when merging multiple font sources into one ImFont.
|
||||
*/
|
||||
public native short getConfigDataCount(); /*
|
||||
return IM_FONT->ConfigDataCount;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Replacement character if a glyph isn't found.
|
||||
*/
|
||||
public native short getFallbackChar(); /*
|
||||
return IM_FONT->FallbackChar;
|
||||
*/
|
||||
@BindingField
|
||||
public short ConfigDataCount;
|
||||
|
||||
/**
|
||||
* Character used for ellipsis rendering.
|
||||
*/
|
||||
public native short getEllipsisChar(); /*
|
||||
return IM_FONT->EllipsisChar;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Character used for ellipsis rendering.
|
||||
*/
|
||||
public native void setEllipsisChar(int ellipsisChar); /*
|
||||
IM_FONT->EllipsisChar = (ImWchar)ellipsisChar;
|
||||
*/
|
||||
@BindingField
|
||||
public short EllipsisChar;
|
||||
|
||||
/**
|
||||
* Character used for ellipsis rendering (if a single '...' character isn't found)
|
||||
*/
|
||||
public native short getDotChar(); /*
|
||||
return IM_FONT->DotChar;
|
||||
*/
|
||||
@BindingField
|
||||
public short DotChar;
|
||||
|
||||
/**
|
||||
* Character used for ellipsis rendering (if a single '...' character isn't found)
|
||||
*/
|
||||
public native void setDotChar(int dotChar); /*
|
||||
IM_FONT->DotChar = (ImWchar)dotChar;
|
||||
*/
|
||||
|
||||
public native boolean getDirtyLookupTables(); /*
|
||||
return IM_FONT->DirtyLookupTables;
|
||||
*/
|
||||
|
||||
public native void setDirtyLookupTables(boolean dirtyLookupTables); /*
|
||||
IM_FONT->DirtyLookupTables = dirtyLookupTables;
|
||||
*/
|
||||
@BindingField
|
||||
public boolean DirtyLookupTables;
|
||||
|
||||
/**
|
||||
* Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
|
||||
*/
|
||||
public native float getScale(); /*
|
||||
return IM_FONT->Scale;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
|
||||
*/
|
||||
public native void setScale(float scale); /*
|
||||
IM_FONT->Scale = scale;
|
||||
*/
|
||||
@BindingField
|
||||
public float Scale;
|
||||
|
||||
/**
|
||||
* Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
*/
|
||||
public native float getAscent(); /*
|
||||
return IM_FONT->Ascent;
|
||||
*/
|
||||
@BindingField
|
||||
public float Ascent;
|
||||
|
||||
/**
|
||||
* Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
*/
|
||||
public native void setAscent(float ascent); /*
|
||||
IM_FONT->Ascent = ascent;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
*/
|
||||
public native float getDescent(); /*
|
||||
return IM_FONT->Descent;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
*/
|
||||
public native void setDescent(float descent); /*
|
||||
IM_FONT->Descent = descent;
|
||||
*/
|
||||
@BindingField
|
||||
public float Descent;
|
||||
|
||||
/**
|
||||
* Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
|
||||
*/
|
||||
public native int getMetricsTotalSurface(); /*
|
||||
return IM_FONT->MetricsTotalSurface;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
|
||||
*/
|
||||
public native void setMetricsTotalSurface(int metricsTotalSurface); /*
|
||||
IM_FONT->MetricsTotalSurface = metricsTotalSurface;
|
||||
*/
|
||||
@BindingField
|
||||
public int MetricsTotalSurface;
|
||||
|
||||
// Methods
|
||||
|
||||
public ImFontGlyph findGlyph(final int c) {
|
||||
foundGlyph.ptr = nFindGlyph(c);
|
||||
return foundGlyph;
|
||||
}
|
||||
@BindingMethod
|
||||
public native ImFontGlyph FindGlyph(@ArgValue(callPrefix = "(ImWchar)") int c);
|
||||
|
||||
private native long nFindGlyph(int c); /*
|
||||
return (intptr_t)IM_FONT->FindGlyph((ImWchar)c);
|
||||
*/
|
||||
@BindingMethod
|
||||
public native ImFontGlyph FindGlyphNoFallback(@ArgValue(callPrefix = "(ImWchar)") int c);
|
||||
|
||||
public ImFontGlyph findGlyphNoFallback(final int c) {
|
||||
foundGlyph.ptr = nFindGlyphNoFallback(c);
|
||||
return foundGlyph;
|
||||
}
|
||||
@BindingMethod
|
||||
public native float GetCharAdvance(@ArgValue(callPrefix = "(ImWchar)") int c);
|
||||
|
||||
private native long nFindGlyphNoFallback(int c); /*
|
||||
return (intptr_t)IM_FONT->FindGlyphNoFallback((ImWchar)c);
|
||||
*/
|
||||
@BindingMethod
|
||||
public native boolean IsLoaded();
|
||||
|
||||
public native float getCharAdvance(int c); /*
|
||||
return IM_FONT->GetCharAdvance((ImWchar)c);
|
||||
*/
|
||||
|
||||
public native boolean isLoaded(); /*
|
||||
return IM_FONT->IsLoaded();
|
||||
*/
|
||||
|
||||
public native String getDebugName(); /*
|
||||
return env->NewStringUTF(IM_FONT->GetDebugName());
|
||||
*/
|
||||
|
||||
public ImVec2 calcTextSizeA(final float size, final float maxWidth, final float wrapWidth, final String text) {
|
||||
final ImVec2 value = new ImVec2();
|
||||
calcTextSizeA(value, size, maxWidth, wrapWidth, text);
|
||||
return value;
|
||||
}
|
||||
@BindingMethod
|
||||
public native String GetDebugName();
|
||||
|
||||
/**
|
||||
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
||||
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
||||
*/
|
||||
public native void calcTextSizeA(ImVec2 dstImVec2, float size, float maxWidth, float wrapWidth, String text); /*
|
||||
Jni::ImVec2Cpy(env, IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text), dstImVec2);
|
||||
*/
|
||||
@BindingMethod
|
||||
public native ImVec2 CalcTextSizeA(float size, float maxWidth, float wrapWidth, String textBegin, @OptArg String textEnd);
|
||||
|
||||
/**
|
||||
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
||||
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
||||
@BindingMethod
|
||||
public native String CalcWordWrapPositionA(float scale, String text, String textEnd, float wrapWidth);
|
||||
|
||||
@BindingMethod
|
||||
public native void RenderChar(ImDrawList drawList, float size, ImVec2 pos, int col, @ArgValue(callPrefix = "(ImWchar)") int c);
|
||||
|
||||
@BindingMethod
|
||||
public native void RenderText(ImDrawList drawList, float size, ImVec2 pos, int col, ImVec4 clipRect, String textBegin, String textEnd, @OptArg(callValue = "0.0f") float wrapWidth, @OptArg boolean cpuFineClip);
|
||||
|
||||
/*JNI
|
||||
#undef THIS
|
||||
*/
|
||||
public native float calcTextSizeAX(float size, float maxWidth, float wrapWidth, String text); /*
|
||||
return IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text).x;
|
||||
*/
|
||||
|
||||
/**
|
||||
* 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
||||
* 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
||||
*/
|
||||
public native float calcTextSizeAY(float size, float maxWidth, float wrapWidth, String text); /*
|
||||
return IM_FONT->CalcTextSizeA(size, maxWidth, wrapWidth, text).y;
|
||||
*/
|
||||
|
||||
public native String calcWordWrapPositionA(float scale, String text, String textEnd, float wrapWidth); /*
|
||||
return env->NewStringUTF(IM_FONT->CalcWordWrapPositionA(scale, text, textEnd, wrapWidth));
|
||||
*/
|
||||
|
||||
public void renderChar(final ImDrawList drawList, final float size, final float posX, final float posY, final int col, final int c) {
|
||||
nRenderChar(drawList.ptr, size, posX, posY, col, c);
|
||||
}
|
||||
|
||||
private native void nRenderChar(long drawListPtr, float size, float posX, float posY, int col, int c); /*
|
||||
IM_FONT->RenderChar((ImDrawList*)drawListPtr, size, ImVec2(posX, posY), col, (ImWchar)c);
|
||||
*/
|
||||
|
||||
public void renderText(final ImDrawList drawList, final float size, final float posX, final float posY, final int col, final float clipRectX, final float clipRectY, final float clipRectW, final float clipRectZ, final String text, final String textEnd) {
|
||||
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, 0, false);
|
||||
}
|
||||
|
||||
public void renderText(final ImDrawList drawList, final float size, final float posX, final float posY, final int col, final float clipRectX, final float clipRectY, final float clipRectW, final float clipRectZ, final String text, final String textEnd, final float wrapWidth) {
|
||||
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, wrapWidth, false);
|
||||
}
|
||||
|
||||
public void renderText(final ImDrawList drawList, final float size, final float posX, final float posY, final int col, final float clipRectX, final float clipRectY, final float clipRectW, final float clipRectZ, final String text, final String textEnd, final float wrapWidth, final boolean cpuFineClip) {
|
||||
nRenderText(drawList.ptr, size, posX, posY, col, clipRectX, clipRectY, clipRectW, clipRectZ, text, textEnd, wrapWidth, cpuFineClip);
|
||||
}
|
||||
|
||||
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); /*
|
||||
IM_FONT->RenderText((ImDrawList*)drawListPtr, size, ImVec2(posX, posY), col, ImVec4(clipRectX, clipRectY, clipRectW, clipRectZ), text, textEnd, wrapWidth, cpuFineClip);
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user