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.
This commit is contained in:
parent
6857829dc3
commit
2337029602
3 changed files with 32 additions and 22 deletions
|
|
@ -19,6 +19,8 @@ pub struct Button<'a, Message, Element> {
|
||||||
|
|
||||||
pub width: Length,
|
pub width: Length,
|
||||||
|
|
||||||
|
pub min_width: u32,
|
||||||
|
|
||||||
pub padding: u16,
|
pub padding: u16,
|
||||||
|
|
||||||
pub background: Option<Background>,
|
pub background: Option<Background>,
|
||||||
|
|
@ -52,6 +54,7 @@ impl<'a, Message, Element> Button<'a, Message, Element> {
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
on_press: None,
|
on_press: None,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
|
min_width: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
background: None,
|
background: None,
|
||||||
border_radius: 0,
|
border_radius: 0,
|
||||||
|
|
@ -66,6 +69,11 @@ impl<'a, Message, Element> Button<'a, Message, Element> {
|
||||||
self
|
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 {
|
pub fn padding(mut self, padding: u16) -> Self {
|
||||||
self.padding = padding;
|
self.padding = padding;
|
||||||
self
|
self
|
||||||
|
|
|
||||||
|
|
@ -671,6 +671,7 @@ fn button<'a, Message>(
|
||||||
)
|
)
|
||||||
.padding(12)
|
.padding(12)
|
||||||
.border_radius(12)
|
.border_radius(12)
|
||||||
|
.min_width(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primary_button<'a, Message>(
|
fn primary_button<'a, Message>(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ impl button::Renderer for Renderer {
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let padding = f32::from(button.padding);
|
let padding = f32::from(button.padding);
|
||||||
let limits = limits
|
let limits = limits
|
||||||
.min_width(100)
|
.min_width(button.min_width)
|
||||||
.width(button.width)
|
.width(button.width)
|
||||||
.height(Length::Shrink)
|
.height(Length::Shrink)
|
||||||
.pad(padding);
|
.pad(padding);
|
||||||
|
|
@ -56,7 +56,9 @@ impl button::Renderer for Renderer {
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
Primitive::Group {
|
match button.background {
|
||||||
|
None => content,
|
||||||
|
Some(background) => Primitive::Group {
|
||||||
primitives: vec![
|
primitives: vec![
|
||||||
Primitive::Quad {
|
Primitive::Quad {
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
|
|
@ -71,14 +73,13 @@ impl button::Renderer for Renderer {
|
||||||
},
|
},
|
||||||
Primitive::Quad {
|
Primitive::Quad {
|
||||||
bounds,
|
bounds,
|
||||||
background: button.background.unwrap_or(
|
background,
|
||||||
Background::Color([0.8, 0.8, 0.8].into()),
|
|
||||||
),
|
|
||||||
border_radius: button.border_radius,
|
border_radius: button.border_radius,
|
||||||
},
|
},
|
||||||
content,
|
content,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
if is_mouse_over {
|
if is_mouse_over {
|
||||||
MouseCursor::Pointer
|
MouseCursor::Pointer
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue