diff --git a/MainUI.cs b/MainUI.cs index 687c896..5084933 100644 --- a/MainUI.cs +++ b/MainUI.cs @@ -9,14 +9,54 @@ static class MainUI public static List tabs = new List(); + public static ImFontPtr Font; + public static List HeadingFonts = new List(); + public static ImFontPtr MonospaceFont; + public static void NewTab(string url) { tabs.Add(new Tab(url)); } + public static unsafe void AddFontFromResource(string resource, Action f) + { + var io = ImGui.GetIO(); + using(var m = new MemoryStream()) + { + Assembly.GetExecutingAssembly().GetManifestResourceStream(resource).CopyTo(m); + var fontBuffer = m.ToArray(); + fixed(byte* buffer = fontBuffer) + { + f(new IntPtr(buffer), fontBuffer.Length); + } + } + } + + public static unsafe bool Load() + { + var io = ImGui.GetIO(); + ImGui.StyleColorsDark(); + io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; + + 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)); + }); + AddFontFromResource("RobotoMono.ttf", (buf, len)=>{ + MonospaceFont = io.Fonts.AddFontFromMemoryTTF(buf, len, 16f); + }); + + return true; + } + public static bool Render() { bool quit = true; + + ImGui.PushFont(Font); + ImGui.DockSpaceOverViewport(); Gui.MainMenuBar(()=> @@ -45,6 +85,8 @@ static class MainUI tab.Render(); } + ImGui.PopFont(); + return quit; } } \ No newline at end of file diff --git a/Media/GeminiMediaHandler.cs b/Media/GeminiMediaHandler.cs index f30916b..1bb22d3 100644 --- a/Media/GeminiMediaHandler.cs +++ b/Media/GeminiMediaHandler.cs @@ -32,6 +32,8 @@ class GeminiMediaHandler : MediaHandler if(line.StartsWith("```")) { formatting = !formatting; + if(formatting) ImGui.PopFont(); + else ImGui.PushFont(MainUI.MonospaceFont); } else if(formatting) { @@ -47,19 +49,14 @@ class GeminiMediaHandler : MediaHandler } else if(line.StartsWith("#")) { - var scale = 2f; var heading = 1; - if(line.StartsWith("##")) (scale, heading) = (1.5f, 2); - if(line.StartsWith("###")) (scale, heading) = (1.25f, 3); + if(line.StartsWith("##")) heading = 2; + if(line.StartsWith("###")) heading = 3; - var font = ImGui.GetFont(); - float oldScale = font.Scale; - font.Scale *= scale; - ImGui.PushFont(font); + ImGui.PushFont(MainUI.HeadingFonts[heading-1]); ImGui.TextUnformatted(line[heading..].Trim()); - font.Scale = oldScale; ImGui.PopFont(); } else if(line.StartsWith("* ")) @@ -76,5 +73,6 @@ class GeminiMediaHandler : MediaHandler else ImGui.TextUnformatted(line); } + if(!formatting) ImGui.PopFont(); } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 25f8477..c1c9592 100644 --- a/Program.cs +++ b/Program.cs @@ -10,12 +10,15 @@ class Program { Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_MAXIMIZED); Raylib.InitWindow(1024, 768, "Shoko"); - rlImGui.Setup(true); - ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.DockingEnable; - bool quit = true; + + rlImGui.BeginInitImGui(); + bool quit = MainUI.Load(); + rlImGui.EndInitImGui(); + if(args.Length > 0) foreach (var arg in args) MainUI.NewTab(arg); + while(!Raylib.WindowShouldClose() && quit) { Raylib.BeginDrawing(); diff --git a/Resources/RobotoFlex.ttf b/Resources/RobotoFlex.ttf new file mode 100644 index 0000000..cb404e4 Binary files /dev/null and b/Resources/RobotoFlex.ttf differ diff --git a/Resources/RobotoMono.ttf b/Resources/RobotoMono.ttf new file mode 100644 index 0000000..7caacd8 Binary files /dev/null and b/Resources/RobotoMono.ttf differ diff --git a/shoko.csproj b/shoko.csproj index 2123e1e..bdba28d 100644 --- a/shoko.csproj +++ b/shoko.csproj @@ -15,6 +15,9 @@ + + +