1// Copyright 2023 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
34//! Change the apperance of a button.
5use iced_core::{Background, Color, Vector, border::Radius};
67use crate::theme::THEME;
89/// The appearance of a button.
10#[must_use]
11#[derive(Debug, Clone, Copy)]
12pub struct Style {
13/// The amount of offset to apply to the shadow of the button.
14pub shadow_offset: Vector,
1516/// The [`Background`] of the button.
17pub background: Option<Background>,
1819/// The [`Background`] overlay of the button.
20pub overlay: Option<Background>,
2122/// The border radius of the button.
23pub border_radius: Radius,
2425/// The border width of the button.
26pub border_width: f32,
2728/// The border [`Color`] of the button.
29pub border_color: Color,
3031/// An outline placed around the border.
32pub outline_width: f32,
3334/// The [`Color`] of the outline.
35pub outline_color: Color,
3637/// The icon [`Color`] of the button.
38pub icon_color: Option<Color>,
3940/// The text [`Color`] of the button.
41pub text_color: Option<Color>,
42}
4344impl Style {
45// TODO: `Radius` is not `const fn` compatible.
46pub fn new() -> Self {
47let rad_0 = THEME.lock().unwrap().cosmic().corner_radii.radius_0;
48Self {
49 shadow_offset: Vector::new(0.0, 0.0),
50 background: None,
51 border_radius: Radius::from(rad_0),
52 border_width: 0.0,
53 border_color: Color::TRANSPARENT,
54 outline_width: 0.0,
55 outline_color: Color::TRANSPARENT,
56 icon_color: None,
57 text_color: None,
58 overlay: None,
59 }
60 }
61}
6263impl std::default::Default for Style {
64fn default() -> Self {
65Self::new()
66 }
67}
6869// TODO update to match other styles
70/// A set of rules that dictate the style of a button.
71pub trait Catalog {
72/// The supported style of the [`StyleSheet`].
73type Class: Default;
7475/// Produces the active [`Appearance`] of a button.
76fn active(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
7778/// Produces the disabled [`Appearance`] of a button.
79fn disabled(&self, style: &Self::Class) -> Style;
8081/// [`Appearance`] when the button is the target of a DND operation.
82fn drop_target(&self, style: &Self::Class) -> Style {
83self.hovered(false, false, style)
84 }
8586/// Produces the hovered [`Appearance`] of a button.
87fn hovered(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
8889/// Produces the pressed [`Appearance`] of a button.
90fn pressed(&self, focused: bool, selected: bool, style: &Self::Class) -> Style;
9192/// Background color of the selection indicator
93fn selection_background(&self) -> Background;
94}