cosmic/widget/wayland/tooltip/
mod.rs

1//! Change the apperance of a tooltip.
2
3pub mod widget;
4
5// Copyright 2023 System76 <info@system76.com>
6// SPDX-License-Identifier: MPL-2.0
7
8use iced_core::{Background, Color, Vector, border::Radius};
9
10use crate::theme::THEME;
11
12/// The appearance of a tooltip.
13#[must_use]
14#[derive(Debug, Clone, Copy)]
15pub struct Style {
16    /// The amount of offset to apply to the shadow of the tooltip.
17    pub shadow_offset: Vector,
18
19    /// The [`Background`] of the tooltip.
20    pub background: Option<Background>,
21
22    /// The border radius of the tooltip.
23    pub border_radius: Radius,
24
25    /// The border width of the tooltip.
26    pub border_width: f32,
27
28    /// The border [`Color`] of the tooltip.
29    pub border_color: Color,
30
31    /// An outline placed around the border.
32    pub outline_width: f32,
33
34    /// The [`Color`] of the outline.
35    pub outline_color: Color,
36
37    /// The icon [`Color`] of the tooltip.
38    pub icon_color: Option<Color>,
39
40    /// The text [`Color`] of the tooltip.
41    pub text_color: Color,
42}
43
44impl Style {
45    // TODO: `Radius` is not `const fn` compatible.
46    pub fn new() -> Self {
47        let rad_0 = THEME.lock().unwrap().cosmic().corner_radii.radius_0;
48        Self {
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: Color::BLACK,
58        }
59    }
60}
61
62impl std::default::Default for Style {
63    fn default() -> Self {
64        Self::new()
65    }
66}
67
68// TODO update to match other styles
69/// A set of rules that dictate the style of a tooltip.
70pub trait Catalog {
71    /// The supported style of the [`StyleSheet`].
72    type Class: Default;
73
74    /// Produces the active [`Appearance`] of a tooltip.
75    fn style(&self, style: &Self::Class) -> Style;
76}