diff options
author | 2021-06-01 19:59:02 +0700 | |
---|---|---|
committer | 2021-06-01 19:59:02 +0700 | |
commit | aab2176802b6d745a7eab76ec13762b5b4ddf782 (patch) | |
tree | 3d1655b36aa8d7151c878e1879c03c8271a466a5 /native/src/widget/button.rs | |
parent | a9eb591628017caaf7aa9af505d1206f7a143a9a (diff) | |
parent | 8a3b71df8b619571ce0a972826cb5a3987b66b3d (diff) | |
download | iced-aab2176802b6d745a7eab76ec13762b5b4ddf782.tar.gz iced-aab2176802b6d745a7eab76ec13762b5b4ddf782.tar.bz2 iced-aab2176802b6d745a7eab76ec13762b5b4ddf782.zip |
Merge pull request #630 from blefevre/asymmetric-padding
Add support for asymmetrical padding
Diffstat (limited to '')
-rw-r--r-- | native/src/widget/button.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 99e98fd1..f61c22d0 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -7,7 +7,8 @@ use crate::mouse; use crate::overlay; use crate::touch; use crate::{ - Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget, + Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, + Widget, }; use std::hash::Hash; @@ -37,7 +38,7 @@ pub struct Button<'a, Message, Renderer: self::Renderer> { height: Length, min_width: u32, min_height: u32, - padding: u16, + padding: Padding, style: Renderer::Style, } @@ -89,9 +90,9 @@ where self } - /// Sets the padding of the [`Button`]. - pub fn padding(mut self, padding: u16) -> Self { - self.padding = padding; + /// Sets the [`Padding`] of the [`Button`]. + pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self { + self.padding = padding.into(); self } @@ -140,18 +141,20 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { - let padding = f32::from(self.padding); let limits = limits .min_width(self.min_width) .min_height(self.min_height) .width(self.width) .height(self.height) - .pad(padding); + .pad(self.padding); let mut content = self.content.layout(renderer, &limits); - content.move_to(Point::new(padding, padding)); + content.move_to(Point::new( + self.padding.left.into(), + self.padding.top.into(), + )); - let size = limits.resolve(content.size()).pad(padding); + let size = limits.resolve(content.size()).pad(self.padding); layout::Node::with_children(size, vec![content]) } @@ -258,7 +261,7 @@ where /// [renderer]: crate::renderer pub trait Renderer: crate::Renderer + Sized { /// The default padding of a [`Button`]. - const DEFAULT_PADDING: u16; + const DEFAULT_PADDING: Padding; /// The style supported by this renderer. type Style: Default; |