feat(app): footer widget

This commit is contained in:
Jeremy Soller 2024-10-10 11:01:05 -06:00 committed by Michael Murphy
parent 9f11239ea5
commit 100f75f88e
2 changed files with 46 additions and 29 deletions

View file

@ -421,6 +421,11 @@ where
None None
} }
/// Displays a footer at the bottom of the application window when `Some`.
fn footer(&self) -> Option<Element<Self::Message>> {
None
}
/// Attaches elements to the start section of the header. /// Attaches elements to the start section of the header.
fn header_start(&self) -> Vec<Element<Self::Message>> { fn header_start(&self) -> Vec<Element<Self::Message>> {
Vec::new() Vec::new()
@ -705,16 +710,10 @@ impl<App: Application> ApplicationExt for App {
widgets.push(main_content); widgets.push(main_content);
if let Some(context) = self.context_drawer() { if let Some(context) = self.context_drawer() {
widgets.push( widgets.push(
context_drawer( crate::widget::ContextDrawer::new_inner(
&core.window.context_title, &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), context.map(Message::App),
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
context_width, context_width,
) )
.apply(|drawer| { .apply(|drawer| {
@ -733,8 +732,12 @@ impl<App: Application> ApplicationExt for App {
widgets 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 { let content: Element<_> = if core.window.content_container {
content_row content_col
.apply(crate::widget::container) .apply(crate::widget::container)
.padding([0, 8, 8, 8]) .padding([0, 8, 8, 8])
.width(iced::Length::Fill) .width(iced::Length::Fill)
@ -743,7 +746,7 @@ impl<App: Application> ApplicationExt for App {
.apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_content_container"))) .apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_content_container")))
.into() .into()
} else { } else {
content_row.into() content_col.into()
}; };
let view_column = crate::widget::column::with_capacity(2) let view_column = crate::widget::column::with_capacity(2)

View file

@ -27,16 +27,13 @@ pub struct ContextDrawer<'a, Message> {
} }
impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
/// Creates an empty [`ContextDrawer`]. pub fn new_inner<Drawer>(
pub fn new<Content, Drawer>(
header: &'a str, header: &'a str,
content: Content,
drawer: Drawer, drawer: Drawer,
on_close: Message, on_close: Message,
max_width: f32, max_width: f32,
) -> Self ) -> Element<'a, Message>
where where
Content: Into<Element<'a, Message>>,
Drawer: Into<Element<'a, Message>>, Drawer: Into<Element<'a, Message>>,
{ {
let header = row::with_capacity(3) let header = row::with_capacity(3)
@ -82,23 +79,40 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
.width(Length::Shrink), .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<Content, Drawer>(
header: &'a str,
content: Content,
drawer: Drawer,
on_close: Message,
max_width: f32,
) -> Self
where
Content: Into<Element<'a, Message>>,
Drawer: Into<Element<'a, Message>>,
{
let drawer = Self::new_inner(header, drawer, on_close, max_width);
ContextDrawer { ContextDrawer {
id: None, id: None,
content: content.into(), content: content.into(),
// XXX new limits do not exactly handle the max width well for containers drawer,
// 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(),
on_close: None, on_close: None,
} }
} }