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
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).
fn clone_string(&self) -> String
fn clone_string(&self) -> String
Clone the unformatted text as a String
fn env(&self) -> &Environment
fn env(&self) -> &Environment
Read the environment
fn env_mut(&mut self) -> &mut Environment
fn env_mut(&mut self) -> &mut Environment
Mutate the environment
If using this directly, ensure that necessary preparation actions are
completed afterwards. Consider using TextApiExt::update_env
instead.
fn display(&self) -> &TextDisplay
fn display(&self) -> &TextDisplay
Read the TextDisplay
fn require_action(&mut self, action: Action)
fn require_action(&mut self, action: Action)
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
.
fn prepare_runs(&mut self)
fn prepare_runs(&mut self)
Prepare text runs
Wraps TextDisplay::prepare_runs
, passing parameters from the
environment state.
fn resize_runs(&mut self)
fn resize_runs(&mut self)
Update font size
Wraps TextDisplay::resize_runs
, passing parameters from the
environment state.
fn prepare_lines(&mut self) -> Vec2
fn prepare_lines(&mut self) -> Vec2
Prepare lines (“wrap”)
Wraps TextDisplay::prepare_lines
, passing parameters from the
environment state.
fn effect_tokens(&self) -> &[Effect<()>]
fn effect_tokens(&self) -> &[Effect<()>]
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
).