libcosmic-yoda/src/widget/card/style.rs

48 lines
1.6 KiB
Rust
Raw Normal View History

// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
2023-07-17 11:44:57 -04:00
use iced_core::{Background, Color};
/// Appearance of the cards.
#[derive(Clone, Copy)]
2024-10-16 20:36:46 -04:00
pub struct Style {
2023-07-17 11:44:57 -04:00
pub card_1: Background,
pub card_2: Background,
}
2024-10-16 20:36:46 -04:00
impl Default for Style {
2023-07-17 11:44:57 -04:00
fn default() -> Self {
Self {
card_1: Background::Color(Color::WHITE),
card_2: Background::Color(Color::WHITE),
}
}
}
/// Defines the [`Appearance`] of a cards.
2024-10-16 20:36:46 -04:00
pub trait Catalog {
2023-07-17 11:44:57 -04:00
/// The default [`Appearance`] of the cards.
2024-10-16 20:36:46 -04:00
fn default(&self) -> Style;
2023-07-17 11:44:57 -04:00
}
2025-04-30 15:32:41 -04:00
impl crate::widget::card::style::Catalog for crate::Theme {
fn default(&self) -> crate::widget::card::style::Style {
let cosmic = self.cosmic();
match self.layer {
cosmic_theme::Layer::Background => crate::widget::card::style::Style {
card_1: Background::Color(cosmic.background.component.hover.into()),
card_2: Background::Color(cosmic.background.component.pressed.into()),
},
cosmic_theme::Layer::Primary => crate::widget::card::style::Style {
card_1: Background::Color(cosmic.primary.component.hover.into()),
card_2: Background::Color(cosmic.primary.component.pressed.into()),
},
cosmic_theme::Layer::Secondary => crate::widget::card::style::Style {
card_1: Background::Color(cosmic.secondary.component.hover.into()),
card_2: Background::Color(cosmic.secondary.component.pressed.into()),
},
}
}
}