diff --git a/src/app/context_drawer.rs b/src/app/context_drawer.rs index bb68124..5d15d7b 100644 --- a/src/app/context_drawer.rs +++ b/src/app/context_drawer.rs @@ -62,4 +62,22 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { self.footer = Some(footer.into()); self } + + pub fn map( + mut self, + on_message: fn(Message) -> Out, + ) -> ContextDrawer<'a, Out> { + ContextDrawer { + title: self.title, + content: self.content.map(on_message), + header: self.header.map(|el| el.map(on_message)), + footer: self.footer.map(|el| el.map(on_message)), + on_close: on_message(self.on_close), + header_actions: self + .header_actions + .into_iter() + .map(|el| el.map(on_message)) + .collect(), + } + } } diff --git a/src/app/mod.rs b/src/app/mod.rs index 4cb144a..3135505 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -10,6 +10,7 @@ mod action; pub use action::Action; use cosmic_config::CosmicConfigEntry; pub mod context_drawer; +pub use context_drawer::{ContextDrawer, context_drawer}; pub mod cosmic; #[cfg(all(feature = "winit", feature = "multi-window"))] pub(crate) mod multi_window; @@ -22,7 +23,6 @@ use crate::prelude::*; use crate::theme::THEME; use crate::widget::{container, horizontal_space, id_container, menu, nav_bar, popover}; use apply::Apply; -use context_drawer::ContextDrawer; use iced::window; use iced::{Length, Subscription}; pub use settings::Settings; diff --git a/src/widget/context_drawer/widget.rs b/src/widget/context_drawer/widget.rs index fd752ec..7f493da 100644 --- a/src/widget/context_drawer/widget.rs +++ b/src/widget/context_drawer/widget.rs @@ -164,12 +164,27 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { } /// Sets the [`Id`] of the [`ContextDrawer`]. + #[inline] pub fn id(mut self, id: iced_core::widget::Id) -> Self { self.id = Some(id); self } - // Optionally assigns message to `on_close` event. + /// Map the message type of the context drawer to another + #[inline] + pub fn map( + mut self, + on_message: fn(Message) -> Out, + ) -> ContextDrawer<'a, Out> { + ContextDrawer { + id: self.id, + content: self.content.map(on_message), + drawer: self.drawer.map(on_message), + on_close: self.on_close.map(on_message), + } + } + + /// Optionally assigns message to `on_close` event. #[inline] pub fn on_close_maybe(mut self, message: Option) -> Self { self.on_close = message;