diff options
author | 2022-11-14 00:24:23 +0100 | |
---|---|---|
committer | 2022-11-14 00:24:23 +0100 | |
commit | f5c9f63329ec420757c81ef73ab76e7a8cb2cd2e (patch) | |
tree | 06cd44cdc5abfca94c1acfa10ab0281ae21c4b0c /native/src/widget/text_input.rs | |
parent | 5f08b8d41ae2d749bd11068f103a0f8ce3abd7bf (diff) | |
parent | a7a4a92466a4447f8d2e9b5ae2fc715ba6262de0 (diff) | |
download | iced-f5c9f63329ec420757c81ef73ab76e7a8cb2cd2e.tar.gz iced-f5c9f63329ec420757c81ef73ab76e7a8cb2cd2e.tar.bz2 iced-f5c9f63329ec420757c81ef73ab76e7a8cb2cd2e.zip |
Merge pull request #1529 from tarkah/feat/text-input-operations
Add text input operations
Diffstat (limited to 'native/src/widget/text_input.rs')
-rw-r--r-- | native/src/widget/text_input.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 2315b05a..e2886181 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -233,6 +233,7 @@ where let state = tree.state.downcast_mut::<State>(); operation.focusable(state, self.id.as_ref().map(|id| &id.0)); + operation.text_input(state, self.id.as_ref().map(|id| &id.0)); } fn on_event( @@ -337,6 +338,32 @@ pub fn focus<Message: 'static>(id: Id) -> Command<Message> { Command::widget(operation::focusable::focus(id.0)) } +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// end. +pub fn move_cursor_to_end<Message: 'static>(id: Id) -> Command<Message> { + Command::widget(operation::text_input::move_cursor_to_end(id.0)) +} + +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// front. +pub fn move_cursor_to_front<Message: 'static>(id: Id) -> Command<Message> { + Command::widget(operation::text_input::move_cursor_to_front(id.0)) +} + +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// provided position. +pub fn move_cursor_to<Message: 'static>( + id: Id, + position: usize, +) -> Command<Message> { + Command::widget(operation::text_input::move_cursor_to(id.0, position)) +} + +/// Produces a [`Command`] that selects all the content of the [`TextInput`] with the given [`Id`]. +pub fn select_all<Message: 'static>(id: Id) -> Command<Message> { + Command::widget(operation::text_input::select_all(id.0)) +} + /// Computes the layout of a [`TextInput`]. pub fn layout<Renderer>( renderer: &Renderer, @@ -1001,6 +1028,24 @@ impl operation::Focusable for State { } } +impl operation::TextInput for State { + fn move_cursor_to_front(&mut self) { + State::move_cursor_to_front(self) + } + + fn move_cursor_to_end(&mut self) { + State::move_cursor_to_end(self) + } + + fn move_cursor_to(&mut self, position: usize) { + State::move_cursor_to(self, position) + } + + fn select_all(&mut self) { + State::select_all(self) + } +} + mod platform { use crate::keyboard; |