pub enum FontSize {
Pt(f32),
Px(f32),
}Expand description
A font size with an explicit unit.
In TOML presets, this appears as either size_pt (typographic points)
or size_px (logical pixels). Serde mapping is handled by the parent
struct (FontSpec, TextScaleEntry) — FontSize itself has no
Serialize/Deserialize impl.
During validation, all FontSize values are converted to logical pixels
via FontSize::to_logical_px(dpi), producing a plain f32 for the resolved model.
Variants§
Pt(f32)
Typographic points (1/72 inch). Used by platform presets where the OS
reports font sizes in points (KDE, GNOME, Windows).
Converted to px during validation: px = pt * dpi / 72.
Px(f32)
Logical pixels. Used by community/non-platform presets where font sizes are hand-authored in pixels.
Implementations§
Source§impl FontSize
impl FontSize
Sourcepub fn to_logical_px(self, dpi: f32) -> f32
pub fn to_logical_px(self, dpi: f32) -> f32
Convert to logical pixels.
Pt(v)->v * dpi / 72.0(DPI matters)Px(v)->v(already logical pixels, DPI ignored)
The name to_logical_px makes the asymmetry explicit: Px values
are already in logical pixels, so the DPI parameter has no effect.
§Examples
use native_theme::theme::FontSize;
// Pt branch: DPI affects the result
let pt_size = FontSize::Pt(10.0);
assert_eq!(pt_size.to_logical_px(96.0), 10.0 * 96.0 / 72.0);
assert_eq!(pt_size.to_logical_px(72.0), 10.0); // identity at 72 DPI
// Px branch: DPI is ignored, value returned unchanged
let px_size = FontSize::Px(14.0);
assert_eq!(px_size.to_logical_px(96.0), 14.0);
assert_eq!(px_size.to_logical_px(144.0), 14.0); // same regardless of DPI