Style

Struct Style 

Source
pub struct Style { /* private fields */ }
Expand description

A style annotation for a string.

The annotation consists of:

  • a font family, see FontFamily (defaults to the FontCache default)
  • a font size in points (defaults to 12)
  • a line spacing factor, with 1 meaning single line spacing (defaults to 1)
  • an outline color, see Color (defaults to black)
  • a combination of text effects, see Effect (defaults to none)

All properties are optional. If they are not set, they can be inferred from parent styles or from the defaults.

Implementations§

Source§

impl Style

Source

pub fn new() -> Style

Creates a new style without settings.

Source

pub fn merge(&mut self, style: impl Into<Style>)

Merges the given style into this style.

Source

pub fn and(self, style: impl Into<Style>) -> Style

Combines this style and the given style and returns the result.

Source

pub fn combine(left: impl Into<Style>, right: impl Into<Style>) -> Style

Creates a new style by combining the given styles.

Source

pub fn color(&self) -> Option<Color>

Returns the outline color for this style, if set.

Source

pub fn is_bold(&self) -> bool

Returns whether the bold text effect is set.

Source

pub fn is_italic(&self) -> bool

Returns whether the italic text effect is set.

Source

pub fn font_size(&self) -> u8

Returns the font size for this style in points, or 12 if no font size is set.

Source

pub fn line_spacing(&self) -> f64

Returns the line spacing factor for this style, or 1 if no line spacing factor is set.

Source

pub fn set_bold(&mut self)

Sets the bold effect for this style.

Source

pub fn bold(self) -> Style

Sets the bold effect for this style and returns it.

Source

pub fn set_italic(&mut self)

Sets the italic effect for this style.

Source

pub fn italic(self) -> Style

Sets the italic effect for this style and returns it.

Source

pub fn set_font_family(&mut self, font_family: FontFamily<Font>)

Sets the font family for this style.

Source

pub fn with_font_family(self, font_family: FontFamily<Font>) -> Style

Sets the font family for this style and returns it.

Source

pub fn set_line_spacing(&mut self, line_spacing: f64)

Sets the line spacing factor for this style.

Source

pub fn with_line_spacing(self, line_spacing: f64) -> Style

Sets the line spacing factor for this style and returns it.

Source

pub fn set_font_size(&mut self, font_size: u8)

Sets the font size in points for this style.

Source

pub fn with_font_size(self, font_size: u8) -> Style

Sets the font size in points for this style and returns it.

Source

pub fn set_color(&mut self, color: Color)

Sets the outline color for this style.

Source

pub fn with_color(self, color: Color) -> Self

Sets the outline color for this style and returns it.

Source

pub fn char_width(&self, font_cache: &FontCache, c: char) -> Mm

Calculates the width of the given character with this style using the data in the given font cache.

If the font family is set, it must have been created by the given FontCache.

Source

pub fn str_width(&self, font_cache: &FontCache, s: &str) -> Mm

Calculates the width of the given string with this style using the data in the given font cache.

If the font family is set, it must have been created by the given FontCache.

Source

pub fn font_family(&self, font_cache: &FontCache) -> FontFamily<Font>

Returns the font family for this style or the default font family using the given font cache.

If the font family is set, it must have been created by the given FontCache.

Source

pub fn font(&self, font_cache: &FontCache) -> Font

Returns the font for this style using the given font cache.

If the font family is set, it must have been created by the given FontCache.

Source

pub fn line_height(&self, font_cache: &FontCache) -> Mm

Calculates the line height for strings with this style using the data in the given font cache.

If the font family is set, it must have been created by the given FontCache.

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

impl<T: Into<Style>> Extend<T> for Style

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Color> for Style

Source§

fn from(color: Color) -> Style

Converts to this type from the input type.
Source§

impl From<Effect> for Style

Source§

fn from(effect: Effect) -> Style

Converts to this type from the input type.
Source§

impl From<FontFamily<Font>> for Style

Source§

fn from(font_family: FontFamily<Font>) -> Style

Converts to this type from the input type.
Source§

impl<T: Into<Style>> FromIterator<T> for Style

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Style

Creates a value from an iterator. Read more
Source§

impl PartialEq for Style

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Style

Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.