summaryrefslogtreecommitdiffstats
path: root/native/src/widget/operation/text_input.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-04 05:37:11 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-04 05:37:11 +0100
commit3a0d34c0240f4421737a6a08761f99d6f8140d02 (patch)
treec9a4a6b8e9c1db1b8fcd05bc98e3f131d5ef4bd5 /native/src/widget/operation/text_input.rs
parentc54409d1711e1f615c7ea4b02c082954e340632a (diff)
downloadiced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.gz
iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.bz2
iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.zip
Create `iced_widget` subcrate and re-organize the whole codebase
Diffstat (limited to 'native/src/widget/operation/text_input.rs')
-rw-r--r--native/src/widget/operation/text_input.rs131
1 files changed, 0 insertions, 131 deletions
diff --git a/native/src/widget/operation/text_input.rs b/native/src/widget/operation/text_input.rs
deleted file mode 100644
index 4c773e99..00000000
--- a/native/src/widget/operation/text_input.rs
+++ /dev/null
@@ -1,131 +0,0 @@
-//! Operate on widgets that have text input.
-use crate::widget::operation::Operation;
-use crate::widget::Id;
-
-/// The internal state of a widget that has text input.
-pub trait TextInput {
- /// Moves the cursor of the text input to the front of the input text.
- fn move_cursor_to_front(&mut self);
- /// Moves the cursor of the text input to the end of the input text.
- fn move_cursor_to_end(&mut self);
- /// Moves the cursor of the text input to an arbitrary location.
- fn move_cursor_to(&mut self, position: usize);
- /// Selects all the content of the text input.
- fn select_all(&mut self);
-}
-
-/// Produces an [`Operation`] that moves the cursor of the widget with the given [`Id`] to the
-/// front.
-pub fn move_cursor_to_front<T>(target: Id) -> impl Operation<T> {
- struct MoveCursor {
- target: Id,
- }
-
- impl<T> Operation<T> for MoveCursor {
- fn text_input(&mut self, state: &mut dyn TextInput, id: Option<&Id>) {
- match id {
- Some(id) if id == &self.target => {
- state.move_cursor_to_front();
- }
- _ => {}
- }
- }
-
- fn container(
- &mut self,
- _id: Option<&Id>,
- operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
- ) {
- operate_on_children(self)
- }
- }
-
- MoveCursor { target }
-}
-
-/// Produces an [`Operation`] that moves the cursor of the widget with the given [`Id`] to the
-/// end.
-pub fn move_cursor_to_end<T>(target: Id) -> impl Operation<T> {
- struct MoveCursor {
- target: Id,
- }
-
- impl<T> Operation<T> for MoveCursor {
- fn text_input(&mut self, state: &mut dyn TextInput, id: Option<&Id>) {
- match id {
- Some(id) if id == &self.target => {
- state.move_cursor_to_end();
- }
- _ => {}
- }
- }
-
- fn container(
- &mut self,
- _id: Option<&Id>,
- operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
- ) {
- operate_on_children(self)
- }
- }
-
- MoveCursor { target }
-}
-
-/// Produces an [`Operation`] that moves the cursor of the widget with the given [`Id`] to the
-/// provided position.
-pub fn move_cursor_to<T>(target: Id, position: usize) -> impl Operation<T> {
- struct MoveCursor {
- target: Id,
- position: usize,
- }
-
- impl<T> Operation<T> for MoveCursor {
- fn text_input(&mut self, state: &mut dyn TextInput, id: Option<&Id>) {
- match id {
- Some(id) if id == &self.target => {
- state.move_cursor_to(self.position);
- }
- _ => {}
- }
- }
-
- fn container(
- &mut self,
- _id: Option<&Id>,
- operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
- ) {
- operate_on_children(self)
- }
- }
-
- MoveCursor { target, position }
-}
-
-/// Produces an [`Operation`] that selects all the content of the widget with the given [`Id`].
-pub fn select_all<T>(target: Id) -> impl Operation<T> {
- struct MoveCursor {
- target: Id,
- }
-
- impl<T> Operation<T> for MoveCursor {
- fn text_input(&mut self, state: &mut dyn TextInput, id: Option<&Id>) {
- match id {
- Some(id) if id == &self.target => {
- state.select_all();
- }
- _ => {}
- }
- }
-
- fn container(
- &mut self,
- _id: Option<&Id>,
- operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
- ) {
- operate_on_children(self)
- }
- }
-
- MoveCursor { target }
-}