From f932a7704bfcabdd9d91d947e14f03e463fedf04 Mon Sep 17 00:00:00 2001 From: NepuShiro Date: Thu, 21 May 2026 23:33:23 -0500 Subject: [PATCH] b --- Program.cs | 24 ++++++++++++++++++++++++ SDL3/FontFind.cs | 24 ++++++++++++++++++++---- SDL3/SDL3Window.cs | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index 1193296..b6bee1c 100644 --- a/Program.cs +++ b/Program.cs @@ -71,6 +71,30 @@ public class Program ImGui.EndMenuBar(); } + string hash = "AAAA"; + bool hasValue = true; + string text2 = ""; + + if (ImGui.InputTextWithHint($"##{hash}", hasValue ? "" : "Null", ref text2, 99999, ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.CtrlEnterForNewLine)) + { + + } + + float buttonSize = ImGui.GetFrameHeight(); + + float avail = ImGui.GetContentRegionAvail().X; + float inputWidth = avail - buttonSize; + + ImGui.PushItemWidth(inputWidth); + ImGui.SameLine(0f, 0f); + + if (ImGui.Button($"X##{hash}_clear", new Vector2(buttonSize, buttonSize))) + { + } + + ImGui.PopItemWidth(); + + ImGui.End(); if (_fontStuff) diff --git a/SDL3/FontFind.cs b/SDL3/FontFind.cs index 15c00b8..d29a547 100644 --- a/SDL3/FontFind.cs +++ b/SDL3/FontFind.cs @@ -21,7 +21,7 @@ public static class FontFind { extension(ImGuiIOPtr io) { - public unsafe ImFontPtr AddFont(string fontPath) + public unsafe ImFontPtr AddFont(string fontPath, bool merge = false) { try { @@ -29,13 +29,14 @@ public static class FontFind FileInfo info = new FileInfo(fontPath); if (!info.Exists || info.Length <= 0) return null; - FontMetrics metrics = ReadFontMetrics(fontPath); + FontMetrics metrics = ReadFontMetricsSafe(fontPath); float size = GetRecommendedPixelSize(metrics); ImFontConfigPtr config = ImGui.ImFontConfig(); - config.FontLoaderFlags |= (uint)ImGuiFreeTypeLoaderFlags.LoadColor; + config.FontLoaderFlags |= (uint)ImGuiFreeTypeLoaderFlags.LoadColor | (uint)ImGuiFreeTypeLoaderFlags.Bitmap; + config.MergeMode = merge; ImFontPtr font = io.Fonts.AddFontFromFileTTF(fontPath, size, config); - Program.Logger.Log("Added font: " + Path.GetFileName(fontPath)); + Program.Logger.Log($"{(merge ? "Merged" : "Added")} font: " + Path.GetFileName(fontPath)); return font; } catch (Exception e) @@ -71,6 +72,21 @@ public static class FontFind return flag; } } + + public static FontMetrics ReadFontMetricsSafe(string fontPath) + { + try + { + return ReadFontMetrics(fontPath); + } + catch (Exception ex) + { + Console.WriteLine("Font parsing failed: " + fontPath); + Console.WriteLine(ex.ToString()); + + return new FontMetrics(); + } + } public static FontMetrics ReadFontMetrics(string fontPath) { diff --git a/SDL3/SDL3Window.cs b/SDL3/SDL3Window.cs index a46f1b3..fefc580 100644 --- a/SDL3/SDL3Window.cs +++ b/SDL3/SDL3Window.cs @@ -102,23 +102,52 @@ public sealed unsafe class SDL3Window : IDisposable if (!File.Exists(b.FullPath)) return; if (Path.GetExtension(b.FullPath) != ".ttf") return; - ImGui.GetIO().AddFont(b.FullPath); }; _watcher.Deleted += (_, b) => { if (Path.GetExtension(b.FullPath) != ".ttf") return; - ImGui.GetIO().RemoveFont(b.Name); }; + _watcher.Renamed += (_, b) => + { + if (Path.GetExtension(b.OldFullPath) != ".ttf") return; + ImGui.GetIO().RemoveFont(b.OldName); + + if (!File.Exists(b.FullPath)) return; + if (Path.GetExtension(b.FullPath) != ".ttf") return; + ImGui.GetIO().AddFont(b.FullPath); + }; _watcher.IncludeSubdirectories = false; _watcher.EnableRaisingEvents = true; - string[] fonts = Directory.GetFiles(fontsPath, "*.ttf", SearchOption.AllDirectories); + List fonts = Directory.GetFiles(fontsPath, "*.ttf", SearchOption.AllDirectories).ToList(); + fonts.Sort(); + + List mergeFonts = new List(); + for (int i = fonts.Count - 1; i >= 0; i--) + { + if (Path.GetFileName(fonts[i]).StartsWith("merge_", StringComparison.OrdinalIgnoreCase)) + { + mergeFonts.Add(fonts[i]); + fonts.RemoveAt(i); + } + } + mergeFonts.Reverse(); + + foreach (string merge in mergeFonts) + { + io.AddFont(merge, true); + } + foreach (string font in fonts) { io.AddFont(font); + foreach (string merge in mergeFonts) + { + io.AddFont(merge, true); + } } } catch (Exception e)