feat: ContextDrawer struct in Application trait
This commit is contained in:
parent
3dcc47d6a7
commit
62c4282383
7 changed files with 121 additions and 84 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
//! Application API example
|
||||
|
||||
use cosmic::app::context_drawer::{context_drawer, ContextDrawer};
|
||||
use cosmic::app::{Core, Settings, Task};
|
||||
use cosmic::iced::widget::column;
|
||||
use cosmic::iced_core::Size;
|
||||
|
|
@ -35,6 +36,7 @@ pub struct App {
|
|||
core: Core,
|
||||
nav_model: nav_bar::Model,
|
||||
about: About,
|
||||
show_about: bool,
|
||||
}
|
||||
|
||||
/// Implement [`cosmic::Application`] to integrate with COSMIC.
|
||||
|
|
@ -80,6 +82,7 @@ impl cosmic::Application for App {
|
|||
core,
|
||||
nav_model,
|
||||
about,
|
||||
show_about: false,
|
||||
};
|
||||
|
||||
let command = app.update_title();
|
||||
|
|
@ -98,20 +101,18 @@ impl cosmic::Application for App {
|
|||
self.update_title()
|
||||
}
|
||||
|
||||
fn context_drawer(&self) -> Option<Element<Self::Message>> {
|
||||
if !self.core.window.show_context {
|
||||
return None;
|
||||
fn context_drawer(&self) -> Option<ContextDrawer<Self::Message>> {
|
||||
match self.show_about {
|
||||
true => Some(context_drawer(widget::about(&self.about, Message::Open), Message::ToggleAbout)),
|
||||
false => None,
|
||||
}
|
||||
|
||||
Some(widget::about(&self.about, Message::Open))
|
||||
}
|
||||
|
||||
/// Handle application events here.
|
||||
fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
|
||||
match message {
|
||||
Message::ToggleAbout => {
|
||||
self.core.window.show_context = !self.core.window.show_context;
|
||||
self.core.set_show_context(self.core.window.show_context)
|
||||
self.show_about = !self.show_about;
|
||||
}
|
||||
Message::Open(url) => match open::that_detached(url) {
|
||||
Ok(_) => (),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue