Skip to main content

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