pub struct RichText { /* private fields */ }Expand description
Text with a little formatting, written the way chat apps write it: *bold*, _italic_,
~struck~, `code`, a fenced block of ```, lines that start with * , -
or > , and web addresses, which become links.
It wraps to the width it is offered, between words, and a marked piece stays with the
punctuation around it. Text with nothing to format is drawn as one Text, for the same
cost. Links take the keyboard: Tab reaches them, and Enter or Space opens them. It only
recognizes http and https, and it hands the address to Self::on_link instead of
opening anything.
ravenrs-text shapes one style per text and embeds neither an italic nor a monospace
font, so italics are told apart by a muted color and code by a chip behind it.
use ravenrs_widgets::{RichText, Ui};
let text = RichText::new("*Ready:* see `report.pdf` at https://example.com/r")
.on_link(|address| println!("open {address}"));
let mut ui = Ui::new(text, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl RichText
impl RichText
Sourcepub fn links_only(self) -> RichText
pub fn links_only(self) -> RichText
Takes every mark literally, and only finds the links: for text from somewhere that does not use these marks.
Sourcepub fn foreground(self, fill: impl Into<Fill>) -> RichText
pub fn foreground(self, fill: impl Into<Fill>) -> RichText
Text color, as a theme role (Ink by default) or a literal color.
Sourcepub fn on_link(self, handler: impl Fn(String) + 'static) -> RichText
pub fn on_link(self, handler: impl Fn(String) + 'static) -> RichText
Called with the address of a link when it is clicked, or pressed with Enter or Space. Without it, links look like links but cannot be activated or focused.
Sourcepub fn plain_text(text: &str) -> String
pub fn plain_text(text: &str) -> String
The text without its marks, on one line: for a preview, such as in a list of conversations.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RichText
impl !Send for RichText
impl !Sync for RichText
impl !UnwindSafe for RichText
impl Freeze for RichText
impl Unpin for RichText
impl UnsafeUnpin for RichText
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.