diff options
author | 2020-07-08 11:44:40 +0200 | |
---|---|---|
committer | 2020-07-08 11:44:40 +0200 | |
commit | f3dfaa2c43bad16fc91660b2b73cb9173549e7ec (patch) | |
tree | 353365f4dd1e3136bc651ac8c1572f62fff1304b /native/src/widget/text_input.rs | |
parent | 072ec69d53d2708d8fd1693151bcec7305efccf8 (diff) | |
parent | 5c4f5ae5ecb36703a95cafb2cd58692529c9466d (diff) | |
download | iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.gz iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.bz2 iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.zip |
Merge branch 'master' into feature/pane-grid-titlebar
Diffstat (limited to 'native/src/widget/text_input.rs')
-rw-r--r-- | native/src/widget/text_input.rs | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index e3a5355b..3f415101 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -17,8 +17,8 @@ use editor::Editor; use crate::{ keyboard, layout, mouse::{self, click}, - Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle, Size, - Widget, + text, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle, + Size, Widget, }; use std::u32; @@ -486,7 +486,8 @@ where let text_bounds = layout.children().next().unwrap().bounds(); if self.is_secure { - renderer.draw( + self::Renderer::draw( + renderer, bounds, text_bounds, cursor_position, @@ -498,7 +499,8 @@ where &self.style, ) } else { - renderer.draw( + self::Renderer::draw( + renderer, bounds, text_bounds, cursor_position, @@ -531,20 +533,10 @@ where /// /// [`TextInput`]: struct.TextInput.html /// [renderer]: ../../renderer/index.html -pub trait Renderer: crate::Renderer + Sized { - /// The font type used for [`TextInput`]. - /// - /// [`TextInput`]: struct.TextInput.html - type Font: Default + Copy; - +pub trait Renderer: text::Renderer + Sized { /// The style supported by this renderer. type Style: Default; - /// Returns the default size of the text of the [`TextInput`]. - /// - /// [`TextInput`]: struct.TextInput.html - fn default_size(&self) -> u16; - /// Returns the width of the value of the [`TextInput`]. /// /// [`TextInput`]: struct.TextInput.html @@ -683,6 +675,30 @@ impl State { pub fn cursor(&self) -> Cursor { self.cursor } + + /// Moves the [`Cursor`] of the [`TextInput`] to the front of the input text. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to_front(&mut self) { + self.cursor.move_to(0); + } + + /// Moves the [`Cursor`] of the [`TextInput`] to the end of the input text. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to_end(&mut self) { + self.cursor.move_to(usize::MAX); + } + + /// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to(&mut self, position: usize) { + self.cursor.move_to(position); + } } // TODO: Reduce allocations |