diff options
author | 2020-11-23 17:19:21 +0000 | |
---|---|---|
committer | 2021-06-01 19:05:39 +0700 | |
commit | fe0a27c56d9d75fb521e69352259f1d737402a20 (patch) | |
tree | f7f77430b63983717036a81e734276123d139ca6 /web/src/widget/text_input.rs | |
parent | a9eb591628017caaf7aa9af505d1206f7a143a9a (diff) | |
download | iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.gz iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.bz2 iced-fe0a27c56d9d75fb521e69352259f1d737402a20.zip |
Add support for asymmetrical padding
Diffstat (limited to 'web/src/widget/text_input.rs')
-rw-r--r-- | web/src/widget/text_input.rs | 30 |
1 files changed, 13 insertions, 17 deletions
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<u16>, on_change: Rc<Box<dyn Fn(String) -> Message>>, on_submit: Option<Message>, @@ -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<P: Into<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, |