From bf375587aa52808cdabf4191571f20784315ea99 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 20 Jan 2024 13:34:07 +0100 Subject: Add `Shadow` to `container::Appearance` --- style/src/container.rs | 4 +++- style/src/theme.rs | 3 ++- widget/src/button.rs | 3 +-- widget/src/container.rs | 7 +++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/style/src/container.rs b/style/src/container.rs index a490c187..00649c25 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -1,5 +1,5 @@ //! Change the appearance of a container. -use crate::core::{Background, Border, Color, Pixels}; +use crate::core::{Background, Border, Color, Pixels, Shadow}; /// The appearance of a container. #[derive(Debug, Clone, Copy, Default)] @@ -10,6 +10,8 @@ pub struct Appearance { pub background: Option, /// The [`Border`] of the container. pub border: Border, + /// The [`Shadow`] of the container. + pub shadow: Shadow, } impl Appearance { diff --git a/style/src/theme.rs b/style/src/theme.rs index d90efb0a..8d1ff237 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -21,7 +21,7 @@ use crate::text_editor; use crate::text_input; use crate::toggler; -use crate::core::{Background, Border, Color, Vector}; +use crate::core::{Background, Border, Color, Shadow, Vector}; use std::fmt; use std::rc::Rc; @@ -434,6 +434,7 @@ impl container::StyleSheet for Theme { text_color: None, background: Some(palette.background.weak.color.into()), border: Border::with_radius(2), + shadow: Shadow::default(), } } Container::Custom(custom) => custom.appearance(self), diff --git a/widget/src/button.rs b/widget/src/button.rs index cd141169..14626dd3 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -392,15 +392,14 @@ where }; if styling.background.is_some() - || styling.shadow.color.a > 0.0 || styling.border.width > 0.0 + || styling.shadow.color.a > 0.0 { renderer.fill_quad( renderer::Quad { bounds, border: styling.border, shadow: styling.shadow, - ..renderer::Quad::default() }, styling .background diff --git a/widget/src/container.rs b/widget/src/container.rs index b87f1d9f..f2d1aaba 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -337,12 +337,15 @@ pub fn draw_background( ) where Renderer: crate::core::Renderer, { - if appearance.background.is_some() || appearance.border.width > 0.0 { + if appearance.background.is_some() + || appearance.border.width > 0.0 + || appearance.shadow.color.a > 0.0 + { renderer.fill_quad( renderer::Quad { bounds, border: appearance.border, - ..renderer::Quad::default() + shadow: appearance.shadow, }, appearance .background -- cgit