From 6a2c73d0e0ea710f2b6acfaad2b6a6551f807352 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 08:58:34 -0700 Subject: sketch of move_cursor_to commands --- native/src/widget/text_input.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index e3a5355b..9e7d504a 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -683,6 +683,22 @@ 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(5000); + } } // TODO: Reduce allocations -- cgit From 0d119aa73197d545f12d95e5a2549a68d3067de9 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:08:36 -0700 Subject: added value to move_cursor_to_end --- native/src/widget/text_input.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9e7d504a..0dbcc3d6 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -696,8 +696,8 @@ impl State { /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html - pub fn move_cursor_to_end(&mut self) { - self.cursor.move_to(5000); + pub fn move_cursor_to_end(&mut self, value: &String) { + self.cursor.move_to(value.len()); } } -- cgit From 98cf9c455a201fec3069f415ce2ddf5e88def242 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:19:46 -0700 Subject: added move_cursor_to --- native/src/widget/text_input.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 0dbcc3d6..c821247f 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -699,6 +699,14 @@ impl State { pub fn move_cursor_to_end(&mut self, value: &String) { self.cursor.move_to(value.len()); } + + /// 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 -- cgit From 19c07da86f6481244577f30262d250df25f43c39 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:57:18 -0700 Subject: fixed formatting --- native/src/widget/text_input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c821247f..9d6afffb 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -685,7 +685,7 @@ impl State { } /// 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) { @@ -693,7 +693,7 @@ impl State { } /// 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, value: &String) { @@ -701,7 +701,7 @@ impl State { } /// 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) { -- cgit From 5260b3072ac0426489a16ab435dc9d533c5ed081 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Mon, 8 Jun 2020 10:00:25 -0700 Subject: implemented hecrj's suggestion --- native/src/widget/text_input.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9d6afffb..24085606 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -696,8 +696,8 @@ impl State { /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html - pub fn move_cursor_to_end(&mut self, value: &String) { - self.cursor.move_to(value.len()); + pub fn move_cursor_to_end(&mut self) { + self.cursor.move_to(usize::MAX); } /// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location. -- cgit From dfeb3db003d724a1c980329dab9cbfae55b7f589 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 6 Jul 2020 23:58:15 +0200 Subject: Use `default_font_size` for `TextInput` widget --- native/src/widget/text_input.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 24085606..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 -- cgit