pub struct Text<T>where
T: FormattableText + ?Sized,{ /* private fields */ }Expand description
Text, prepared for display in a given environment
This struct is composed of three parts: an Environment, a representation
of the FormattableText being displayed, and a TextDisplay object.
Most Functionality is implemented via the TextApi and TextApiExt
traits.
Implementations
sourceimpl<T> Text<T>where
T: FormattableText,
impl<T> Text<T>where
T: FormattableText,
sourcepub fn new(text: T) -> Text<T>
pub fn new(text: T) -> Text<T>
Construct from a text model
This struct must be made ready for usage by calling Text::prepare.
sourcepub fn new_env(env: Environment, text: T) -> Text<T>
pub fn new_env(env: Environment, text: T) -> Text<T>
Construct from a text model and environment
This struct must be made ready for usage by calling Text::prepare.
sourcepub fn clone_text(&self) -> Twhere
T: Clone,
pub fn clone_text(&self) -> Twhere
T: Clone,
Clone the formatted text
sourcepub fn set_text(&mut self, text: T)
pub fn set_text(&mut self, text: T)
Set the text
One must call Text::prepare afterwards and may wish to inspect its
return value to check the size allocation meets requirements.
sourcepub fn set_and_try_prepare(&mut self, text: T) -> Result<bool, InvalidFontId>
pub fn set_and_try_prepare(&mut self, text: T) -> Result<bool, InvalidFontId>
Set the text and prepare (if any fonts are loaded)
Sets text regardless of other outcomes.
If fonts are not loaded, this fails fast (see fonts::any_loaded),
unlike other preparation methods.
Returns true if at least some action is performed and the text exceeds
the allocated bounds (Environment::bounds).
Trait Implementations
sourceimpl<T> AsMut<TextDisplay> for Text<T>where
T: FormattableText + ?Sized,
impl<T> AsMut<TextDisplay> for Text<T>where
T: FormattableText + ?Sized,
sourcefn as_mut(&mut self) -> &mut TextDisplay
fn as_mut(&mut self) -> &mut TextDisplay
Converts this type into a mutable reference of the (usually inferred) input type.
sourceimpl<T> AsRef<TextDisplay> for Text<T>where
T: FormattableText + ?Sized,
impl<T> AsRef<TextDisplay> for Text<T>where
T: FormattableText + ?Sized,
sourcefn as_ref(&self) -> &TextDisplay
fn as_ref(&self) -> &TextDisplay
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<T> EditableTextApi for Text<T>where
T: EditableText + ?Sized,
impl<T> EditableTextApi for Text<T>where
T: EditableText + ?Sized,
sourcefn insert_char(&mut self, index: usize, c: char)
fn insert_char(&mut self, index: usize, c: char)
Insert a char at the given position Read more
sourcefn replace_range(&mut self, range: Range<usize>, replace_with: &str)
fn replace_range(&mut self, range: Range<usize>, replace_with: &str)
Replace a section of text Read more
sourcefn set_string(&mut self, string: String)
fn set_string(&mut self, string: String)
Set text to a raw String Read more
sourcefn swap_string(&mut self, string: &mut String)
fn swap_string(&mut self, string: &mut String)
Swap the raw text with a String Read more
sourceimpl<T> TextApi for Text<T>where
T: FormattableText + ?Sized,
impl<T> TextApi for Text<T>where
T: FormattableText + ?Sized,
sourcefn display(&self) -> &TextDisplay
fn display(&self) -> &TextDisplay
Read the TextDisplay
sourcefn clone_string(&self) -> String
fn clone_string(&self) -> String
Clone the unformatted text as a String
sourcefn env(&self) -> Environment
fn env(&self) -> Environment
Read the environment
sourcefn set_env(&mut self, env: Environment)
fn set_env(&mut self, env: Environment)
Set the environment Read more
sourcefn require_action(&mut self, action: Action)
fn require_action(&mut self, action: Action)
Require an action Read more
sourcefn prepare_runs(&mut self) -> Result<(), InvalidFontId>
fn prepare_runs(&mut self) -> Result<(), InvalidFontId>
Prepare text runs Read more
sourcefn measure_width(&mut self, limit: f32) -> Result<f32, InvalidFontId>
fn measure_width(&mut self, limit: f32) -> Result<f32, InvalidFontId>
Measure required width, up to some limit Read more
sourcefn measure_height(&mut self) -> Result<f32, InvalidFontId>
fn measure_height(&mut self) -> Result<f32, InvalidFontId>
Measure required vertical height, wrapping as configured Read more
sourcefn prepare(&mut self) -> Result<bool, InvalidFontId>
fn prepare(&mut self) -> Result<bool, InvalidFontId>
Prepare text for display, as necessary Read more
sourcefn effect_tokens(&self) -> &[Effect<()>]
fn effect_tokens(&self) -> &[Effect<()>]
Get the sequence of effect tokens Read more
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for Text<T>where
T: RefUnwindSafe,
impl<T: ?Sized> Send for Text<T>where
T: Send,
impl<T: ?Sized> Sync for Text<T>where
T: Sync,
impl<T: ?Sized> Unpin for Text<T>where
T: Unpin,
impl<T: ?Sized> UnwindSafe for Text<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
sourcefn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Try approximate conversion from Self to T Read more
sourcefn cast_approx(self) -> T
fn cast_approx(self) -> T
Cast approximately from Self to T Read more
sourceimpl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
sourcefn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
sourcefn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
sourcefn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
sourcefn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more
sourceimpl<T> TextApiExt for Twhere
T: TextApi + ?Sized,
impl<T> TextApiExt for Twhere
T: TextApi + ?Sized,
sourcefn update_env(&mut self, env: Environment) -> Result<bool, InvalidFontId>
fn update_env(&mut self, env: Environment) -> Result<bool, InvalidFontId>
Update the environment and do full preparation Read more
sourcefn try_prepare(&mut self) -> Result<bool, InvalidFontId>
fn try_prepare(&mut self) -> Result<bool, InvalidFontId>
Prepare text for display, failing fast if fonts are not loaded Read more
sourcefn bounding_box(&self) -> Result<(Vec2, Vec2), NotReady>
fn bounding_box(&self) -> Result<(Vec2, Vec2), NotReady>
Get the size of the required bounding box Read more
sourcefn required_action(&self) -> Action
fn required_action(&self) -> Action
Get required action
sourcefn num_lines(&self) -> Result<usize, NotReady>
fn num_lines(&self) -> Result<usize, NotReady>
Get the number of lines (after wrapping) Read more
sourcefn find_line(
&self,
index: usize
) -> Result<Option<(usize, Range<usize>)>, NotReady>
fn find_line(
&self,
index: usize
) -> Result<Option<(usize, Range<usize>)>, NotReady>
Find the line containing text index Read more
sourcefn line_range(&self, line: usize) -> Result<Option<Range<usize>>, NotReady>
fn line_range(&self, line: usize) -> Result<Option<Range<usize>>, NotReady>
Get the range of a line, by line number Read more
sourcefn text_is_rtl(&self) -> Result<bool, NotReady>
fn text_is_rtl(&self) -> Result<bool, NotReady>
Get the directionality of the first line
sourcefn line_is_rtl(&self, line: usize) -> Result<Option<bool>, NotReady>
fn line_is_rtl(&self, line: usize) -> Result<Option<bool>, NotReady>
Get the directionality of the current line Read more
sourcefn text_index_nearest(&self, pos: Vec2) -> Result<usize, NotReady>
fn text_index_nearest(&self, pos: Vec2) -> Result<usize, NotReady>
Find the text index for the glyph nearest the given pos Read more
sourcefn line_index_nearest(
&self,
line: usize,
x: f32
) -> Result<Option<usize>, NotReady>
fn line_index_nearest(
&self,
line: usize,
x: f32
) -> Result<Option<usize>, NotReady>
Find the text index nearest horizontal-coordinate x on line Read more
sourcefn text_glyph_pos(&self, index: usize) -> Result<MarkerPosIter, NotReady>
fn text_glyph_pos(&self, index: usize) -> Result<MarkerPosIter, NotReady>
Find the starting position (top-left) of the glyph at the given index Read more
sourcefn glyphs<F>(&self, f: F) -> Result<(), NotReady>where
F: FnMut(FaceId, f32, Glyph),
fn glyphs<F>(&self, f: F) -> Result<(), NotReady>where
F: FnMut(FaceId, f32, Glyph),
Yield a sequence of positioned glyphs Read more