pub struct AttrsList { /* private fields */ }Expand description
A list of text attributes with default styling and per-range overrides.
AttrsList pairs a set of default Attrs with zero or more byte-range spans
that override specific properties. When applied to a Parley builder via
apply_to_builder, the defaults are pushed first,
then each span is layered on top for its range.
§Example
use floem_renderer::text::{Attrs, AttrsList, FontWeight};
use peniko::Color;
let mut attrs_list = AttrsList::new(Attrs::new().font_size(14.0));
// Make bytes 0..5 bold and red.
attrs_list.add_span(
0..5,
Attrs::new()
.font_size(14.0)
.weight(FontWeight::BOLD)
.color(Color::WHITE),
);Implementations§
Source§impl AttrsList
impl AttrsList
Sourcepub fn new(defaults: Attrs<'_>) -> Self
pub fn new(defaults: Attrs<'_>) -> Self
Creates a new attribute list with the given default attributes and no spans.
Sourcepub fn clear_spans(&mut self)
pub fn clear_spans(&mut self)
Removes all attribute spans, keeping only the defaults.
Sourcepub fn add_span(&mut self, range: Range<usize>, attrs: Attrs<'_>)
pub fn add_span(&mut self, range: Range<usize>, attrs: Attrs<'_>)
Adds an attribute span for the given byte range.
Any existing spans that overlap with range are removed before the new
span is inserted.
Sourcepub fn get_span(&self, index: usize) -> Attrs<'_>
pub fn get_span(&self, index: usize) -> Attrs<'_>
Returns the attributes at the given byte index.
If a span covers index, its attributes are returned. Otherwise the
defaults are returned.
Sourcepub fn split_off(&mut self, index: usize) -> Self
pub fn split_off(&mut self, index: usize) -> Self
Splits this attribute list at the given byte index.
Returns a new AttrsList covering [index..) with span ranges shifted
to start from zero. Spans that cross the split point are duplicated into
both halves with their ranges adjusted accordingly. self is left
containing only the [..index) portion.
Sourcepub fn apply_to_builder(&self, builder: &mut RangedBuilder<'_, TextBrush>)
pub fn apply_to_builder(&self, builder: &mut RangedBuilder<'_, TextBrush>)
Applies all defaults and spans to a Parley RangedBuilder.
This first pushes the default attributes, then layers each span on top for its byte range. Span properties that match the defaults are skipped to avoid redundant work.
Sourcepub fn spans(&self) -> &[(Range<usize>, AttrsOwned)]
pub fn spans(&self) -> &[(Range<usize>, AttrsOwned)]
Returns the inner spans as a slice of (byte_range, attributes) pairs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AttrsList
impl RefUnwindSafe for AttrsList
impl Send for AttrsList
impl Sync for AttrsList
impl Unpin for AttrsList
impl UnsafeUnpin for AttrsList
impl UnwindSafe for AttrsList
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.