pub struct RichText { /* private fields */ }Expand description
Text with optional style spans.
Implementations§
Source§impl RichText
impl RichText
Sourcepub fn new(buffer: ArcStr) -> Self
pub fn new(buffer: ArcStr) -> Self
Create a new RichText object with the provided text.
Examples found in repository?
examples/text.rs (line 89)
83pub fn main() {
84 // describe the main window
85 let main_window = WindowDesc::new(build_root_widget())
86 .title(WINDOW_TITLE)
87 .window_size((400.0, 600.0));
88
89 let text = RichText::new(TEXT.into())
90 .with_attribute(0..9, Attribute::text_color(Color::rgb(1.0, 0.2, 0.1)))
91 .with_attribute(0..9, Attribute::size(24.0))
92 .with_attribute(0..9, Attribute::font_family(FontFamily::SERIF))
93 .with_attribute(194..239, Attribute::weight(FontWeight::BOLD))
94 .with_attribute(764.., Attribute::size(12.0))
95 .with_attribute(764.., Attribute::style(FontStyle::Italic));
96
97 // create the initial app state
98 let initial_state = AppState {
99 line_break_mode: LineBreaking::Clip,
100 alignment: Default::default(),
101 text,
102 };
103
104 // start the application
105 AppLauncher::with_window(main_window)
106 .log_to_console()
107 .launch(initial_state)
108 .expect("Failed to launch application");
109}Sourcepub fn new_with_attributes(buffer: ArcStr, attributes: AttributeSpans) -> Self
pub fn new_with_attributes(buffer: ArcStr, attributes: AttributeSpans) -> Self
Create a new RichText, providing explicit attributes.
Sourcepub fn with_attribute(
self,
range: impl RangeBounds<usize>,
attr: Attribute,
) -> Self
pub fn with_attribute( self, range: impl RangeBounds<usize>, attr: Attribute, ) -> Self
Builder-style method for adding an Attribute to a range of text.
Examples found in repository?
examples/text.rs (line 90)
83pub fn main() {
84 // describe the main window
85 let main_window = WindowDesc::new(build_root_widget())
86 .title(WINDOW_TITLE)
87 .window_size((400.0, 600.0));
88
89 let text = RichText::new(TEXT.into())
90 .with_attribute(0..9, Attribute::text_color(Color::rgb(1.0, 0.2, 0.1)))
91 .with_attribute(0..9, Attribute::size(24.0))
92 .with_attribute(0..9, Attribute::font_family(FontFamily::SERIF))
93 .with_attribute(194..239, Attribute::weight(FontWeight::BOLD))
94 .with_attribute(764.., Attribute::size(12.0))
95 .with_attribute(764.., Attribute::style(FontStyle::Italic));
96
97 // create the initial app state
98 let initial_state = AppState {
99 line_break_mode: LineBreaking::Clip,
100 alignment: Default::default(),
101 text,
102 };
103
104 // start the application
105 AppLauncher::with_window(main_window)
106 .log_to_console()
107 .launch(initial_state)
108 .expect("Failed to launch application");
109}Sourcepub fn add_attribute(&mut self, range: impl RangeBounds<usize>, attr: Attribute)
pub fn add_attribute(&mut self, range: impl RangeBounds<usize>, attr: Attribute)
Add an Attribute to the provided range of text.
Trait Implementations§
Source§impl TextStorage for RichText
impl TextStorage for RichText
Source§impl TextStorage for RichText
impl TextStorage for RichText
Source§fn add_attributes(
&self,
builder: PietTextLayoutBuilder,
env: &Env,
) -> PietTextLayoutBuilder
fn add_attributes( &self, builder: PietTextLayoutBuilder, env: &Env, ) -> PietTextLayoutBuilder
If this TextStorage object manages style spans, it should implement
this method and update the provided builder with its spans, as required.
Source§fn env_update(&self, ctx: &EnvUpdateCtx<'_, '_>) -> bool
fn env_update(&self, ctx: &EnvUpdateCtx<'_, '_>) -> bool
This is called whenever the Env changes and should return true
if the layout should be rebuilt.
Auto Trait Implementations§
impl Freeze for RichText
impl !RefUnwindSafe for RichText
impl !Send for RichText
impl !Sync for RichText
impl Unpin for RichText
impl !UnwindSafe for RichText
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
Source§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.