Add Shadow to container::Appearance

This commit is contained in:
Héctor Ramón Jiménez 2024-01-20 13:34:07 +01:00
parent e736038d5f
commit bf375587aa
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 11 additions and 6 deletions

View file

@ -1,5 +1,5 @@
//! Change the appearance of a container. //! 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. /// The appearance of a container.
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
@ -10,6 +10,8 @@ pub struct Appearance {
pub background: Option<Background>, pub background: Option<Background>,
/// The [`Border`] of the container. /// The [`Border`] of the container.
pub border: Border, pub border: Border,
/// The [`Shadow`] of the container.
pub shadow: Shadow,
} }
impl Appearance { impl Appearance {

View file

@ -21,7 +21,7 @@ use crate::text_editor;
use crate::text_input; use crate::text_input;
use crate::toggler; use crate::toggler;
use crate::core::{Background, Border, Color, Vector}; use crate::core::{Background, Border, Color, Shadow, Vector};
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
@ -434,6 +434,7 @@ impl container::StyleSheet for Theme {
text_color: None, text_color: None,
background: Some(palette.background.weak.color.into()), background: Some(palette.background.weak.color.into()),
border: Border::with_radius(2), border: Border::with_radius(2),
shadow: Shadow::default(),
} }
} }
Container::Custom(custom) => custom.appearance(self), Container::Custom(custom) => custom.appearance(self),

View file

@ -392,15 +392,14 @@ where
}; };
if styling.background.is_some() if styling.background.is_some()
|| styling.shadow.color.a > 0.0
|| styling.border.width > 0.0 || styling.border.width > 0.0
|| styling.shadow.color.a > 0.0
{ {
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds, bounds,
border: styling.border, border: styling.border,
shadow: styling.shadow, shadow: styling.shadow,
..renderer::Quad::default()
}, },
styling styling
.background .background

View file

@ -337,12 +337,15 @@ pub fn draw_background<Renderer>(
) where ) where
Renderer: crate::core::Renderer, 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.fill_quad(
renderer::Quad { renderer::Quad {
bounds, bounds,
border: appearance.border, border: appearance.border,
..renderer::Quad::default() shadow: appearance.shadow,
}, },
appearance appearance
.background .background