feat!(app): ContextDrawer return type for context_drawer method

This commit is contained in:
wiiznokes 2024-11-16 03:38:29 +01:00 committed by GitHub
parent aaadf7199e
commit a355a049d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 68 deletions

View file

@ -24,4 +24,5 @@ features = [
"wgpu",
"single-instance",
"multi-window",
"about",
]

View file

@ -3,6 +3,7 @@
//! Application API example
use cosmic::app::context_drawer::{self, 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,17 @@ impl cosmic::Application for App {
self.update_title()
}
fn context_drawer(&self) -> Option<Element<Self::Message>> {
if !self.core.window.show_context {
return None;
}
Some(widget::about(&self.about, Message::Open))
fn context_drawer(&self) -> Option<ContextDrawer<Self::Message>> {
self.show_about
.then(|| context_drawer::about(&self.about, Message::Open, Message::ToggleAbout))
}
/// 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.set_show_context(!self.core.window.show_context);
self.show_about = !self.show_about;
}
Message::Open(url) => match open::that_detached(url) {
Ok(_) => (),