Expand description
Text widget, properties and other types.
The Text!
widget implements text layout and rendering, it is also the base widget for
SelectableText!
, TextInput!
and label!
. Text properties are largely contextual,
you can set text::font_size
in any widget to affect all text inside that widget.
The Text!
widget provides simple text rendering, that is all text is of the same style and
different fonts are only used as fallback. You can implement rich text by combining multiple
Text!
and Wrap!
panels, see the wrap
module docs for an example. Some widgets also parse
text and generate the rich text setup automatically, the Markdown!
and AnsiText!
widgets
are examples of this.
The example below declares two text widgets, one displays a text that requires multiple fonts to render, the other displays debug information about the first.
use zng::prelude::*;
let txt = "text テキスト 📋";
let font_use = var(vec![]);
Stack! {
text::font_family = ["Segoe UI", "Yu Gothic UI", "Segoe Ui Emoji", "sans-serif"];
children = ui_vec![
Text! {
font_size = 1.5.em();
txt;
get_font_use = font_use.clone();
},
Text! {
font_size = 0.9.em();
txt = font_use.map(|u| {
let mut r = Txt::from("");
for (font, range) in u {
use std::fmt::Write as _;
writeln!(&mut r, "{} = {:?}", font.face().family_name(), &txt[range.clone()]).unwrap();
}
r.end_mut();
r
});
},
];
direction = StackDirection::top_to_bottom();
spacing = 15;
}
Note that the font_family
is set on the parent widget, both texts have the same
font family value because of this, the font_size
on the other hand is set for
each text widget and only affects that widget.
§Full API
See zng_wgt_text
for the full widget API.
Modules§
- Commands that control the editable text.
Macros§
- A simple text run with italic font style.
- A simple text run with bold font weight.
- Creates a
Txt
by formatting using theformat_args!
syntax.
Structs§
- Defines when text is auto-selected on focus.
- Display info of edit caret position.
- Arguments for
on_change_stop
. m
Language and text direction properties.m
Text paragraph properties.- Arguments for
selection_toolbar_fn
. - Text internals used by text implementer nodes and properties.
W
A configured text run.- Text string type, can be one of multiple internal representations, mostly optimized for sharing and one for editing.
- Represents what parts of a text the underline must skip over.
Enums§
- Defines the position of an interactive caret in relation to the selection.
- Cause of an
on_change_stop
. - Defines when the interactive carets are used.
- Represents the number of lines and number of wrap lines in a text.
- Defines how text overflow is handled by the text widgets.
- Identifies how a
Txt
is currently storing the string data. - Defines what line gets traced by the text underline decoration.
Statics§
- Color of
Text!
glyphs that are not colored by palette.
Traits§
- A trait for converting a value to a
Txt
. - Represents a type that can be a var value, parse and display.
Functions§
P
If the'\n'
character is inserted when enter is pressed and the text is editable.P
If the'\t'
character is inserted when tab is pressed and the text is editable.P
Auto-selection on focus when the text is selectable.P
Defines the color of the non-interactive caret.P
Debounce time foron_change_stop
.P
Sets the layout direction used in the layout of the widget and descendants.P
Configure the anti-aliasing used to render text glyphs inside the widget.P
Sets the font annotation alternative feature.P
Sets the font capital variant features.P
Sets the font character variant alternative feature.P
Sets the Chinese logographic set.P
Defines the color the most text glyphs are filled with.P
Sets the font common ligatures features.P
Sets the font contextual alternatives feature.P
Sets the font discretionary ligatures feature.P
Sets the East Asian figure width.P
Font family name or list of names for texts in this widget or descendants.P
Sets font features.P
Sets the font historical forms alternative feature.P
Sets the font historical ligatures feature.P
Sets the Japanese logographic set.P
Sets the font kerning feature.P
Sets the font numeric fraction features.P
Sets the font numeric spacing features.P
Sets the font numeric variant features.P
Sets the font ornaments alternative feature.P
Defines the palette used to render colored glyphs (Emoji).P
Defines custom palette colors that affect Emoji colors.P
Sets the font sub/super script position alternative feature.P
Sets the font size for the widget and descendants.P
Defines how condensed or expanded the preferred font should be.P
Defines the skew style of the font glyphs.P
Sets the font stylistic set alternative feature.P
Sets the font stylistic alternative feature.P
Sets the font swash features.P
Configure if a synthetic font is generated for fonts that do not implement bold or oblique variants.P
Sets font variations.P
Defines the thickness or boldness the preferred font should have.P
Gets the caret char index, if the text is editable.P
Gets the caret display status, if the text is editable.P
Gets the number of character in the text.P
Gets the number of lines in the text, including wrap lines.P
Gets the number of wrap lines per text lines.P
Gets the overflow text, that is a clone of the text starting from the first overflow character.P
The char or small string that is rendered when text is auto-hyphenated.P
Configure hyphenation.P
Style and thickness of the line drawn under the IME preview text.P
Defines when the interactive carets are used.P
Defines custom caret visual for interactive caret.P
Gets if the text has an entire line overflown.P
Gets if the text is overflown.P
If text has changed buttxt_parse
has not tried to parse the new text yet.P
Config the automatic spacing inserted between words and letters when text is aligned to fill.P
Sets the text language and script for the widget and descendants.P
Extra spacing added in between text letters. If not set inherits theletter_spacing
from the parent widget.P
Configuration of text wrapping for Chinese, Japanese, or Korean text.P
Height of each text line. If not set inherits theline_height
from the parent widget.P
Extra spacing in-between text lines. If not set inherits theline_spacing
from the parent widget.P
Maximum number of characters that can be input.P
If the typed text is obscured in render.P
Replacement character used when obscuring text.P
Called after the text changed and interaction has stopped.P
Draw lines above each text line.P
Extra spacing in-between paragraphs.P
Sets theSELECTION_COLOR_VAR
.P
Defines the floating mini-toolbar that shows near a new text selection.P
Position the selection toolbar in relation to the bounding box of all selection rectangles.P
Defines the floating mini-toolbar that shows near a new text selection.- Set the caret hotspot that marks the middle of the caret on the text line.
P
Draw lines across each text line.P
Length of the TAB character space, relative to the normal space advance.P
Alignment of text inside available space.P
Enable text caret, input and makes the widget focusable.P
Defines if text overflow is truncated, with optional suffix append.P
Alignment of text inside available space when the text overflows.P
Draw lines under each text line.P
Defines what segments of each text line are skipped when tracing theunderline
.P
Text white space transform.P
Configure line breaks inside words during text wrap.P
Extra spacing added to the UnicodeU+0020 SPACE
character. If not set inherits theword_spacing
from the parent widget.