summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-13 07:34:07 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-13 07:36:50 +0100
commit23370296024fc30b8721902955867c2fdab88832 (patch)
tree83097972fe18eb0d8f55d671315217f3eed0edec
parent6857829dc3171fd68065498b6cd29f0ef02a8d43 (diff)
downloadiced-23370296024fc30b8721902955867c2fdab88832.tar.gz
iced-23370296024fc30b8721902955867c2fdab88832.tar.bz2
iced-23370296024fc30b8721902955867c2fdab88832.zip
Remove default styling of `Button`
- A background will only show if explicitly set. - `iced_wgpu` won't apply a `min_width` of 100 units anymore.
-rw-r--r--core/src/widget/button.rs8
-rw-r--r--examples/tour.rs1
-rw-r--r--wgpu/src/renderer/widget/button.rs45
3 files changed, 32 insertions, 22 deletions
diff --git a/core/src/widget/button.rs b/core/src/widget/button.rs
index 9cf20071..e7961284 100644
--- a/core/src/widget/button.rs
+++ b/core/src/widget/button.rs
@@ -19,6 +19,8 @@ pub struct Button<'a, Message, Element> {
pub width: Length,
+ pub min_width: u32,
+
pub padding: u16,
pub background: Option<Background>,
@@ -52,6 +54,7 @@ impl<'a, Message, Element> Button<'a, Message, Element> {
content: content.into(),
on_press: None,
width: Length::Shrink,
+ min_width: 0,
padding: 0,
background: None,
border_radius: 0,
@@ -66,6 +69,11 @@ impl<'a, Message, Element> Button<'a, Message, Element> {
self
}
+ pub fn min_width(mut self, min_width: u32) -> Self {
+ self.min_width = min_width;
+ self
+ }
+
pub fn padding(mut self, padding: u16) -> Self {
self.padding = padding;
self
diff --git a/examples/tour.rs b/examples/tour.rs
index 3fd031b8..34ad0a34 100644
--- a/examples/tour.rs
+++ b/examples/tour.rs
@@ -671,6 +671,7 @@ fn button<'a, Message>(
)
.padding(12)
.border_radius(12)
+ .min_width(100)
}
fn primary_button<'a, Message>(
diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs
index 3d5e42ba..a19c7d86 100644
--- a/wgpu/src/renderer/widget/button.rs
+++ b/wgpu/src/renderer/widget/button.rs
@@ -12,7 +12,7 @@ impl button::Renderer for Renderer {
) -> layout::Node {
let padding = f32::from(button.padding);
let limits = limits
- .min_width(100)
+ .min_width(button.min_width)
.width(button.width)
.height(Length::Shrink)
.pad(padding);
@@ -56,28 +56,29 @@ impl button::Renderer for Renderer {
};
(
- Primitive::Group {
- primitives: vec![
- Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + 1.0,
- y: bounds.y + shadow_offset,
- ..bounds
+ match button.background {
+ None => content,
+ Some(background) => Primitive::Group {
+ primitives: vec![
+ Primitive::Quad {
+ bounds: Rectangle {
+ x: bounds.x + 1.0,
+ y: bounds.y + shadow_offset,
+ ..bounds
+ },
+ background: Background::Color(
+ [0.0, 0.0, 0.0, 0.5].into(),
+ ),
+ border_radius: button.border_radius,
},
- background: Background::Color(
- [0.0, 0.0, 0.0, 0.5].into(),
- ),
- border_radius: button.border_radius,
- },
- Primitive::Quad {
- bounds,
- background: button.background.unwrap_or(
- Background::Color([0.8, 0.8, 0.8].into()),
- ),
- border_radius: button.border_radius,
- },
- content,
- ],
+ Primitive::Quad {
+ bounds,
+ background,
+ border_radius: button.border_radius,
+ },
+ content,
+ ],
+ },
},
if is_mouse_over {
MouseCursor::Pointer