From ea4b3cd6aeb3c4dcb5113389c85f577fd3714682 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 27 Oct 2022 12:10:47 -0700 Subject: Fix text input padding --- native/src/widget/text_input.rs | 12 +++++++++--- 1 file changed, 9 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 c2d25520..6ac4a2dd 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -350,15 +350,21 @@ where { let text_size = size.unwrap_or_else(|| renderer.default_size()); - let limits = limits + let text_limits = limits .pad(padding) .width(width) .height(Length::Units(text_size)); + let limits = limits.width(width).height(Length::Shrink); + + let mut text = layout::Node::new(text_limits.resolve(Size::ZERO)); + + let padding = padding.constrain(text.size(), limits.max()); - let mut text = layout::Node::new(limits.resolve(Size::ZERO)); text.move_to(Point::new(padding.left.into(), padding.top.into())); - layout::Node::with_children(text.size().pad(padding), vec![text]) + let size = limits.pad(padding).resolve(text.size()).pad(padding); + + layout::Node::with_children(size, vec![text]) } /// Processes an [`Event`] and updates the [`State`] of a [`TextInput`] -- cgit From 7476663069572adec25161b46c26570f864f736f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Nov 2022 03:56:05 +0100 Subject: Rename `Padding::constrain` to `fit` --- native/src/widget/text_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 6ac4a2dd..a71c3b63 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -358,7 +358,7 @@ where let mut text = layout::Node::new(text_limits.resolve(Size::ZERO)); - let padding = padding.constrain(text.size(), limits.max()); + let padding = padding.fit(text.size(), limits.max()); text.move_to(Point::new(padding.left.into(), padding.top.into())); -- cgit From 914f0993428c752937d8db0a70a48f6f6f29c839 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Nov 2022 04:04:01 +0100 Subject: Rearrange `layout` code to improve readability --- native/src/widget/text_input.rs | 4 +--- 1 file changed, 1 insertion(+), 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 a71c3b63..dfc49a8d 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -357,13 +357,11 @@ where let limits = limits.width(width).height(Length::Shrink); let mut text = layout::Node::new(text_limits.resolve(Size::ZERO)); - let padding = padding.fit(text.size(), limits.max()); + let size = limits.pad(padding).resolve(text.size()).pad(padding); text.move_to(Point::new(padding.left.into(), padding.top.into())); - let size = limits.pad(padding).resolve(text.size()).pad(padding); - layout::Node::with_children(size, vec![text]) } -- cgit From 18fb74f20092b2703a90afdb01f39754445998da Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Nov 2022 04:05:31 +0100 Subject: Introduce `Custom` variants for every style in the built-in `Theme` --- 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 25a8690e..22eff7f1 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -188,7 +188,7 @@ where self.size, &self.font, self.is_secure, - self.style, + &self.style, ) } } @@ -284,7 +284,7 @@ where self.size, &self.font, self.is_secure, - self.style, + &self.style, ) } @@ -746,7 +746,7 @@ pub fn draw( size: Option, font: &Renderer::Font, is_secure: bool, - style: ::Style, + style: &::Style, ) where Renderer: text::Renderer, Renderer::Theme: StyleSheet, -- cgit From 1480ab20306e463b69b2229dcd5e81d4c66b2a64 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 00:10:53 +0100 Subject: Fix broken documentation links --- native/src/widget/text_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 22eff7f1..2315b05a 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -165,7 +165,7 @@ where } /// Draws the [`TextInput`] with the given [`Renderer`], overriding its - /// [`text_input::Value`] if provided. + /// [`Value`] if provided. /// /// [`Renderer`]: text::Renderer pub fn draw( -- cgit From 44aba47b0e67ce3cf1d5e8a79768e8fe996f5580 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Fri, 11 Nov 2022 08:44:10 +0800 Subject: Allow converting from widget-specific IDs to generic ID --- native/src/widget/text_input.rs | 6 ++++++ 1 file changed, 6 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 2315b05a..e57f41ea 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -332,6 +332,12 @@ impl Id { } } +impl From for widget::Id { + fn from(id: Id) -> Self { + id.0 + } +} + /// Produces a [`Command`] that focuses the [`TextInput`] with the given [`Id`]. pub fn focus(id: Id) -> Command { Command::widget(operation::focusable::focus(id.0)) -- cgit From c4bca3f2af7ae9b2c8dfc3af48ab73dad852ed34 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Fri, 11 Nov 2022 08:43:36 -0800 Subject: Add text input operations --- native/src/widget/text_input.rs | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 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 2315b05a..e2886181 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -233,6 +233,7 @@ where let state = tree.state.downcast_mut::(); operation.focusable(state, self.id.as_ref().map(|id| &id.0)); + operation.text_input(state, self.id.as_ref().map(|id| &id.0)); } fn on_event( @@ -337,6 +338,32 @@ pub fn focus(id: Id) -> Command { Command::widget(operation::focusable::focus(id.0)) } +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// end. +pub fn move_cursor_to_end(id: Id) -> Command { + Command::widget(operation::text_input::move_cursor_to_end(id.0)) +} + +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// front. +pub fn move_cursor_to_front(id: Id) -> Command { + Command::widget(operation::text_input::move_cursor_to_front(id.0)) +} + +/// Produces a [`Command`] that moves the cursor of the [`TextInput`] with the given [`Id`] to the +/// provided position. +pub fn move_cursor_to( + id: Id, + position: usize, +) -> Command { + Command::widget(operation::text_input::move_cursor_to(id.0, position)) +} + +/// Produces a [`Command`] that selects all the content of the [`TextInput`] with the given [`Id`]. +pub fn select_all(id: Id) -> Command { + Command::widget(operation::text_input::select_all(id.0)) +} + /// Computes the layout of a [`TextInput`]. pub fn layout( renderer: &Renderer, @@ -1001,6 +1028,24 @@ impl operation::Focusable for State { } } +impl operation::TextInput for State { + fn move_cursor_to_front(&mut self) { + State::move_cursor_to_front(self) + } + + fn move_cursor_to_end(&mut self) { + State::move_cursor_to_end(self) + } + + fn move_cursor_to(&mut self, position: usize) { + State::move_cursor_to(self, position) + } + + fn select_all(&mut self) { + State::select_all(self) + } +} + mod platform { use crate::keyboard; -- cgit From 3bd99221cc3b50ba9e038b1875fec91fdea8039b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Nov 2022 10:01:40 +0100 Subject: Fix padding for `TextInput` with `Length::Units` width --- native/src/widget/text_input.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 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 ef2f9a17..14e7e1b7 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -383,19 +383,17 @@ where { let text_size = size.unwrap_or_else(|| renderer.default_size()); - let text_limits = limits + let padding = padding.fit(Size::ZERO, limits.max()); + + let limits = limits .pad(padding) .width(width) .height(Length::Units(text_size)); - let limits = limits.width(width).height(Length::Shrink); - - let mut text = layout::Node::new(text_limits.resolve(Size::ZERO)); - let padding = padding.fit(text.size(), limits.max()); - let size = limits.pad(padding).resolve(text.size()).pad(padding); + let mut text = layout::Node::new(limits.resolve(Size::ZERO)); text.move_to(Point::new(padding.left.into(), padding.top.into())); - layout::Node::with_children(size, vec![text]) + layout::Node::with_children(text.size().pad(padding), vec![text]) } /// Processes an [`Event`] and updates the [`State`] of a [`TextInput`] -- cgit