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)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
pub fn main() {
// describe the main window
let main_window = WindowDesc::new(build_root_widget())
.title(WINDOW_TITLE)
.window_size((400.0, 600.0));
let text = RichText::new(TEXT.into())
.with_attribute(0..9, Attribute::text_color(Color::rgb(1.0, 0.2, 0.1)))
.with_attribute(0..9, Attribute::size(24.0))
.with_attribute(0..9, Attribute::font_family(FontFamily::SERIF))
.with_attribute(194..239, Attribute::weight(FontWeight::BOLD))
.with_attribute(764.., Attribute::size(12.0))
.with_attribute(764.., Attribute::style(FontStyle::Italic));
// create the initial app state
let initial_state = AppState {
line_break_mode: LineBreaking::Clip,
alignment: Default::default(),
text,
};
// start the application
AppLauncher::with_window(main_window)
.log_to_console()
.launch(initial_state)
.expect("Failed to launch application");
}
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)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
pub fn main() {
// describe the main window
let main_window = WindowDesc::new(build_root_widget())
.title(WINDOW_TITLE)
.window_size((400.0, 600.0));
let text = RichText::new(TEXT.into())
.with_attribute(0..9, Attribute::text_color(Color::rgb(1.0, 0.2, 0.1)))
.with_attribute(0..9, Attribute::size(24.0))
.with_attribute(0..9, Attribute::font_family(FontFamily::SERIF))
.with_attribute(194..239, Attribute::weight(FontWeight::BOLD))
.with_attribute(764.., Attribute::size(12.0))
.with_attribute(764.., Attribute::style(FontStyle::Italic));
// create the initial app state
let initial_state = AppState {
line_break_mode: LineBreaking::Clip,
alignment: Default::default(),
text,
};
// start the application
AppLauncher::with_window(main_window)
.log_to_console()
.launch(initial_state)
.expect("Failed to launch application");
}
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 !RefUnwindSafe for RichText
impl !Send for RichText
impl !Sync for RichText
impl Unpin for RichText
impl !UnwindSafe for RichText
Blanket Implementations§
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>
§impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
§fn round_from(x: T) -> T
fn round_from(x: T) -> T
Performs the conversion.
§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,
§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.