Implement text_input::State::focused

This commit is contained in:
Héctor Ramón Jiménez 2019-11-13 07:38:06 +01:00
parent 621e5a55b7
commit 657e513651
2 changed files with 19 additions and 0 deletions

View file

@ -91,6 +91,13 @@ impl State {
Self::default()
}
pub fn focused(value: &str) -> Self {
Self {
is_focused: true,
cursor_position: Value::new(value).len(),
}
}
pub fn move_cursor_right(&mut self, value: &Value) {
let current = self.cursor_position(value);
@ -107,6 +114,10 @@ impl State {
}
}
pub fn move_cursor_to_end(&mut self, value: &Value) {
self.cursor_position = value.len();
}
pub fn cursor_position(&self, value: &Value) -> usize {
self.cursor_position.min(value.len())
}