cosmic/widget/card/
style.rs

1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4use iced_core::{Background, Color};
5
6/// Appearance of the cards.
7#[derive(Clone, Copy)]
8pub struct Style {
9    pub card_1: Background,
10    pub card_2: Background,
11}
12
13impl Default for Style {
14    fn default() -> Self {
15        Self {
16            card_1: Background::Color(Color::WHITE),
17            card_2: Background::Color(Color::WHITE),
18        }
19    }
20}
21
22/// Defines the [`Appearance`] of a cards.
23pub trait Catalog {
24    /// The default [`Appearance`] of the cards.
25    fn default(&self) -> Style;
26}
27
28impl crate::widget::card::style::Catalog for crate::Theme {
29    fn default(&self) -> crate::widget::card::style::Style {
30        let cosmic = self.cosmic();
31
32        match self.layer {
33            cosmic_theme::Layer::Background => crate::widget::card::style::Style {
34                card_1: Background::Color(cosmic.background.component.hover.into()),
35                card_2: Background::Color(cosmic.background.component.pressed.into()),
36            },
37            cosmic_theme::Layer::Primary => crate::widget::card::style::Style {
38                card_1: Background::Color(cosmic.primary.component.hover.into()),
39                card_2: Background::Color(cosmic.primary.component.pressed.into()),
40            },
41            cosmic_theme::Layer::Secondary => crate::widget::card::style::Style {
42                card_1: Background::Color(cosmic.secondary.component.hover.into()),
43                card_2: Background::Color(cosmic.secondary.component.pressed.into()),
44            },
45        }
46    }
47}