Add font ranges

This commit is contained in:
Yuki 2023-11-10 16:45:01 -05:00
parent 52172d3d73
commit 38ea69977c
2 changed files with 24 additions and 6 deletions

View File

@ -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;

View File

@ -22,7 +22,7 @@ class Program
while(!Raylib.WindowShouldClose() && quit)
{
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.WHITE);
MainUI.PreRender();
rlImGui.Begin();
quit = MainUI.Render();