summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-05 19:48:27 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-05 19:48:27 +0100
commita848306b89053ef4ba2aeb4eb7899bec94d93cb3 (patch)
treed0f07322f84451982b73dcdbe933a5b770b9ca25
parent7c4dba29c7614428041bda049924569d751cbb1a (diff)
downloadiced-a848306b89053ef4ba2aeb4eb7899bec94d93cb3.tar.gz
iced-a848306b89053ef4ba2aeb4eb7899bec94d93cb3.tar.bz2
iced-a848306b89053ef4ba2aeb4eb7899bec94d93cb3.zip
Fix styling in `button::Renderer` implementation
-rw-r--r--wgpu/src/renderer/widget/button.rs64
1 files changed, 37 insertions, 27 deletions
diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs
index 63a53473..eb5d7c09 100644
--- a/wgpu/src/renderer/widget/button.rs
+++ b/wgpu/src/renderer/widget/button.rs
@@ -1,6 +1,6 @@
use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
use iced_native::{
- Background, Color, Element, Layout, MouseCursor, Point, Rectangle,
+ Background, Color, Element, Layout, MouseCursor, Point, Rectangle, Vector,
};
impl iced_native::button::Renderer for Renderer {
@@ -45,33 +45,43 @@ impl iced_native::button::Renderer for Renderer {
);
(
- match styling.background {
- None => content,
- Some(background) => Primitive::Group {
- primitives: vec![
- Primitive::Quad {
- bounds: Rectangle {
- x: bounds.x + styling.shadow_offset.x,
- y: bounds.y + styling.shadow_offset.y,
- ..bounds
- },
- background: Background::Color(
- [0.0, 0.0, 0.0, 0.5].into(),
- ),
- border_radius: styling.border_radius,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- },
- Primitive::Quad {
- bounds,
- background,
- border_radius: styling.border_radius,
- border_width: styling.border_width,
- border_color: styling.border_color,
+ if styling.background.is_some() || styling.border_width > 0 {
+ let background = Primitive::Quad {
+ bounds,
+ background: styling
+ .background
+ .unwrap_or(Background::Color(Color::TRANSPARENT)),
+ border_radius: styling.border_radius,
+ border_width: styling.border_width,
+ border_color: styling.border_color,
+ };
+
+ if styling.shadow_offset == Vector::default() {
+ Primitive::Group {
+ primitives: vec![background, content],
+ }
+ } else {
+ // TODO: Implement proper shadow support
+ let shadow = Primitive::Quad {
+ bounds: Rectangle {
+ x: bounds.x + styling.shadow_offset.x,
+ y: bounds.y + styling.shadow_offset.y,
+ ..bounds
},
- content,
- ],
- },
+ background: Background::Color(
+ [0.0, 0.0, 0.0, 0.5].into(),
+ ),
+ border_radius: styling.border_radius,
+ border_width: 0,
+ border_color: Color::TRANSPARENT,
+ };
+
+ Primitive::Group {
+ primitives: vec![shadow, background, content],
+ }
+ }
+ } else {
+ content
},
if is_mouse_over {
MouseCursor::Pointer