diff options
Diffstat (limited to '')
| -rw-r--r-- | widget/src/text_input.rs | 24 | ||||
| -rw-r--r-- | widget/src/text_input/cursor.rs | 26 | ||||
| -rw-r--r-- | widget/src/text_input/value.rs | 11 | 
3 files changed, 31 insertions, 30 deletions
| diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index f9a2d419..27efe755 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -250,7 +250,7 @@ where              self.is_secure,              self.icon.as_ref(),              &self.style, -        ) +        );      }  } @@ -375,7 +375,7 @@ where              self.is_secure,              self.icon.as_ref(),              &self.style, -        ) +        );      }      fn mouse_interaction( @@ -619,7 +619,7 @@ where              font,              size,              line_height, -        ) +        );      };      match event { @@ -846,7 +846,7 @@ where                                  state.cursor.move_left_by_words(value);                              }                          } else if modifiers.shift() { -                            state.cursor.select_left(value) +                            state.cursor.select_left(value);                          } else {                              state.cursor.move_left(value);                          } @@ -861,7 +861,7 @@ where                                  state.cursor.move_right_by_words(value);                              }                          } else if modifiers.shift() { -                            state.cursor.select_right(value) +                            state.cursor.select_right(value);                          } else {                              state.cursor.move_right(value);                          } @@ -1217,7 +1217,7 @@ pub fn draw<Renderer>(      if text_width > text_bounds.width {          renderer.with_layer(text_bounds, |renderer| { -            renderer.with_translation(Vector::new(-offset, 0.0), render) +            renderer.with_translation(Vector::new(-offset, 0.0), render);          });      } else {          render(renderer); @@ -1339,29 +1339,29 @@ impl<P: text::Paragraph> operation::Focusable for State<P> {      }      fn focus(&mut self) { -        State::focus(self) +        State::focus(self);      }      fn unfocus(&mut self) { -        State::unfocus(self) +        State::unfocus(self);      }  }  impl<P: text::Paragraph> operation::TextInput for State<P> {      fn move_cursor_to_front(&mut self) { -        State::move_cursor_to_front(self) +        State::move_cursor_to_front(self);      }      fn move_cursor_to_end(&mut self) { -        State::move_cursor_to_end(self) +        State::move_cursor_to_end(self);      }      fn move_cursor_to(&mut self, position: usize) { -        State::move_cursor_to(self, position) +        State::move_cursor_to(self, position);      }      fn select_all(&mut self) { -        State::select_all(self) +        State::select_all(self);      }  } diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs index 9680dfd7..f682b17d 100644 --- a/widget/src/text_input/cursor.rs +++ b/widget/src/text_input/cursor.rs @@ -56,7 +56,7 @@ impl Cursor {              State::Selection { start, end } => {                  Some((start.min(end), start.max(end)))              } -            _ => None, +            State::Index(_) => None,          }      } @@ -65,11 +65,11 @@ impl Cursor {      }      pub(crate) fn move_right(&mut self, value: &Value) { -        self.move_right_by_amount(value, 1) +        self.move_right_by_amount(value, 1);      }      pub(crate) fn move_right_by_words(&mut self, value: &Value) { -        self.move_to(value.next_end_of_word(self.right(value))) +        self.move_to(value.next_end_of_word(self.right(value)));      }      pub(crate) fn move_right_by_amount( @@ -79,7 +79,7 @@ impl Cursor {      ) {          match self.state(value) {              State::Index(index) => { -                self.move_to(index.saturating_add(amount).min(value.len())) +                self.move_to(index.saturating_add(amount).min(value.len()));              }              State::Selection { start, end } => self.move_to(end.max(start)),          } @@ -89,7 +89,7 @@ impl Cursor {          match self.state(value) {              State::Index(index) if index > 0 => self.move_to(index - 1),              State::Selection { start, end } => self.move_to(start.min(end)), -            _ => self.move_to(0), +            State::Index(_) => self.move_to(0),          }      } @@ -108,10 +108,10 @@ impl Cursor {      pub(crate) fn select_left(&mut self, value: &Value) {          match self.state(value) {              State::Index(index) if index > 0 => { -                self.select_range(index, index - 1) +                self.select_range(index, index - 1);              }              State::Selection { start, end } if end > 0 => { -                self.select_range(start, end - 1) +                self.select_range(start, end - 1);              }              _ => {}          } @@ -120,10 +120,10 @@ impl Cursor {      pub(crate) fn select_right(&mut self, value: &Value) {          match self.state(value) {              State::Index(index) if index < value.len() => { -                self.select_range(index, index + 1) +                self.select_range(index, index + 1);              }              State::Selection { start, end } if end < value.len() => { -                self.select_range(start, end + 1) +                self.select_range(start, end + 1);              }              _ => {}          } @@ -132,10 +132,10 @@ impl Cursor {      pub(crate) fn select_left_by_words(&mut self, value: &Value) {          match self.state(value) {              State::Index(index) => { -                self.select_range(index, value.previous_start_of_word(index)) +                self.select_range(index, value.previous_start_of_word(index));              }              State::Selection { start, end } => { -                self.select_range(start, value.previous_start_of_word(end)) +                self.select_range(start, value.previous_start_of_word(end));              }          }      } @@ -143,10 +143,10 @@ impl Cursor {      pub(crate) fn select_right_by_words(&mut self, value: &Value) {          match self.state(value) {              State::Index(index) => { -                self.select_range(index, value.next_end_of_word(index)) +                self.select_range(index, value.next_end_of_word(index));              }              State::Selection { start, end } => { -                self.select_range(start, value.next_end_of_word(end)) +                self.select_range(start, value.next_end_of_word(end));              }          }      } diff --git a/widget/src/text_input/value.rs b/widget/src/text_input/value.rs index d1b056c8..46a1f754 100644 --- a/widget/src/text_input/value.rs +++ b/widget/src/text_input/value.rs @@ -89,11 +89,6 @@ impl Value {          Self { graphemes }      } -    /// Converts the [`Value`] into a `String`. -    pub fn to_string(&self) -> String { -        self.graphemes.concat() -    } -      /// Inserts a new `char` at the given grapheme `index`.      pub fn insert(&mut self, index: usize, c: char) {          self.graphemes.insert(index, c.to_string()); @@ -131,3 +126,9 @@ impl Value {          }      }  } + +impl std::fmt::Display for Value { +    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +        f.write_str(&self.graphemes.concat()) +    } +} | 
