-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated Context Menu to newest Iced master branch
- Loading branch information
genusistimelord
committed
Jun 27, 2024
1 parent
bb2e27c
commit 961c9a9
Showing
8 changed files
with
98 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,59 @@ | ||
//! Use a badge for color highlighting important information. | ||
//! | ||
//! *This API requires the following crate features to be activated: badge* | ||
use std::rc::Rc; | ||
|
||
use super::{Status, StyleFn}; | ||
use iced::{Background, Color, Theme}; | ||
|
||
/// The appearance of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
/// The style of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct Appearance { | ||
pub struct Style { | ||
/// The background of the [`ContextMenu`](crate::widgets::ContextMenu). | ||
/// | ||
/// This is used to color the backdrop of the modal. | ||
pub background: Background, | ||
} | ||
|
||
impl Default for Appearance { | ||
impl Default for Style { | ||
fn default() -> Self { | ||
Self { | ||
background: Background::Color([0.87, 0.87, 0.87, 0.30].into()), | ||
} | ||
} | ||
} | ||
|
||
/// The appearance of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
pub trait StyleSheet { | ||
/// The Catalog of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
pub trait Catalog { | ||
///Style for the trait to use. | ||
type Style: Default + Clone; | ||
/// The normal appearance of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
fn active(&self, style: &Self::Style) -> Appearance; | ||
} | ||
type Class<'a>; | ||
|
||
/// The default appearance of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
#[derive(Clone, Default)] | ||
#[allow(missing_docs, clippy::missing_docs_in_private_items)] | ||
pub enum ContextMenuStyle { | ||
#[default] | ||
Default, | ||
Custom(Rc<dyn StyleSheet<Style = Theme>>), | ||
/// The default class produced by the [`Catalog`]. | ||
fn default<'a>() -> Self::Class<'a>; | ||
|
||
/// The [`Style`] of a class with the given status. | ||
fn style(&self, class: &Self::Class<'_>, status: Status) -> Style; | ||
} | ||
|
||
impl ContextMenuStyle { | ||
/// Creates a custom [`ContextMenuStyle`] style variant. | ||
pub fn custom(style_sheet: impl StyleSheet<Style = Theme> + 'static) -> Self { | ||
Self::Custom(Rc::new(style_sheet)) | ||
impl Catalog for Theme { | ||
type Class<'a> = StyleFn<'a, Self, Style>; | ||
|
||
fn default<'a>() -> Self::Class<'a> { | ||
Box::new(primary) | ||
} | ||
} | ||
|
||
impl StyleSheet for Theme { | ||
type Style = ContextMenuStyle; | ||
fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { | ||
class(self, status) | ||
} | ||
} | ||
|
||
fn active(&self, _style: &Self::Style) -> Appearance { | ||
let palette = self.extended_palette(); | ||
/// The primary theme of a [`ContextMenu`](crate::widgets::ContextMenu). | ||
#[must_use] | ||
pub fn primary(theme: &Theme, _status: Status) -> Style { | ||
let palette = theme.extended_palette(); | ||
|
||
Appearance { | ||
background: Color { | ||
a: 0f32, | ||
..palette.background.base.color | ||
} | ||
.into(), | ||
} | ||
Style { | ||
background: Background::Color(Color { | ||
a: 0f32, | ||
..palette.background.base.color | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.