diff --git a/addons/imgui-godot/ImGuiGodot/Internal/Fonts.cs b/addons/imgui-godot/ImGuiGodot/Internal/Fonts.cs index 1a0291f..fa22065 100644 --- a/addons/imgui-godot/ImGuiGodot/Internal/Fonts.cs +++ b/addons/imgui-godot/ImGuiGodot/Internal/Fonts.cs @@ -16,6 +16,7 @@ private sealed class FontParams public FontFile? Font { get; init; } public int FontSize { get; init; } public bool Merge { get; init; } + public ushort[] Ranges { get; init; } } private readonly List _fontConfiguration = new(); @@ -32,12 +33,12 @@ public void ResetFonts() _fontConfiguration.Clear(); } - public void AddFont(FontFile? fontData, int fontSize, bool merge) + public void AddFont(FontFile? fontData, int fontSize, bool merge, ushort[] predefinedRanges = null) { - _fontConfiguration.Add(new FontParams { Font = fontData, FontSize = fontSize, Merge = merge }); + _fontConfiguration.Add(new FontParams { Font = fontData, FontSize = fontSize, Merge = merge, Ranges = predefinedRanges}); } - private static unsafe void AddFontToAtlas(FontFile? fontData, int fontSize, bool merge) + private static unsafe void AddFontToAtlas(FontFile? fontData, int fontSize, bool merge, ushort[] predefinedRanges) { ImFontConfig* fc = ImGuiNative.ImFontConfig_ImFontConfig(); if (merge) @@ -70,7 +71,14 @@ private static unsafe void AddFontToAtlas(FontFile? fontData, int fontSize, bool // let ImGui manage this memory IntPtr p = ImGui.MemAlloc((uint)len); Marshal.Copy(fontData.Data, 0, p, len); - ImGui.GetIO().Fonts.AddFontFromMemoryTTF(p, len, fontSize, fc, ranges.Data); + if ( predefinedRanges == null ) { + ImGui.GetIO().Fonts.AddFontFromMemoryTTF(p, len, fontSize, fc, ranges.Data); + } + else { + fixed ( ushort* rangesPtr = predefinedRanges ) { + ImGui.GetIO().Fonts.AddFontFromMemoryTTF(p, len, fontSize, fc, ( IntPtr )rangesPtr); + } + } } if (merge) @@ -143,7 +151,7 @@ public unsafe void RebuildFontAtlas(float scale) foreach (var fontParams in _fontConfiguration) { - AddFontToAtlas(fontParams.Font, (int)(fontParams.FontSize * scale), fontParams.Merge); + AddFontToAtlas(fontParams.Font, (int)(fontParams.FontSize * scale), fontParams.Merge, fontParams.Ranges); } io.Fonts.GetTexDataAsRGBA32(out byte* pixelData, out int width, out int height, out int bytesPerPixel); diff --git a/addons/imgui-godot/plugin.cfg b/addons/imgui-godot/plugin.cfg index a69a7a8..940f9d4 100644 --- a/addons/imgui-godot/plugin.cfg +++ b/addons/imgui-godot/plugin.cfg @@ -5,3 +5,4 @@ description="Dear ImGui for Godot" author="Patrick Dawson" version="4.1.0" script="scripts/ImGuiPlugin.gd" +version="4.1.1"