From a9f4018e0f328a239b38f9b69b70ab96db3d98cb Mon Sep 17 00:00:00 2001 From: n00mkrad <61149547+n00mkrad@users.noreply.github.com> Date: Sun, 9 Nov 2025 20:34:37 +0100 Subject: [PATCH] Use Cascadia as default monospace font, fallbacks to Consolas/Courier New, wider DebugForm --- CodeLegacy/Forms/DebugForm.cs | 13 ++++++------ CodeLegacy/Forms/MessageForm.cs | 5 +++-- CodeLegacy/Os/NvApi.cs | 21 ++++++++----------- CodeLegacy/Ui/UiUtils.cs | 36 +++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/CodeLegacy/Forms/DebugForm.cs b/CodeLegacy/Forms/DebugForm.cs index c131017..404a3c2 100644 --- a/CodeLegacy/Forms/DebugForm.cs +++ b/CodeLegacy/Forms/DebugForm.cs @@ -1,15 +1,9 @@ using Flowframes.IO; using Flowframes.Ui; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Diagnostics; -using System.Drawing; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace Flowframes.Forms @@ -21,11 +15,16 @@ namespace Flowframes.Forms public DebugForm() { InitializeComponent(); + + int smallestWidth = Screen.AllScreens.Min(s => s.WorkingArea.Width); + Width = Math.Min((Program.mainForm.Width * 1.25f).RoundToInt(), smallestWidth - 80); + Height = Program.mainForm.Height; } private void DebugForm_Shown(object sender, EventArgs e) { - configDataGrid.Font = new Font("Consolas", 9f); + configDataGrid.Font = UiUtils.GetMonospaceFont(9.5f); + logBox.Font = UiUtils.GetMonospaceFont(9f); RefreshLogs(); } diff --git a/CodeLegacy/Forms/MessageForm.cs b/CodeLegacy/Forms/MessageForm.cs index d829026..d2e7169 100644 --- a/CodeLegacy/Forms/MessageForm.cs +++ b/CodeLegacy/Forms/MessageForm.cs @@ -1,4 +1,5 @@ -using System; +using Flowframes.Ui; +using System; using System.Drawing; using System.Windows.Forms; @@ -30,7 +31,7 @@ namespace Flowframes.Forms if (_monospace) { - textLabel.Font = new Font("Cascadia Code", textLabel.Font.Size, textLabel.Font.Style); + textLabel.Font = UiUtils.GetMonospaceFont(textLabel.Font.Size, textLabel.Font.Style); } if(_btns == MessageBoxButtons.OK) diff --git a/CodeLegacy/Os/NvApi.cs b/CodeLegacy/Os/NvApi.cs index 844b4ff..e7389a4 100644 --- a/CodeLegacy/Os/NvApi.cs +++ b/CodeLegacy/Os/NvApi.cs @@ -11,8 +11,8 @@ namespace Flowframes.Os { public enum Architecture { Undetected, Fermi, Kepler, Maxwell, Pascal, Turing, Ampere, Ada, Blackwell }; public static List NvGpus = new List(); - public static PhysicalGPU GpuWithMostVram = null; - public static int GpuWithMostVramId => NvGpus.IndexOf(GpuWithMostVram); + public static Dictionary GpuVram = new Dictionary(); + public static PhysicalGPU GpuWithMostVram => GpuVram.OrderByDescending(kv => kv.Value).First().Key; public static void Init() { @@ -25,22 +25,17 @@ namespace Flowframes.Os if (gpus.Length == 0) return; - NvGpus = gpus.OrderByDescending(g => g.GetVramGb()).ThenBy(g => g.FullName).ToList(); - float mostVram = -1f; - foreach (PhysicalGPU gpu in gpus) { float vramGb = gpu.GetVramGb(); - Logger.Log($"Nvidia GPU: {gpu.FullName} ({vramGb.ToString("0.")} GB) {GetArch(gpu)} Architecture", true); - - if (vramGb > mostVram) - { - mostVram = vramGb; - GpuWithMostVram = gpu; - } + vramGb = (float)(Math.Round(vramGb * 2, MidpointRounding.AwayFromZero) / 2); // Round to nearest 0.5 GB + Logger.Log($"Nvidia GPU: {gpu.FullName} ({vramGb.ToString("0.#")} GB) {GetArch(gpu)} Architecture", true); + GpuVram[gpu] = vramGb; } - Logger.Log($"Initialized Nvidia API in {sw.ElapsedMs} ms. GPU{(gpus.Length > 1 ? "s" : "")}: {string.Join(", ", gpus.Select(g => g.FullName))}. Most VRAM: {GpuWithMostVram.FullName} ({mostVram} GB)", true); + NvGpus = gpus.OrderByDescending(g => GpuVram[g]).ThenBy(g => g.FullName).ToList(); + string mostVramGpu = gpus.Length > 1 ? $" Most VRAM: {GpuWithMostVram.FullName} ({GpuVram[GpuWithMostVram].ToString("0.#")} GB)" : ""; + Logger.Log($"Initialized Nvidia API in {sw.ElapsedMs} ms. GPU{(gpus.Length > 1 ? "s" : "")}: {string.Join(", ", gpus.Select(g => g.FullName))}.{mostVramGpu}", true); } catch (Exception e) { diff --git a/CodeLegacy/Ui/UiUtils.cs b/CodeLegacy/Ui/UiUtils.cs index 09a8dc8..65be816 100644 --- a/CodeLegacy/Ui/UiUtils.cs +++ b/CodeLegacy/Ui/UiUtils.cs @@ -4,6 +4,7 @@ using Flowframes.IO; using Flowframes.Main; using Flowframes.Os; using System; +using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -158,5 +159,40 @@ namespace Flowframes.Ui return Regex.Replace(s, "([A-Z])", " $1").Trim(); } + + private static Dictionary _fontAvailabilityCache = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + + /// Checks if a is installed on the system, results are cached. + public static bool IsFontInstalled(string font) + { + if (_fontAvailabilityCache.TryGetValue(font, out bool isInstalledCached)) + return isInstalledCached; + + using (var testFont = new System.Drawing.Font(font, 8)) + { + bool isInstalled = string.Equals(font, testFont.Name, StringComparison.InvariantCultureIgnoreCase); + Logger.Log($"Font is {(isInstalled ? "" : "not ")}available: {font}", true); + _fontAvailabilityCache[font] = isInstalled; + return isInstalled; + } + } + + /// Gets a font or tries one of the fallbacks (if provided). If none are found, returns the default font. + public static System.Drawing.Font GetFontOrFallback(string preferredFont, float emSize, System.Drawing.FontStyle? style = null, params string[] fallbackFonts) + { + style = style ?? System.Drawing.FontStyle.Regular; + if (IsFontInstalled(preferredFont)) + return new System.Drawing.Font(preferredFont, emSize, style.Value); + foreach (var fallback in fallbackFonts) + { + if (IsFontInstalled(fallback)) + return new System.Drawing.Font(fallback, emSize, style.Value); + } + // Last resort: use default font + return new System.Drawing.Font(System.Drawing.SystemFonts.DefaultFont.FontFamily, emSize, style.Value); + } + + public static System.Drawing.Font GetMonospaceFont(float emSize, System.Drawing.FontStyle? style = null) + => GetFontOrFallback("Cascadia Mono", emSize, style ?? System.Drawing.FontStyle.Regular, "Cascadia Code", "Consolas", "Courier New"); } }