Trait kas::text::TextApi[]

pub trait TextApi {
    fn as_str(&self) -> &str;
fn clone_string(&self) -> String;
fn env(&self) -> &Environment;
fn env_mut(&mut self) -> &mut Environment;
fn display(&self) -> &TextDisplay;
fn require_action(&mut self, action: Action);
fn prepare(&mut self) -> Option<Vec2>;
fn prepare_runs(&mut self);
fn resize_runs(&mut self);
fn prepare_lines(&mut self) -> Vec2;
fn effect_tokens(&self) -> &[Effect<()>]; fn str_len(&self) -> usize { ... } }
Expand description

Trait over a sub-set of Text functionality

This allows dynamic dispatch over Text’s type parameters.

Required methods

Access whole text as contiguous str

It is valid to reference text within the range 0..text_len(), even if not all text within this range will be displayed (due to runs).

Clone the unformatted text as a String

Read the environment

Mutate the environment

If using this directly, ensure that necessary preparation actions are completed afterwards. Consider using TextApiExt::update_env instead.

Read the TextDisplay

Require an action

Wraps TextDisplay::require_action.

Prepare text for display

Returns the required size to display text (with wrapping based on the bounds set in env), if any update occurred (see documentation of TextDisplay::prepare).

Wraps TextDisplay::prepare, passing through env.

Prepare text runs

Wraps TextDisplay::prepare_runs, passing parameters from the environment state.

Update font size

Wraps TextDisplay::resize_runs, passing parameters from the environment state.

Prepare lines (“wrap”)

Wraps TextDisplay::prepare_lines, passing parameters from the environment state.

Get the sequence of effect tokens

This method has some limitations: (1) it may only return a reference to an existing sequence, (2) effect tokens cannot be generated dependent on input state, and (3) it does not incorporate colour information. For most uses it should still be sufficient, but for other cases it may be preferable not to use this method (use a dummy implementation returning &[] and use inherent methods on the text object via Text::text).

Provided methods

Length of text

This is a shortcut to self.as_str().len().

It is valid to reference text within the range 0..text_len(), even if not all text within this range will be displayed (due to runs).

Implementors