pub struct ResolutionContext {
pub font_dpi: f32,
pub button_order: DialogButtonOrder,
pub icon_theme: Option<Cow<'static, str>>,
}Expand description
Resolution-time inputs captured once per theme-build.
Accessibility preferences live on
SystemTheme, NOT here — accessibility is a
render-time concern, not a resolve-time concern.
§Examples
use native_theme::resolve::ResolutionContext;
// The running platform's: its constant font DPI, its button order and
// its detected icon theme.
let ctx = ResolutionContext::from_system();
assert!(ctx.font_dpi > 0.0);
// Tests: deterministic values.
let ctx = ResolutionContext::for_tests();
assert_eq!(ctx.font_dpi, 96.0);
assert!(ctx.icon_theme.is_none());Fields§
§font_dpi: f32Font DPI for pt-to-px conversion. It must be finite and positive:
resolution rejects any other value as one
Error::ResolutionInvalid on the
path context.font_dpi, before any point size is converted.
from_system gives the platform’s: 72.0 on macOS,
where a point is a pixel, and 96.0 everywhere else, every Linux desktop
included. Nothing is detected or cached. On Linux the toolkit’s scale
factor carries the display’s scale (from the compositor on Wayland, from
Xft.dpi on X11), so the font DPI carries none of it; GNOME’s
text-scaling factor is carried in
AccessibilityPreferences. When the OS
theme is read (SystemTheme::from_system),
the reader’s own DPI, the same value, replaces it.
That font DPI is not right in these cases, where the application passes a font DPI of its own:
- where the application, not the toolkit, decides the X11 scale
(
GPUI_X11_SCALE_FACTOR,WINIT_X11_SCALE_FACTOR); - on X11 without
Xft.dpi, where gpui and winit scale the whole interface by the monitor’s size (gpui-fast byGDK_SCALEwhere the session sets it) and Qt does not (text and interface stay in proportion, at the toolkit’s size); - on Plasma 6.7 X11 with a global scale other than 1 and a forced font
DPI that departs from it, where Qt takes its scale from
QT_SCREEN_SCALE_FACTORSand gpui and winit fromXft.dpi; - for a toolkit that does not scale by
Xft.dpion X11 (none of the three connectors’).
On the preset and TOML paths the application builds its own context and
resolves with it (Theme::resolve_with,
ThemeMode::into_resolved):
use native_theme::resolve::ResolutionContext;
use native_theme::theme::{ColorMode, Resolved, Theme};
/// Resolves `kde-breeze` at the font DPI the application decided.
fn resolve_at(dpi: f32) -> native_theme::Result<Resolved> {
let ctx = ResolutionContext { font_dpi: dpi, ..ResolutionContext::from_system() };
Theme::preset("kde-breeze")?.resolve_with(ColorMode::Light, &ctx)
}SystemTheme::from_system takes no
font DPI, so on that path the application re-derives its sizes from each
resolved font’s
defined_size. The text
scale’s entries carry no defined_size, so their sizes cannot be
re-derived.
Dialog button ordering (PrimaryLeft on KDE and Windows,
PrimaryRight elsewhere).
icon_theme: Option<Cow<'static, str>>Runtime-detected icon theme name, used when the preset and
per-variant icon_theme fields are both None. Three-tier
precedence in the pipeline: per-variant → Theme-level shared →
this runtime detection.
from_system puts the detected system icon
theme here, or None where detection failed;
system_icon_theme() gives the
reason.
Implementations§
Source§impl ResolutionContext
impl ResolutionContext
Sourcepub fn from_system() -> Self
pub fn from_system() -> Self
Build the context of the running platform:
font_dpi: 72.0 on macOS and 96.0 everywhere else, a constant per platform (nothing is read);button_order:PrimaryLefton Windows and on a KDE desktop,PrimaryRightelsewhere;icon_theme: the system icon theme (crate::detect::system_icon_theme),Nonewhere detection fails.