Skip to content

Commit b67491b

Browse files
committed
Additional logic to preserve ImGuiKey.ModXYZ naming.
1 parent 83fc862 commit b67491b

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/CodeGenerator/ImguiDefinitions.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,30 @@ public string SanitizeNames(string text)
280280
private string SanitizeMemberName(string memberName)
281281
{
282282
string ret = memberName;
283-
foreach (string name in Names)
283+
bool altSubstitution = false;
284+
285+
// Try alternate substitution first
286+
foreach (KeyValuePair<string, string> substitutionPair in TypeInfo.AlternateEnumPrefixSubstitutions)
287+
{
288+
if (memberName.StartsWith(substitutionPair.Key))
289+
{
290+
ret = ret.Replace(substitutionPair.Key, substitutionPair.Value);
291+
altSubstitution = true;
292+
break;
293+
}
294+
}
295+
296+
if (!altSubstitution)
284297
{
285-
if (memberName.StartsWith(name))
298+
foreach (string name in Names)
286299
{
287-
ret = memberName.Substring(name.Length);
288-
if (ret.StartsWith("_"))
300+
if (memberName.StartsWith(name))
289301
{
290-
ret = ret.Substring(1);
302+
ret = memberName.Substring(name.Length);
303+
if (ret.StartsWith("_"))
304+
{
305+
ret = ret.Substring(1);
306+
}
291307
}
292308
}
293309
}
@@ -297,7 +313,7 @@ private string SanitizeMemberName(string memberName)
297313
ret = ret.Substring(0, ret.Length - 1);
298314
}
299315

300-
if (Char.IsDigit(ret.First()))
316+
if (char.IsDigit(ret.First()))
301317
ret = "_" + ret;
302318

303319
return ret;

src/CodeGenerator/TypeInfo.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public class TypeInfo
6767
{
6868
{ "ImGuiKey", "ImGuiMod" },
6969
};
70-
70+
71+
public static readonly Dictionary<string, string> AlternateEnumPrefixSubstitutions = new Dictionary<string, string>()
72+
{
73+
{ "ImGuiMod_", "Mod" },
74+
};
75+
7176
public static readonly Dictionary<string, string> WellKnownFieldReplacements = new Dictionary<string, string>()
7277
{
7378
{ "bool", "bool" }, // Force bool to remain as bool in type-safe wrappers.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ public enum ImGuiKey
144144
ReservedForModAlt = 650,
145145
ReservedForModSuper = 651,
146146
COUNT = 652,
147-
None = 0,
148-
Ctrl = 4096,
149-
Shift = 8192,
150-
Alt = 16384,
151-
Super = 32768,
152-
Mask = 61440,
153-
Shortcut = 4096,
147+
ModNone = 0,
148+
ModCtrl = 4096,
149+
ModShift = 8192,
150+
ModAlt = 16384,
151+
ModSuper = 32768,
152+
ModMask = 61440,
153+
ModShortcut = 4096,
154154
NamedKey_BEGIN = 512,
155155
NamedKey_END = 652,
156156
NamedKey_COUNT = 140,

0 commit comments

Comments
 (0)