diff --git a/Cargo.lock b/Cargo.lock index 12ed69ae..2106e036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,6 +606,14 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "context_menu" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "core-foundation" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index ef3f779e..da16acb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,8 @@ default = [ "slide_bar", "wrap", "selection_list", - #"quad", - #"context_menu", + "quad", + "context_menu", "spinner", "drop_down", #"menu", @@ -89,7 +89,7 @@ members = [ "examples/sliderbar", "examples/wrap", "examples/selection_list", - #"examples/context_menu", + "examples/context_menu", "examples/spinner", "examples/WidgetIDReturn", "examples/drop_down", diff --git a/examples/context_menu/src/main.rs b/examples/context_menu/src/main.rs index 731d7750..eb7e7dbc 100644 --- a/examples/context_menu/src/main.rs +++ b/examples/context_menu/src/main.rs @@ -1,12 +1,17 @@ use iced::{ widget::{column, Button, Container, Row, Text}, - Alignment, Element, Sandbox, Settings, + Alignment, Element, }; use iced_aw::ContextMenu; fn main() -> iced::Result { - ContextMenuExample::run(Settings::default()) + iced::application( + "ContextMenu example", + ContextMenuExample::update, + ContextMenuExample::view, + ) + .run() } #[derive(Clone, Debug)] @@ -23,22 +28,12 @@ struct ContextMenuExample { last_message: Option, } -impl Sandbox for ContextMenuExample { - type Message = Message; - - fn new() -> Self { - Self::default() - } - - fn title(&self) -> String { - String::from("ContextMenu example") - } - - fn update(&mut self, message: Self::Message) { +impl ContextMenuExample { + fn update(&mut self, message: Message) { self.last_message = Some(message); } - fn view(&self) -> Element<'_, Self::Message> { + fn view(&self) -> Element<'_, Message> { let underlay = Container::new( Row::new() .spacing(10) diff --git a/src/lib.rs b/src/lib.rs index b9a01e5b..d0d57860 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -138,9 +138,7 @@ mod platform { #[doc(no_inline)] #[cfg(feature = "context_menu")] - pub use { - crate::style::ContextMenuStyle, crate::widgets::context_menu, context_menu::ContextMenu, - }; + pub use {crate::widgets::context_menu, context_menu::ContextMenu}; #[doc(no_inline)] #[cfg(feature = "drop_down")] diff --git a/src/style.rs b/src/style.rs index 90bec0f7..5a53c257 100644 --- a/src/style.rs +++ b/src/style.rs @@ -37,5 +37,3 @@ pub use menu_bar::MenuBarStyle; #[cfg(feature = "context_menu")] pub mod context_menu; -#[cfg(feature = "context_menu")] -pub use context_menu::ContextMenuStyle; diff --git a/src/style/context_menu.rs b/src/style/context_menu.rs index fbfb90c1..f84e7dc0 100644 --- a/src/style/context_menu.rs +++ b/src/style/context_menu.rs @@ -1,20 +1,19 @@ //! 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()), @@ -22,42 +21,39 @@ impl Default for Appearance { } } -/// 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>), + /// 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