b
This commit is contained in:
+24
@@ -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)
|
||||
|
||||
+20
-4
@@ -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)
|
||||
@@ -72,6 +73,21 @@ public static class FontFind
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(fontPath);
|
||||
|
||||
+32
-3
@@ -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<string> fonts = Directory.GetFiles(fontsPath, "*.ttf", SearchOption.AllDirectories).ToList();
|
||||
fonts.Sort();
|
||||
|
||||
List<string> mergeFonts = new List<string>();
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user