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/button.rs | |
parent | a9eb591628017caaf7aa9af505d1206f7a143a9a (diff) | |
download | iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.gz iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.bz2 iced-fe0a27c56d9d75fb521e69352259f1d737402a20.zip |
Add support for asymmetrical padding
Diffstat (limited to '')
-rw-r--r-- | web/src/widget/button.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 7c389a9f..0e75fa3f 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -1,7 +1,7 @@ //! Allow your users to perform actions by pressing a button. //! //! A [`Button`] has some local [`State`]. -use crate::{css, Background, Bus, Css, Element, Length, Widget}; +use crate::{css, Background, Bus, Css, Element, Length, Padding, Widget}; pub use iced_style::button::{Style, StyleSheet}; @@ -30,7 +30,7 @@ pub struct Button<'a, Message> { min_width: u32, #[allow(dead_code)] min_height: u32, - padding: u16, + padding: Padding, style: Box<dyn StyleSheet>, } @@ -48,7 +48,7 @@ impl<'a, Message> Button<'a, Message> { height: Length::Shrink, min_width: 0, min_height: 0, - padding: 5, + padding: Padding::new(5), style: Default::default(), } } @@ -77,9 +77,14 @@ impl<'a, Message> Button<'a, Message> { self } - /// Sets the padding of the [`Button`]. - pub fn padding(mut self, padding: u16) -> Self { - self.padding = padding; + /// Sets the [`Padding`] of the [`Button`]. + ///```ignore + /// Button::new(/*...*/).padding(20); // 20px on all sides + /// Button::new(/*...*/).padding([10, 20]); // top/bottom, left/right + /// Button::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 } @@ -122,9 +127,6 @@ where // TODO: State-based styling let style = self.style.active(); - let padding_class = - style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let background = match style.background { None => String::from("none"), Some(background) => match background { @@ -132,25 +134,19 @@ where }, }; - let class = { - use dodrio::bumpalo::collections::String; - - String::from_str_in(&padding_class, bump).into_bump_str() - }; - let mut node = button(bump) - .attr("class", class) .attr( "style", bumpalo::format!( in bump, "background: {}; border-radius: {}px; width:{}; \ - min-width: {}; color: {}", + min-width: {}; color: {}; padding: {}", background, style.border_radius, css::length(self.width), css::min_length(self.min_width), - css::color(style.text_color) + css::color(style.text_color), + css::padding(self.padding) ) .into_bump_str(), ) |