zng/
text.rs

1//! Text widget, properties and other types.
2//!
3//! The [`Text!`] widget implements text layout and rendering, it is also the base widget for
4//! [`SelectableText!`], [`TextInput!`] and [`label!`]. Text properties are largely contextual,
5//! you can set `text::font_size` in any widget to affect all text inside that widget.
6//!
7//! The `Text!` widget provides *simple* text rendering, that is all text is of the same style and
8//! different fonts are only used as fallback. You can implement *rich* text by combining multiple
9//! `Text!` and `Wrap!` panels, see the [`wrap`] module docs for an example. Some widgets also parse
10//! text and generate the rich text setup automatically, the [`Markdown!`] and [`AnsiText!`] widgets
11//! are examples of this.
12//!
13//! The example below declares two text widgets, one displays a text that requires multiple fonts to render,
14//! the other displays debug information about the first.
15//!
16//! ```
17//! use zng::prelude::*;
18//! # let _scope = APP.defaults();
19//!
20//! let txt = "text テキスト 📋";
21//! let font_use = var(vec![]);
22//! # let _ =
23//! Stack! {
24//!     text::font_family = ["Segoe UI", "Yu Gothic UI", "Segoe Ui Emoji", "sans-serif"];
25//!     children = ui_vec![
26//!         Text! {
27//!             font_size = 1.5.em();
28//!             txt;
29//!             get_font_use = font_use.clone();
30//!         },
31//!         Text! {
32//!             font_size = 0.9.em();
33//!             txt = font_use.map(|u| {
34//!                 let mut r = Txt::from("");
35//!                 for (font, range) in u {
36//!                     use std::fmt::Write as _;
37//!                     writeln!(&mut r, "{} = {:?}", font.face().family_name(), &txt[range.clone()]).unwrap();
38//!                 }
39//!                 r.end_mut();
40//!                 r
41//!             });
42//!         },
43//!     ];
44//!     direction = StackDirection::top_to_bottom();
45//!     spacing = 15;
46//! }
47//! # ;
48//! ```
49//!
50//! Note that the [`font_family`](fn@font_family) is set on the parent widget, both texts have the same
51//! font family value because of this, the [`font_size`](fn@font_size) on the other hand is set for
52//! each text widget and only affects that widget.
53//!
54//! [`Text!`]: struct@Text
55//! [`SelectableText!`]: struct@crate::selectable::SelectableText
56//! [`TextInput!`]: struct@crate::text_input::TextInput
57//! [`label!`]: struct@crate::label::Label
58//! [`Markdown!`]: struct@crate::markdown::Markdown
59//! [`AnsiText!`]: struct@crate::ansi_text::AnsiText
60//! [`wrap`]: crate::wrap
61//!
62//! # Full API
63//!
64//! See [`zng_wgt_text`] for the full widget API.
65
66pub use zng_txt::*;
67
68pub use zng_wgt_text::{
69    AutoSelection, CaretShape, CaretStatus, ChangeStopArgs, ChangeStopCause, Em, FONT_COLOR_VAR, InteractiveCaretMode, LangMix,
70    LinesWrapCount, ParagraphMix, SelectionToolbarArgs, Strong, Text, TextOverflow, TxtParseValue, UnderlinePosition, UnderlineSkip,
71    accepts_enter, accepts_tab, auto_selection, caret_color, change_stop_delay, cmd, direction, font_aa, font_annotation, font_caps,
72    font_char_variant, font_cn_variant, font_color, font_common_lig, font_contextual_alt, font_discretionary_lig, font_ea_width,
73    font_family, font_features, font_historical_forms, font_historical_lig, font_jp_variant, font_kerning, font_num_fraction,
74    font_num_spacing, font_numeric, font_ornaments, font_palette, font_palette_colors, font_position, font_size, font_stretch, font_style,
75    font_style_set, font_stylistic, font_swash, font_synthesis, font_variations, font_weight, get_caret_index, get_caret_status,
76    get_chars_count, get_lines_len, get_lines_wrap_count, get_overflow, hyphen_char, hyphens, ime_underline, interactive_caret,
77    interactive_caret_visual, is_line_overflown, is_overflown, is_parse_pending, justify_mode, lang, letter_spacing, line_break,
78    line_height, line_spacing, max_chars_count,
79    node::{TEXT, set_interactive_caret_spot},
80    obscure_txt, obscuring_char, on_change_stop, overline, overline_color, paragraph_spacing, selection_color, selection_toolbar,
81    selection_toolbar_anchor, selection_toolbar_fn, strikethrough, strikethrough_color, tab_length, txt_align, txt_editable, txt_overflow,
82    txt_overflow_align, underline, underline_color, underline_skip, white_space, word_break, word_spacing,
83};