Theme
This document describes MewUI’s theme.
1. Theme inputs
Section titled “1. Theme inputs”In MewUI, a Theme is derived from the following four inputs:
ThemeVariant:System/Light/DarkAccent(orColor): the accent colorThemeSeed: base color seeds for Light/DarkThemeMetrics: “look & feel” metrics such as sizes, padding, strokes, and fonts
All examples below configure defaults before calling Run(...).
1.1 ThemeVariant
Section titled “1.1 ThemeVariant”This input selects the Light/Dark mode, or follows the OS setting when using System.
using Aprillz.MewUI;
// Default is ThemeVariant.System.// If you are OK with System, you can omit this.ThemeManager.Default = ThemeVariant.System;// ThemeManager.Default = ThemeVariant.Light;// ThemeManager.Default = ThemeVariant.Dark;1.2 Accent
Section titled “1.2 Accent”This input provides the accent color. You can use the built-in Accent.* presets, or supply a custom Color.
using Aprillz.MewUI;
ThemeManager.DefaultAccent = Accent.Blue;Note: Custom Color is typically used more often for runtime changes (see section 3.2).
1.3 ThemeSeed
Section titled “1.3 ThemeSeed”This input provides the base color seeds for Light and Dark variants.
Common properties on ThemeSeed:
WindowBackground: window backgroundWindowText: default text colorControlBackground: control backgroundButtonFace: default button backgroundButtonDisabledBackground: disabled button background
using Aprillz.MewUI;
ThemeManager.DefaultLightSeed = ThemeSeed.DefaultLight;ThemeManager.DefaultDarkSeed = ThemeSeed.DefaultDark;1.4 ThemeMetrics
Section titled “1.4 ThemeMetrics”This input provides global UI metrics such as base control size, padding, corner radius, and fonts.
Common properties on ThemeMetrics:
FontFamily,FontSize,FontWeightBaseControlHeightControlCornerRadiusItemPaddingScrollBarThickness,ScrollBarHitThickness,ScrollBarMinThumbLengthScrollWheelStep,ScrollBarSmallChange,ScrollBarLargeChange
using Aprillz.MewUI;
ThemeManager.DefaultMetrics = ThemeMetrics.Default with{ ControlCornerRadius = 6, FontSize = 13, FontFamily = "Noto Sans"};Default font and the system font
Section titled “Default font and the system font”When FontFamily is not specified, the theme follows the platform’s system UI font: the configured UI font on Windows (localized, e.g. Malgun Gothic on Korean Windows), .AppleSystemUIFont on macOS, and sans-serif on X11. Assign ThemeMetrics.SystemFontFamily to state that explicitly, and read IsSystemFontFamily to check whether the system font is in effect.
Assigning a family name uses that font instead of the system font, including names that match a platform’s own system font such as "Segoe UI".
// Pin Segoe UI instead of the system fontThemeManager.DefaultMetrics = ThemeMetrics.Default with { FontFamily = "Segoe UI" };
// Follow the system font, change only the sizeThemeManager.DefaultMetrics = ThemeMetrics.Default with { FontSize = 13 };FontFamily resolves on read, so any read after the platform package registers (Win32Platform.Register() and friends) reports the family that will actually be used. ThemeMetrics.Default.FontFamily gives the system font; ThemeManager.DefaultMetrics.FontFamily gives the final font including your override.
Characters missing from the chosen font are covered by the font fallback chain, so pinning Segoe UI still renders Korean, Japanese, and Chinese text.
2. Theme setup at startup
Section titled “2. Theme setup at startup”Recommended order:
- Configure
ThemeManager.Default*first - Build your UI
- Call
Application.Run(...)
2.1 ThemeSeed customization example
Section titled “2.1 ThemeSeed customization example”using Aprillz.MewUI;
// You do not need to re-assign defaults.// Only override the parts you want to change.
ThemeManager.DefaultLightSeed = ThemeSeed.DefaultLight with{ WindowText = Color.FromRgb(20, 20, 20)};
ThemeManager.DefaultDarkSeed = ThemeSeed.DefaultDark with{ WindowText = Color.FromRgb(240, 240, 240)};
var mainWindow = new Window() .Title("Theme Seed Demo") .Content(new TextBlock().Text("Hello, MewUI").Bold());
Application.Run(mainWindow);2.2 Applying settings via ApplicationBuilder
Section titled “2.2 Applying settings via ApplicationBuilder”Included topics:
- Apply theme inputs via builder
UseTheme/UseAccent/UseSeed/UseMetrics - (Optional) Chain platform/backend selection (e.g.
UseWin32/UseDirect2D) when those packages are referenced
Note:
- The builder applies these values to
ThemeManager.Default*right beforeRun(...).
using Aprillz.MewUI;
var mainWindow = new Window() .Title("Theme + Builder") .Content(new TextBlock().Text("Hello"));
Application.Create() .UseMetrics(ThemeMetrics.Default with { ControlCornerRadius = 6, FontSize = 13, FontFamily = "Noto Sans" }) .UseSeed( ThemeSeed.DefaultLight with { WindowText = Color.FromRgb(20, 20, 20) }, ThemeSeed.DefaultDark with { WindowText = Color.FromRgb(240, 240, 240) }) // If needed, configure mode/accent as well (System/Blue are defaults so you can omit them) // .UseTheme(ThemeVariant.System) // .UseAccent(Accent.Blue) .UseWin32() .UseDirect2D() .Run(mainWindow);3. Runtime theme changes
Section titled “3. Runtime theme changes”In general, the following two runtime changes are supported:
- switching
ThemeVariant - switching
Accent
3.1 Switching ThemeVariant
Section titled “3.1 Switching ThemeVariant”Application.Current.SetTheme(ThemeVariant.Dark);// Application.Current.SetTheme(ThemeVariant.Light);// Application.Current.SetTheme(ThemeVariant.System);3.2 Switching Accent
Section titled “3.2 Switching Accent”Application.Current.SetAccent(Accent.Green);
// Custom colorApplication.Current.SetAccent(new Color(0xFF, 0x22, 0x88, 0xFF));4. Theme change callback
Section titled “4. Theme change callback”When the theme changes (theme variant switch, OS theme change in System mode, or a dependent property update), you may want to re-apply some properties based on the current theme.
Use WithTheme((theme, control) => ...) for this purpose.
var accentButton = new Button() .Text("Accent Button") .WithTheme((theme, c) => { c.Background(theme.Palette.Accent); c.Foreground(theme.Palette.AccentText); });5. Theme change event
Section titled “5. Theme change event”Application.Current.ThemeChanged += (oldTheme, newTheme) =>{ // Logging / persistence, etc.};