Skip to content

Commit 80a82e1

Browse files
committed
docs: add docs for text selection
Still really minimal, but text selection is not obvious, so this is a lot better than nothing.
1 parent 1764cef commit 80a82e1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

common/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ pub use geometry::{Affine, Point, Rect, Size, Vec2};
5555
pub enum Role {
5656
#[default]
5757
Unknown,
58+
59+
/// Should be used for selectable Text. For each line of text one `TextRun` should be used.
60+
/// Each one of them should be added as a child to a `Label`, `TextInput`, `MultiLineTextInput`
61+
/// or similar [`Node`]. The selection can be specified with [`Node::set_text_selection`] on the
62+
/// parent [`Node`].
5863
TextRun,
5964
Cell,
65+
/// If the text should be selectable see the documentation at [`Role::MultilineTextInput`].
6066
Label,
6167
Image,
6268
Link,
@@ -79,6 +85,8 @@ pub enum Role {
7985

8086
CheckBox,
8187
RadioButton,
88+
89+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
8290
TextInput,
8391
Button,
8492
DefaultButton,
@@ -94,17 +102,31 @@ pub enum Role {
94102
Switch,
95103
Menu,
96104

105+
/// `MultilineTextInput` should have a child with [`Role::TextRun`] for each line of text.
106+
/// For text selection [`Node::set_text_selection`] and [`Node::set_character_lengths`] are necessary.
107+
/// These should be used on the `MultilineTextInput` node and not on the `TextRun` nodes.
97108
MultilineTextInput,
109+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
98110
SearchInput,
111+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
99112
DateInput,
113+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
100114
DateTimeInput,
115+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
101116
WeekInput,
117+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
102118
MonthInput,
119+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
103120
TimeInput,
121+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
104122
EmailInput,
123+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
105124
NumberInput,
125+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
106126
PasswordInput,
127+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
107128
PhoneNumberInput,
129+
/// To make the text selectable see the documentation at [`Role::MultilineTextInput`].
108130
UrlInput,
109131

110132
Abbr,
@@ -1989,6 +2011,11 @@ property_methods! {
19892011
/// [`transform`]: Node::transform
19902012
(Bounds, bounds, get_rect_property, Option<Rect>, set_bounds, set_rect_property, Rect, clear_bounds),
19912013

2014+
/// Text selection should be added to the parent [`Node`] of the `TextRun` nodes.
2015+
/// In [`TextSelection`] the line of selected text is specified by setting the [`NodeId`]
2016+
/// to the `TextRun` that holds the selected line.
2017+
///
2018+
/// For text selection to work correctly [`Node::character_lengths`] needs to be set as well.
19922019
(TextSelection, text_selection, get_text_selection_property, Option<&TextSelection>, set_text_selection, set_text_selection_property, impl Into<Box<TextSelection>>, clear_text_selection)
19932020
}
19942021

0 commit comments

Comments
 (0)