Fix styling in button::Renderer implementation

This commit is contained in:
Héctor Ramón Jiménez 2020-01-05 19:48:27 +01:00
parent 7c4dba29c7
commit a848306b89

View File

@ -1,6 +1,6 @@
use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer}; use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
use iced_native::{ 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 { impl iced_native::button::Renderer for Renderer {
@ -45,33 +45,43 @@ impl iced_native::button::Renderer for Renderer {
); );
( (
match styling.background { if styling.background.is_some() || styling.border_width > 0 {
None => content, let background = Primitive::Quad {
Some(background) => Primitive::Group { bounds,
primitives: vec![ background: styling
Primitive::Quad { .background
bounds: Rectangle { .unwrap_or(Background::Color(Color::TRANSPARENT)),
x: bounds.x + styling.shadow_offset.x, border_radius: styling.border_radius,
y: bounds.y + styling.shadow_offset.y, border_width: styling.border_width,
..bounds border_color: styling.border_color,
}, };
background: Background::Color(
[0.0, 0.0, 0.0, 0.5].into(), if styling.shadow_offset == Vector::default() {
), Primitive::Group {
border_radius: styling.border_radius, primitives: vec![background, content],
border_width: 0, }
border_color: Color::TRANSPARENT, } 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
}, },
Primitive::Quad { background: Background::Color(
bounds, [0.0, 0.0, 0.0, 0.5].into(),
background, ),
border_radius: styling.border_radius, border_radius: styling.border_radius,
border_width: styling.border_width, border_width: 0,
border_color: styling.border_color, border_color: Color::TRANSPARENT,
}, };
content,
], Primitive::Group {
}, primitives: vec![shadow, background, content],
}
}
} else {
content
}, },
if is_mouse_over { if is_mouse_over {
MouseCursor::Pointer MouseCursor::Pointer