Skip to main content

FontSize

Enum FontSize 

Source
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). That mapping is done by the parent structs (FontSpec, TextScaleEntry); FontSize derives Serialize and Deserialize of its own for ResolvedFontSpec::defined_size.

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). Stated by the OS readers (KDE, GNOME, macOS, Windows) and by the platform presets other than Material (Adwaita, KDE Breeze, macOS, Windows 11, iOS). Converted to px during validation: px = pt * dpi / 72.

§

Px(f32)

Logical pixels. Stated by the Material platform preset and the community colour-scheme presets (Catppuccin, Dracula, Gruvbox, Nord, One Dark, Solarized, Tokyo Night).

Implementations§

Source§

impl FontSize

Source

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
Source

pub fn raw(self) -> f32

Return the raw numeric value regardless of unit. Used during inheritance to compute derived values (e.g. line_height) before unit conversion.

Source

pub fn is_pt(self) -> bool

True when the value is in typographic points.

Trait Implementations§

Source§

impl Clone for FontSize

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FontSize

Source§

impl Debug for FontSize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FontSize

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FontSize

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for FontSize

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for FontSize

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for FontSize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more