Skip to content

Commit 2e31c95

Browse files
committed
Update CodeGenerator to handle the latest output from cimgui.
1 parent 57de7ca commit 2e31c95

12 files changed

Lines changed: 17289 additions & 425 deletions

src/CodeGenerator/Program.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ class Program
4444
{ "float&", "float*" },
4545
{ "ImVec2[2]", "Vector2*" },
4646
{ "char* []", "byte**" },
47-
48-
// TODO: These shouldn't exist
49-
{ "ImVector_ImWchar", "ImVector" },
50-
{ "ImVector_TextRange", "ImVector" },
51-
{ "ImVector_TextRange&", "ImVector*" },
5247
};
5348

5449
private static readonly Dictionary<string, string> s_wellKnownFieldReplacements = new Dictionary<string, string>()
@@ -170,7 +165,8 @@ static void Main(string[] args)
170165
{
171166
string ov_cimguiname = val["ov_cimguiname"]?.ToString();
172167
string cimguiname = val["cimguiname"].ToString();
173-
string friendlyName = val["funcname"].ToString();
168+
string friendlyName = val["funcname"]?.ToString();
169+
if (friendlyName == null) { return null; }
174170

175171
string exportedName = ov_cimguiname;
176172
if (exportedName == null)
@@ -191,10 +187,6 @@ static void Main(string[] args)
191187
}
192188

193189
List<TypeReference> parameters = new List<TypeReference>();
194-
if (selfTypeName != null)
195-
{
196-
parameters.Add(new TypeReference("self", selfTypeName + "*", enums));
197-
}
198190

199191
foreach (JToken p in val["argsT"])
200192
{
@@ -624,8 +616,11 @@ private static void EmitOverload(
624616
else
625617
{
626618
preCallLines.Add($"byte* {nativeArgName};");
627-
preCallLines.Add($"if ({textToEncode} != null)");
628-
preCallLines.Add("{");
619+
if (!hasDefault)
620+
{
621+
preCallLines.Add($"if ({textToEncode} != null)");
622+
preCallLines.Add("{");
623+
}
629624
preCallLines.Add($" int {correctedIdentifier}_byteCount = Encoding.UTF8.GetByteCount({textToEncode});");
630625
preCallLines.Add($" byte* {nativeArgName}_stackBytes = stackalloc byte[{correctedIdentifier}_byteCount + 1];");
631626
preCallLines.Add($" {nativeArgName} = {nativeArgName}_stackBytes;");
@@ -634,8 +629,11 @@ private static void EmitOverload(
634629
preCallLines.Add($" int {nativeArgName}_offset = Encoding.UTF8.GetBytes({correctedIdentifier}_ptr, {textToEncode}.Length, {nativeArgName}, {correctedIdentifier}_byteCount);");
635630
preCallLines.Add($" {nativeArgName}[{nativeArgName}_offset] = 0;");
636631
preCallLines.Add(" }");
637-
preCallLines.Add("}");
638-
preCallLines.Add($"else {{ {nativeArgName} = null; }}");
632+
if (!hasDefault)
633+
{
634+
preCallLines.Add("}");
635+
preCallLines.Add($"else {{ {nativeArgName} = null; }}");
636+
}
639637
}
640638
}
641639
else if (tr.Type == "char* []")
@@ -727,7 +725,7 @@ private static void EmitOverload(
727725
nonPtrType = GetTypeString(tr.Type.Substring(0, tr.Type.Length - 1), false);
728726
}
729727
string nativeArgName = "native_" + tr.Name;
730-
bool isOutParam = tr.Name.Contains("out_");
728+
bool isOutParam = tr.Name.Contains("out_") || tr.Name == "out";
731729
string direction = isOutParam ? "out" : "ref";
732730
marshalledParameters[i] = new MarshalledParameter($"{direction} {nonPtrType}", true, nativeArgName, false);
733731
marshalledParameters[i].PinTarget = CorrectIdentifier(tr.Name);
@@ -853,7 +851,7 @@ private static string GetSafeType(TypeReference typeRef)
853851

854852
private static bool GetWrappedType(string nativeType, out string wrappedType)
855853
{
856-
if (nativeType.StartsWith("Im") && nativeType.EndsWith("*"))
854+
if (nativeType.StartsWith("Im") && nativeType.EndsWith("*") && !nativeType.StartsWith("ImVector"))
857855
{
858856
int pointerLevel = nativeType.Length - nativeType.IndexOf('*');
859857
if (pointerLevel > 1)
@@ -1031,6 +1029,20 @@ public TypeReference(string name, string type, string templateType, EnumDefiniti
10311029
{
10321030
Name = name;
10331031
Type = type.Replace("const", string.Empty).Trim();
1032+
1033+
1034+
if (Type.StartsWith("ImVector_"))
1035+
{
1036+
if (Type.EndsWith("*"))
1037+
{
1038+
Type = "ImVector*";
1039+
}
1040+
else
1041+
{
1042+
Type = "ImVector";
1043+
}
1044+
}
1045+
10341046
TemplateType = templateType;
10351047
int startBracket = name.IndexOf('[');
10361048
if (startBracket != -1)

src/CodeGenerator/definitions.json

Lines changed: 14511 additions & 1 deletion
Large diffs are not rendered by default.

src/CodeGenerator/structs_and_enums.json

Lines changed: 2583 additions & 1 deletion
Large diffs are not rendered by default.

src/ImGui.NET/Generated/ImDrawList.gen.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public void ChannelsSplit(int channels_count)
5454
{
5555
ImGuiNative.ImDrawList_ChannelsSplit(NativePtr, channels_count);
5656
}
57+
public void AddQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d, uint col)
58+
{
59+
float thickness = 1.0f;
60+
ImGuiNative.ImDrawList_AddQuad(NativePtr, a, b, c, d, col, thickness);
61+
}
62+
public void AddQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d, uint col, float thickness)
63+
{
64+
ImGuiNative.ImDrawList_AddQuad(NativePtr, a, b, c, d, col, thickness);
65+
}
5766
public void AddPolyline(ref Vector2 points, int num_points, uint col, bool closed, float thickness)
5867
{
5968
byte native_closed = closed ? (byte)1 : (byte)0;
@@ -137,15 +146,6 @@ public void PrimRect(Vector2 a, Vector2 b, uint col)
137146
{
138147
ImGuiNative.ImDrawList_PrimRect(NativePtr, a, b, col);
139148
}
140-
public void AddQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d, uint col)
141-
{
142-
float thickness = 1.0f;
143-
ImGuiNative.ImDrawList_AddQuad(NativePtr, a, b, c, d, col, thickness);
144-
}
145-
public void AddQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d, uint col, float thickness)
146-
{
147-
ImGuiNative.ImDrawList_AddQuad(NativePtr, a, b, c, d, col, thickness);
148-
}
149149
public void ClearFreeMemory()
150150
{
151151
ImGuiNative.ImDrawList_ClearFreeMemory(NativePtr);

src/ImGui.NET/Generated/ImFont.gen.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public unsafe partial struct ImFontPtr
4848
public ref float Descent => ref Unsafe.AsRef<float>(&NativePtr->Descent);
4949
public ref bool DirtyLookupTables => ref Unsafe.AsRef<bool>(&NativePtr->DirtyLookupTables);
5050
public ref int MetricsTotalSurface => ref Unsafe.AsRef<int>(&NativePtr->MetricsTotalSurface);
51+
public void GrowIndex(int new_size)
52+
{
53+
ImGuiNative.ImFont_GrowIndex(NativePtr, new_size);
54+
}
5155
public void AddRemapChar(ushort dst, ushort src)
5256
{
5357
byte overwrite_dst = 1;
@@ -62,10 +66,6 @@ public void AddGlyph(ushort c, float x0, float y0, float x1, float y1, float u0,
6266
{
6367
ImGuiNative.ImFont_AddGlyph(NativePtr, c, x0, y0, x1, y1, u0, v0, u1, v1, advance_x);
6468
}
65-
public void GrowIndex(int new_size)
66-
{
67-
ImGuiNative.ImFont_GrowIndex(NativePtr, new_size);
68-
}
6969
public ImFontGlyphPtr FindGlyphNoFallback(ushort c)
7070
{
7171
ImFontGlyph* ret = ImGuiNative.ImFont_FindGlyphNoFallback(NativePtr, c);

src/ImGui.NET/Generated/ImFontAtlas.gen.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public unsafe partial struct ImFontAtlasPtr
4646
public ImVector<CustomRect> CustomRects => new ImVector<CustomRect>(NativePtr->CustomRects);
4747
public ImPtrVector<ImFontConfigPtr> ConfigData => new ImPtrVector<ImFontConfigPtr>(NativePtr->ConfigData, Unsafe.SizeOf<ImFontConfig>());
4848
public RangeAccessor<int> CustomRectIds => new RangeAccessor<int>(NativePtr->CustomRectIds, 1);
49+
public void ClearFonts()
50+
{
51+
ImGuiNative.ImFontAtlas_ClearFonts(NativePtr);
52+
}
4953
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels)
5054
{
5155
byte* native_compressed_font_data_base85;
@@ -178,10 +182,6 @@ public void ClearTexData()
178182
{
179183
ImGuiNative.ImFontAtlas_ClearTexData(NativePtr);
180184
}
181-
public void ClearFonts()
182-
{
183-
ImGuiNative.ImFontAtlas_ClearFonts(NativePtr);
184-
}
185185
public void Clear()
186186
{
187187
ImGuiNative.ImFontAtlas_Clear(NativePtr);

0 commit comments

Comments
 (0)