iced_aw/style/
context_menu.rs

1//! Use a badge for color highlighting important information.
2//!
3//! *This API requires the following crate features to be activated: badge*
4use super::{Status, StyleFn};
5use iced_core::{Background, Color, Theme};
6
7/// The style of a [`ContextMenu`](crate::widget::ContextMenu).
8#[derive(Clone, Copy, Debug)]
9pub struct Style {
10    /// The background of the [`ContextMenu`](crate::widget::ContextMenu).
11    ///
12    /// This is used to color the backdrop of the modal.
13    pub background: Background,
14}
15
16impl Default for Style {
17    fn default() -> Self {
18        Self {
19            background: Background::Color([0.87, 0.87, 0.87, 0.30].into()),
20        }
21    }
22}
23
24/// The Catalog of a [`ContextMenu`](crate::widget::ContextMenu).
25pub trait Catalog {
26    ///Style for the trait to use.
27    type Class<'a>;
28
29    /// The default class produced by the [`Catalog`].
30    fn default<'a>() -> Self::Class<'a>;
31
32    /// The [`Style`] of a class with the given status.
33    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
34}
35
36impl Catalog for Theme {
37    type Class<'a> = StyleFn<'a, Self, Style>;
38
39    fn default<'a>() -> Self::Class<'a> {
40        Box::new(primary)
41    }
42
43    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
44        class(self, status)
45    }
46}
47
48/// The primary theme of a [`ContextMenu`](crate::widget::ContextMenu).
49#[must_use]
50pub fn primary(theme: &Theme, _status: Status) -> Style {
51    let palette = theme.extended_palette();
52
53    Style {
54        background: Background::Color(Color {
55            a: 0f32,
56            ..palette.background.base.color
57        }),
58    }
59}