pub struct Attrs<'a> {
pub font_size: f32,
/* private fields */
}Expand description
Text styling attributes used to configure font properties, color, and layout.
Attrs uses a builder pattern where each setter consumes and returns self,
making it easy to chain calls. Unset fields (None) inherit from the layout
defaults when applied to a Parley builder.
§Defaults
| Property | Default |
|---|---|
| font_size | 16.0 |
| line_height | LineHeightValue::Normal(1.0) |
| color | None (inherits from context) |
| family | None (system default) |
| weight | None (normal) |
| style | None (normal) |
| font_width | None (normal) |
| metadata | None |
§Example
use floem_renderer::text::{Attrs, FamilyOwned, FontWeight, LineHeightValue};
use peniko::Color;
let families = [FamilyOwned::Name("Inter".to_string()), FamilyOwned::SansSerif];
let attrs = Attrs::new()
.family(&families)
.font_size(14.0)
.weight(FontWeight::BOLD)
.color(Color::WHITE)
.line_height(LineHeightValue::Normal(1.4));Fields§
§font_size: f32Font size in pixels.
Implementations§
Source§impl<'a> Attrs<'a>
impl<'a> Attrs<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Attrs with default values (16px font, 1.0 line height multiplier).
Sourcepub fn family(self, family: &'a [FamilyOwned]) -> Self
pub fn family(self, family: &'a [FamilyOwned]) -> Self
Sets the font family list. Families are tried in order as fallbacks.
Sourcepub fn font_width(self, stretch: FontWidth) -> Self
pub fn font_width(self, stretch: FontWidth) -> Self
Sets the font width (stretch), e.g. condensed or expanded.
Sourcepub fn font_style(self, font_style: FontStyle) -> Self
pub fn font_style(self, font_style: FontStyle) -> Self
Sets the font style (normal, italic, or oblique).
Sourcepub fn weight(self, weight: FontWeight) -> Self
pub fn weight(self, weight: FontWeight) -> Self
Sets the font weight (e.g. FontWeight::BOLD).
Sourcepub fn raw_weight(self, weight: u16) -> Self
pub fn raw_weight(self, weight: u16) -> Self
Sets the font weight from a raw numeric value (typically 100–900).
Sourcepub fn word_break(self, word_break: WordBreakStrength) -> Self
pub fn word_break(self, word_break: WordBreakStrength) -> Self
Sets the word break strength used when text wrapping is enabled.
Sourcepub fn line_height(self, line_height: LineHeightValue) -> Self
pub fn line_height(self, line_height: LineHeightValue) -> Self
Sets the line height. See LineHeightValue for the available modes.
Sourcepub fn metadata(self, metadata: usize) -> Self
pub fn metadata(self, metadata: usize) -> Self
Sets an opaque metadata value that is carried through layout.
This can be used to associate application-specific data (e.g. a span identifier) with a range of text.
Sourcepub fn get_line_height(&self) -> LineHeightValue
pub fn get_line_height(&self) -> LineHeightValue
Returns the line height setting.
Sourcepub fn get_family(&self) -> Option<&'a [FamilyOwned]>
pub fn get_family(&self) -> Option<&'a [FamilyOwned]>
Returns the font family list, or None if unset.
Sourcepub fn get_weight(&self) -> Option<FontWeight>
pub fn get_weight(&self) -> Option<FontWeight>
Returns the font weight, or None if unset.
Sourcepub fn get_font_style(&self) -> Option<FontStyle>
pub fn get_font_style(&self) -> Option<FontStyle>
Returns the font style, or None if unset.
Sourcepub fn get_stretch(&self) -> Option<FontWidth>
pub fn get_stretch(&self) -> Option<FontWidth>
Returns the font width (stretch), or None if unset.
Sourcepub fn get_word_break(&self) -> Option<WordBreakStrength>
pub fn get_word_break(&self) -> Option<WordBreakStrength>
Returns the word break strength, or None if unset.
Sourcepub fn get_metadata(&self) -> Option<usize>
pub fn get_metadata(&self) -> Option<usize>
Returns the metadata value, or None if unset.
Sourcepub fn effective_line_height(&self) -> f32
pub fn effective_line_height(&self) -> f32
Computes the effective line height in pixels.
For LineHeightValue::Normal, this multiplies the font size by the factor.
For LineHeightValue::Pt, the point value is returned directly.
Sourcepub fn apply_defaults(&self, builder: &mut RangedBuilder<'_, TextBrush>)
pub fn apply_defaults(&self, builder: &mut RangedBuilder<'_, TextBrush>)
Pushes all set properties as defaults onto a Parley RangedBuilder.
Font size and line height are always pushed. Optional properties (color, family, weight, style, width) are only pushed when set.
Sourcepub fn apply_range(
&self,
builder: &mut RangedBuilder<'_, TextBrush>,
range: Range<usize>,
defaults: &Attrs<'_>,
)
pub fn apply_range( &self, builder: &mut RangedBuilder<'_, TextBrush>, range: Range<usize>, defaults: &Attrs<'_>, )
Pushes style properties for a specific byte range onto a Parley RangedBuilder.
Only properties that differ from defaults are pushed, avoiding redundant
work when a span shares most attributes with the base style.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Attrs<'a>
impl<'a> RefUnwindSafe for Attrs<'a>
impl<'a> Send for Attrs<'a>
impl<'a> Sync for Attrs<'a>
impl<'a> Unpin for Attrs<'a>
impl<'a> UnsafeUnpin for Attrs<'a>
impl<'a> UnwindSafe for Attrs<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.