diff --git a/src/app/core.rs b/src/app/core.rs index 92b68dd6..8655be8f 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -15,11 +15,14 @@ pub struct NavBar { #[allow(clippy::struct_excessive_bools)] #[derive(Clone)] pub struct Window { - /// Label to as title in headerbar. + /// Label to display as context drawer title. + pub context_title: String, + /// Label to display as header bar title. pub header_title: String, pub use_template: bool, pub can_fullscreen: bool, pub sharp_corners: bool, + pub show_context: bool, pub show_headerbar: bool, pub show_window_menu: bool, pub show_maximize: bool, @@ -68,10 +71,12 @@ impl Default for Core { title: String::new(), system_theme: crate::theme::active(), window: Window { + context_title: String::new(), header_title: String::new(), use_template: true, can_fullscreen: false, sharp_corners: false, + show_context: false, show_headerbar: true, show_maximize: true, show_minimize: true, diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index d30209a9..e1cc257f 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -24,6 +24,8 @@ pub enum Message { AppThemeChange(Theme), /// Requests to close the window. Close, + /// Closes or shows the context drawer. + ContextDrawer(bool), /// Requests to drag the window. Drag, /// Keyboard shortcuts managed by libcosmic. @@ -166,6 +168,7 @@ where if id != window::Id(0) { return self.app.view_window(id).map(super::Message::App); } + if self.app.core().window.use_template { self.app.view_main() } else { @@ -242,13 +245,12 @@ impl Cosmic { keyboard_nav::Message::Fullscreen => return command::toggle_fullscreen(), }, - Message::Drag => return command::drag(), - - Message::Close => { - self.app.on_app_exit(); - return self.close(); + Message::ContextDrawer(show) => { + self.app.core_mut().window.show_context = show; } + Message::Drag => return command::drag(), + Message::Minimize => return command::minimize(), Message::Maximize => { @@ -303,6 +305,11 @@ impl Cosmic { Message::ScaleFactor(factor) => { self.app.core_mut().set_scale_factor(factor); } + + Message::Close => { + self.app.on_app_exit(); + return self.close(); + } } iced::Command::none() diff --git a/src/app/mod.rs b/src/app/mod.rs index 852d6978..b4af3177 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -41,7 +41,7 @@ pub use self::core::Core; pub use self::settings::Settings; use crate::prelude::*; use crate::theme::THEME; -use crate::widget::nav_bar; +use crate::widget::{context_drawer, nav_bar}; use apply::Apply; use iced::Subscription; use iced::{window, Application as IcedApplication}; @@ -62,6 +62,7 @@ pub fn run(settings: Settings, flags: App::Flags) -> iced::Res core.set_scale_factor(settings.scale_factor); core.set_window_width(settings.size.0); core.set_window_height(settings.size.1); + THEME.with(move |t| { let mut cosmic_theme = t.borrow_mut(); cosmic_theme.set_theme(settings.theme.theme_type); @@ -139,6 +140,11 @@ where /// Creates the application, and optionally emits command on initialize. fn init(core: Core, flags: Self::Flags) -> (Self, iced::Command>); + /// Displays a context drawer on the side of the application window when `Some`. + fn context_drawer(&self) -> Option> { + None + } + /// Attaches elements to the start section of the header. fn header_start(&self) -> Vec> { Vec::new() @@ -332,7 +338,17 @@ impl ApplicationExt for App { if self.nav_model().is_none() || core.show_content() { let main_content = self.view().debug(core.debug).map(Message::App); - widgets.push(main_content); + widgets.push(if let Some(context) = self.context_drawer() { + context_drawer( + &core.window.context_title, + Message::Cosmic(cosmic::Message::ContextDrawer(false)), + main_content, + context.map(Message::App), + ) + .into() + } else { + main_content + }); } widgets