Struct kas_core::text::Text

source ·
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§

source§

impl<T> Text<T>
where T: FormattableText,

source

pub fn new(text: T) -> Text<T>

Construct from a text model

This struct must be made ready for usage by calling Text::prepare.

source

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.

source

pub fn clone_text(&self) -> T
where T: Clone,

Clone the formatted text

source

pub fn take_text(self) -> T

Extract text object, discarding the rest

source

pub fn text(&self) -> &T

Access the formattable text object

source

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.

source

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§

source§

impl<T> AsMut<TextDisplay> for Text<T>
where T: FormattableText + ?Sized,

source§

fn as_mut(&mut self) -> &mut TextDisplay

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsRef<TextDisplay> for Text<T>
where T: FormattableText + ?Sized,

source§

fn as_ref(&self) -> &TextDisplay

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Clone for Text<T>
where T: Clone + FormattableText + ?Sized,

source§

fn clone(&self) -> Text<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Text<T>
where T: Debug + FormattableText + ?Sized,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<T> Default for Text<T>

source§

fn default() -> Text<T>

Returns the “default value” for a type. Read more
source§

impl<T> EditableTextApi for Text<T>
where T: EditableText + ?Sized,

source§

fn insert_char(&mut self, index: usize, c: char)

Insert a char at the given position Read more
source§

fn replace_range(&mut self, range: Range<usize>, replace_with: &str)

Replace a section of text Read more
source§

fn set_string(&mut self, string: String)

Set text to a raw String Read more
source§

fn swap_string(&mut self, string: &mut String)

Swap the raw text with a String Read more
source§

impl<T> TextApi for Text<T>
where T: FormattableText + ?Sized,

source§

fn display(&self) -> &TextDisplay

Read the TextDisplay
source§

fn as_str(&self) -> &str

Access whole text as contiguous str Read more
source§

fn clone_string(&self) -> String

Clone the unformatted text as a String
source§

fn env(&self) -> Environment

Read the environment
source§

fn set_env(&mut self, env: Environment)

Set the environment Read more
source§

fn require_action(&mut self, action: Action)

Require an action Read more
source§

fn prepare_runs(&mut self) -> Result<(), InvalidFontId>

Prepare text runs Read more
source§

fn measure_width(&mut self, limit: f32) -> Result<f32, InvalidFontId>

Measure required width, up to some limit Read more
source§

fn measure_height(&mut self) -> Result<f32, InvalidFontId>

Measure required vertical height, wrapping as configured Read more
source§

fn prepare(&mut self) -> Result<bool, InvalidFontId>

Prepare text for display, as necessary Read more
source§

fn effect_tokens(&self) -> &[Effect<()>]

Get the sequence of effect tokens Read more
source§

fn str_len(&self) -> usize

Length of text 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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<S, T> Cast<T> for S
where T: Conv<S>,

source§

fn cast(self) -> T

Cast from Self to T Read more
source§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

source§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
source§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

source§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
source§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
source§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
source§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
source§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
source§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
source§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
source§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> TextApiExt for T
where T: TextApi + ?Sized,

source§

fn update_env(&mut self, env: Environment) -> Result<bool, InvalidFontId>

Update the environment and do full preparation Read more
source§

fn try_prepare(&mut self) -> Result<bool, InvalidFontId>

Prepare text for display, failing fast if fonts are not loaded Read more
source§

fn bounding_box(&self) -> Result<(Vec2, Vec2), NotReady>

Get the size of the required bounding box Read more
source§

fn required_action(&self) -> Action

Get required action
source§

fn num_lines(&self) -> Result<usize, NotReady>

Get the number of lines (after wrapping) Read more
source§

fn find_line( &self, index: usize ) -> Result<Option<(usize, Range<usize>)>, NotReady>

Find the line containing text index Read more
source§

fn line_range(&self, line: usize) -> Result<Option<Range<usize>>, NotReady>

Get the range of a line, by line number Read more
source§

fn text_is_rtl(&self) -> Result<bool, NotReady>

Get the directionality of the first line
source§

fn line_is_rtl(&self, line: usize) -> Result<Option<bool>, NotReady>

Get the directionality of the current line Read more
source§

fn text_index_nearest(&self, pos: Vec2) -> Result<usize, NotReady>

Find the text index for the glyph nearest the given pos Read more
source§

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
source§

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
source§

fn glyphs<F>(&self, f: F) -> Result<(), NotReady>
where F: FnMut(FaceId, f32, Glyph),

Yield a sequence of positioned glyphs Read more
source§

fn glyphs_with_effects<X, F, G>( &self, effects: &[Effect<X>], default_aux: X, f: F, g: G ) -> Result<(), NotReady>
where X: Copy, F: FnMut(FaceId, f32, Glyph, usize, X), G: FnMut(f32, f32, f32, f32, usize, X),

Like TextDisplay::glyphs but with added effects Read more
source§

fn highlight_range<F>(&self, range: Range<usize>, f: F) -> Result<(), NotReady>
where F: FnMut(Vec2, Vec2),

Yield a sequence of rectangles to highlight a given text range Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more