Skip to content

Commit

Permalink
expose onConfigureIO in CreateWindow and add proper font setup to Mai…
Browse files Browse the repository at this point in the history
…nWindow
  • Loading branch information
jupahe64 committed Nov 6, 2023
1 parent 0f1ad3b commit 103816c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
27 changes: 26 additions & 1 deletion Fushigi/ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,40 @@
using Fushigi.param;
using Fushigi.ui.widgets;
using ImGuiNET;
using System.Runtime.CompilerServices;
using System.Numerics;

namespace Fushigi.ui
{
public class MainWindow
{

private ImFontPtr mDefaultFont;

public MainWindow()
{
WindowManager.CreateWindow(out mWindow);
WindowManager.CreateWindow(out mWindow,
onConfigureIO: () => {
unsafe
{
var io = ImGui.GetIO();

var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig();
//Add a higher horizontal/vertical sample rate for global scaling.
nativeConfig->OversampleH = 8;
nativeConfig->OversampleV = 8;
nativeConfig->RasterizerMultiply = 1f;
nativeConfig->GlyphOffset = new Vector2(0);

{
mDefaultFont = io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "Font.ttf"),
16, nativeConfig);

//other fonts go here and follow the same schema
}
}
});
mWindow.Load += () => WindowManager.RegisterRenderDelegate(mWindow, Render);
mWindow.Closing += Close;
mWindow.Run();
Expand Down
9 changes: 2 additions & 7 deletions Fushigi/windowing/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private record struct WindowResources(ImGuiController ImguiController, IInputCon
private static readonly List<IWindow> s_pendingInits = [];
private static readonly List<(IWindow window, WindowResources res)> s_windows = [];

public static void CreateWindow(out IWindow window, Vector2D<int>? initialWindowSize = null)
public static void CreateWindow(out IWindow window, Vector2D<int>? initialWindowSize = null, Action? onConfigureIO = null)
{
var options = WindowOptions.Default;
options.API = new GraphicsAPI(
Expand Down Expand Up @@ -52,13 +52,8 @@ public static void CreateWindow(out IWindow window, Vector2D<int>? initialWindow
if (_window.Native!.Win32.HasValue)
WindowsDarkmodeUtil.SetDarkmodeAware(_window.Native.Win32.Value.Hwnd);


ImGuiFontConfig? imGuiFontConfig = new ImGuiFontConfig(
Path.Combine("res", "Font.ttf"),
16);

var input = _window.CreateInput();
var imguiController = new ImGuiController(s_gl, _window, input, imGuiFontConfig);
var imguiController = new ImGuiController(s_gl, _window, input, onConfigureIO);

//update
_window.Update += ds => imguiController.Update((float)ds);
Expand Down

0 comments on commit 103816c

Please sign in to comment.