Add Roboto

This commit is contained in:
Yuki 2023-10-03 15:52:26 -04:00
parent fcca47458f
commit 3fa00d5fc2
6 changed files with 57 additions and 11 deletions

View File

@ -9,14 +9,54 @@ static class MainUI
public static List<Tab> tabs = new List<Tab>(); public static List<Tab> tabs = new List<Tab>();
public static ImFontPtr Font;
public static List<ImFontPtr> HeadingFonts = new List<ImFontPtr>();
public static ImFontPtr MonospaceFont;
public static void NewTab(string url) public static void NewTab(string url)
{ {
tabs.Add(new Tab(url)); tabs.Add(new Tab(url));
} }
public static unsafe void AddFontFromResource(string resource, Action<IntPtr, int> 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() public static bool Render()
{ {
bool quit = true; bool quit = true;
ImGui.PushFont(Font);
ImGui.DockSpaceOverViewport(); ImGui.DockSpaceOverViewport();
Gui.MainMenuBar(()=> Gui.MainMenuBar(()=>
@ -45,6 +85,8 @@ static class MainUI
tab.Render(); tab.Render();
} }
ImGui.PopFont();
return quit; return quit;
} }
} }

View File

@ -32,6 +32,8 @@ class GeminiMediaHandler : MediaHandler
if(line.StartsWith("```")) if(line.StartsWith("```"))
{ {
formatting = !formatting; formatting = !formatting;
if(formatting) ImGui.PopFont();
else ImGui.PushFont(MainUI.MonospaceFont);
} }
else if(formatting) else if(formatting)
{ {
@ -47,19 +49,14 @@ class GeminiMediaHandler : MediaHandler
} }
else if(line.StartsWith("#")) else if(line.StartsWith("#"))
{ {
var scale = 2f;
var heading = 1; var heading = 1;
if(line.StartsWith("##")) (scale, heading) = (1.5f, 2); if(line.StartsWith("##")) heading = 2;
if(line.StartsWith("###")) (scale, heading) = (1.25f, 3); if(line.StartsWith("###")) heading = 3;
var font = ImGui.GetFont(); ImGui.PushFont(MainUI.HeadingFonts[heading-1]);
float oldScale = font.Scale;
font.Scale *= scale;
ImGui.PushFont(font);
ImGui.TextUnformatted(line[heading..].Trim()); ImGui.TextUnformatted(line[heading..].Trim());
font.Scale = oldScale;
ImGui.PopFont(); ImGui.PopFont();
} }
else if(line.StartsWith("* ")) else if(line.StartsWith("* "))
@ -76,5 +73,6 @@ class GeminiMediaHandler : MediaHandler
else else
ImGui.TextUnformatted(line); ImGui.TextUnformatted(line);
} }
if(!formatting) ImGui.PopFont();
} }
} }

View File

@ -10,12 +10,15 @@ class Program
{ {
Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_MAXIMIZED); Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_MAXIMIZED);
Raylib.InitWindow(1024, 768, "Shoko"); Raylib.InitWindow(1024, 768, "Shoko");
rlImGui.Setup(true);
ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.DockingEnable; rlImGui.BeginInitImGui();
bool quit = true; bool quit = MainUI.Load();
rlImGui.EndInitImGui();
if(args.Length > 0) if(args.Length > 0)
foreach (var arg in args) foreach (var arg in args)
MainUI.NewTab(arg); MainUI.NewTab(arg);
while(!Raylib.WindowShouldClose() && quit) while(!Raylib.WindowShouldClose() && quit)
{ {
Raylib.BeginDrawing(); Raylib.BeginDrawing();

BIN
Resources/RobotoFlex.ttf Normal file

Binary file not shown.

BIN
Resources/RobotoMono.ttf Normal file

Binary file not shown.

View File

@ -15,6 +15,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources/RobotoFlex.ttf" LogicalName="RobotoFlex.ttf" />
<EmbeddedResource Include="Resources/RobotoMono.ttf" LogicalName="RobotoMono.ttf" />
<PackageReference Include="Raylib-cs" Version="4.5.0.4" /> <PackageReference Include="Raylib-cs" Version="4.5.0.4" />
<PackageReference Include="rlImgui-cs" Version="1.0.3" /> <PackageReference Include="rlImgui-cs" Version="1.0.3" />
<PackageReference Include="ImGui.NET" Version="1.89.9.2" /> <PackageReference Include="ImGui.NET" Version="1.89.9.2" />