From 100f75f88edc5b602e29587fd6698dbf0038901d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 10 Oct 2024 11:01:05 -0600 Subject: [PATCH] feat(app): footer widget --- src/app/mod.rs | 23 +++++++------ src/widget/context_drawer/widget.rs | 52 ++++++++++++++++++----------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 21b47809..e826900b 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -421,6 +421,11 @@ where None } + /// Displays a footer at the bottom of the application window when `Some`. + fn footer(&self) -> Option> { + None + } + /// Attaches elements to the start section of the header. fn header_start(&self) -> Vec> { Vec::new() @@ -705,16 +710,10 @@ impl ApplicationExt for App { widgets.push(main_content); if let Some(context) = self.context_drawer() { widgets.push( - context_drawer( + crate::widget::ContextDrawer::new_inner( &core.window.context_title, - Message::Cosmic(cosmic::Message::ContextDrawer(false)), - //TODO: this is a hack to allow toggling overlay - horizontal_space( - //TODO: this width must be synced with the context drawer width - // Manual spacing must be used due to state workarounds below - Length::Fixed(context_width + 8.0), - ), context.map(Message::App), + Message::Cosmic(cosmic::Message::ContextDrawer(false)), context_width, ) .apply(|drawer| { @@ -733,8 +732,12 @@ impl ApplicationExt for App { widgets }); + let content_col = crate::widget::column::with_capacity(2) + .spacing(8) + .push(content_row) + .push_maybe(self.footer().map(|footer| footer.map(Message::App))); let content: Element<_> = if core.window.content_container { - content_row + content_col .apply(crate::widget::container) .padding([0, 8, 8, 8]) .width(iced::Length::Fill) @@ -743,7 +746,7 @@ impl ApplicationExt for App { .apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_content_container"))) .into() } else { - content_row.into() + content_col.into() }; let view_column = crate::widget::column::with_capacity(2) diff --git a/src/widget/context_drawer/widget.rs b/src/widget/context_drawer/widget.rs index 98056266..417885bc 100644 --- a/src/widget/context_drawer/widget.rs +++ b/src/widget/context_drawer/widget.rs @@ -27,16 +27,13 @@ pub struct ContextDrawer<'a, Message> { } impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { - /// Creates an empty [`ContextDrawer`]. - pub fn new( + pub fn new_inner( header: &'a str, - content: Content, drawer: Drawer, on_close: Message, max_width: f32, - ) -> Self + ) -> Element<'a, Message> where - Content: Into>, Drawer: Into>, { let header = row::with_capacity(3) @@ -82,23 +79,40 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { .width(Length::Shrink), ); + // XXX new limits do not exactly handle the max width well for containers + // XXX this is a hack to get around that + container( + LayerContainer::new(pane) + .layer(cosmic_theme::Layer::Primary) + .style(crate::style::Container::ContextDrawer) + .width(Length::Fill) + .height(Length::Fill) + .max_width(max_width), + ) + .width(Length::Fill) + .height(Length::Fill) + .align_x(alignment::Horizontal::Right) + .into() + } + + /// Creates an empty [`ContextDrawer`]. + pub fn new( + header: &'a str, + content: Content, + drawer: Drawer, + on_close: Message, + max_width: f32, + ) -> Self + where + Content: Into>, + Drawer: Into>, + { + let drawer = Self::new_inner(header, drawer, on_close, max_width); + ContextDrawer { id: None, content: content.into(), - // XXX new limits do not exactly handle the max width well for containers - // XXX this is a hack to get around that - drawer: container( - LayerContainer::new(pane) - .layer(cosmic_theme::Layer::Primary) - .style(crate::style::Container::ContextDrawer) - .width(Length::Fill) - .height(Length::Fill) - .max_width(max_width), - ) - .width(Length::Fill) - .height(Length::Fill) - .align_x(alignment::Horizontal::Right) - .into(), + drawer, on_close: None, } }