From fe0a27c56d9d75fb521e69352259f1d737402a20 Mon Sep 17 00:00:00 2001 From: Ben LeFevre Date: Mon, 23 Nov 2020 17:19:21 +0000 Subject: Add support for asymmetrical padding --- web/src/widget/text_input.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index bc2048a8..c671f80e 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -1,7 +1,7 @@ //! Display fields that can be filled with text. //! //! A [`TextInput`] has some local [`State`]. -use crate::{bumpalo, css, Bus, Css, Element, Length, Widget}; +use crate::{bumpalo, css, Bus, Css, Element, Length, Padding, Widget}; pub use iced_style::text_input::{Style, StyleSheet}; @@ -35,7 +35,7 @@ pub struct TextInput<'a, Message> { is_secure: bool, width: Length, max_width: u32, - padding: u16, + padding: Padding, size: Option, on_change: Rc Message>>, on_submit: Option, @@ -66,7 +66,7 @@ impl<'a, Message> TextInput<'a, Message> { is_secure: false, width: Length::Fill, max_width: u32::MAX, - padding: 0, + padding: Padding::ZERO, size: None, on_change: Rc::new(Box::new(on_change)), on_submit: None, @@ -92,9 +92,14 @@ impl<'a, Message> TextInput<'a, Message> { self } - /// Sets the padding of the [`TextInput`]. - pub fn padding(mut self, units: u16) -> Self { - self.padding = units; + /// Sets the [`Padding`] of the [`TextInput`]. + ///```ignore + /// TextInput::new(/*...*/).padding(20); // 20px on all sides + /// TextInput::new(/*...*/).padding([10, 20]); // top/bottom, left/right + /// TextInput::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left + /// ``` + pub fn padding>(mut self, padding: P) -> Self { + self.padding = padding.into(); self } @@ -131,15 +136,6 @@ where use dodrio::builder::*; use wasm_bindgen::JsCast; - let class = { - use dodrio::bumpalo::collections::String; - - let padding_class = - style_sheet.insert(bump, css::Rule::Padding(self.padding)); - - String::from_str_in(&padding_class, bump).into_bump_str() - }; - let placeholder = { use dodrio::bumpalo::collections::String; @@ -159,16 +155,16 @@ where let style = self.style_sheet.active(); input(bump) - .attr("class", class) .attr( "style", bumpalo::format!( in bump, - "width: {}; max-width: {}; font-size: {}px; \ + "width: {}; max-width: {}; padding: {}; font-size: {}px; \ background: {}; border-width: {}px; border-color: {}; \ border-radius: {}px; color: {}", css::length(self.width), css::max_length(self.max_width), + css::padding(self.padding), self.size.unwrap_or(20), css::background(style.background), style.border_width, -- cgit From 2e17d7860b6f857315f14341813645ca980a15df Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:14:04 +0700 Subject: Fix unused variable warning in `iced_web::text_input` --- web/src/widget/text_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index c671f80e..591fc21d 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -131,7 +131,7 @@ where &self, bump: &'b bumpalo::Bump, bus: &Bus, - style_sheet: &mut Css<'b>, + _style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; use wasm_bindgen::JsCast; -- cgit From 8a3b71df8b619571ce0a972826cb5a3987b66b3d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:45:47 +0700 Subject: Replace ignored doc-tests with additional documentation for `Padding` --- web/src/widget/text_input.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 591fc21d..e8d8ca2f 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -93,11 +93,6 @@ impl<'a, Message> TextInput<'a, Message> { } /// Sets the [`Padding`] of the [`TextInput`]. - ///```ignore - /// TextInput::new(/*...*/).padding(20); // 20px on all sides - /// TextInput::new(/*...*/).padding([10, 20]); // top/bottom, left/right - /// TextInput::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left - /// ``` pub fn padding>(mut self, padding: P) -> Self { self.padding = padding.into(); self -- cgit From 29cc840cfa129a5ee3ecd1befe6e0fe85cb0e2d7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 20:32:54 +0700 Subject: Add empty `select_all` implementation for `TextInput` in `iced_web` --- web/src/widget/text_input.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index bc2048a8..d61ee2fd 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -232,4 +232,9 @@ impl State { // TODO Self::default() } + + /// Selects all the content of the [`TextInput`]. + pub fn select_all(&mut self) { + // TODO + } } -- cgit