Use Cascadia as default monospace font, fallbacks to Consolas/Courier New, wider DebugForm

This commit is contained in:
n00mkrad
2025-11-09 20:34:37 +01:00
parent adf9148f57
commit a9f4018e0f
4 changed files with 53 additions and 22 deletions

View File

@@ -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();
}

View File

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

View File

@@ -11,8 +11,8 @@ namespace Flowframes.Os
{
public enum Architecture { Undetected, Fermi, Kepler, Maxwell, Pascal, Turing, Ampere, Ada, Blackwell };
public static List<PhysicalGPU> NvGpus = new List<PhysicalGPU>();
public static PhysicalGPU GpuWithMostVram = null;
public static int GpuWithMostVramId => NvGpus.IndexOf(GpuWithMostVram);
public static Dictionary<PhysicalGPU, float> GpuVram = new Dictionary<PhysicalGPU, float>();
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)
{

View File

@@ -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<string, bool> _fontAvailabilityCache = new Dictionary<string, bool>(StringComparer.InvariantCultureIgnoreCase);
/// <summary> Checks if a <paramref name="font"/> is installed on the system, results are cached. </summary>
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;
}
}
/// <summary> Gets a font or tries one of the fallbacks (if provided). If none are found, returns the default font. </summary>
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");
}
}