From 38ea69977c870b38f48f307de0d9b1eb1aa4046e Mon Sep 17 00:00:00 2001 From: juju2143 Date: Fri, 10 Nov 2023 16:45:01 -0500 Subject: [PATCH] Add font ranges --- MainUI.cs | 28 +++++++++++++++++++++++----- Program.cs | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/MainUI.cs b/MainUI.cs index 5813fce..5f88fca 100644 --- a/MainUI.cs +++ b/MainUI.cs @@ -1,5 +1,6 @@ using System.Reflection; using ImGuiNET; +using Raylib_cs; namespace Shoko; @@ -37,16 +38,28 @@ static class MainUI ImGui.StyleColorsDark(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; + nint fontrange; + ImFontGlyphRangesBuilderPtr builder; + unsafe { + fixed(ushort* chars = new ushort[]{1, 0xffff, 0}) + fontrange = new nint(chars); + builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); + } + builder.AddRanges(fontrange); + builder.BuildRanges(out ImVector ranges); + AddFontFromResource("RobotoFlex.ttf", (buf, len)=>{ - Font = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f); - HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 32f)); - HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 24f)); - HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 20f)); + Font = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f, null, ranges.Data); + HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 32f, null, ranges.Data)); + HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 24f, null, ranges.Data)); + HeadingFonts.Add(io.Fonts.AddFontFromMemoryTTF(buf, len, 20f, null, ranges.Data)); }); AddFontFromResource("RobotoMono.ttf", (buf, len)=>{ - MonospaceFont = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f); + MonospaceFont = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f, null, ranges.Data); }); + io.Fonts.Build(); + if(args.Length > 0) foreach (var arg in args) NewTab(arg); @@ -54,6 +67,11 @@ static class MainUI return true; } + public static void PreRender() + { + Raylib.ClearBackground(Color.WHITE); + } + public static bool Render() { bool quit = true; diff --git a/Program.cs b/Program.cs index a549e71..54a68df 100644 --- a/Program.cs +++ b/Program.cs @@ -22,7 +22,7 @@ class Program while(!Raylib.WindowShouldClose() && quit) { Raylib.BeginDrawing(); - Raylib.ClearBackground(Color.WHITE); + MainUI.PreRender(); rlImGui.Begin(); quit = MainUI.Render();