-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(app): ContextDrawer return type for context_drawer method
- Loading branch information
Showing
7 changed files
with
115 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ features = [ | |
"wgpu", | ||
"single-instance", | ||
"multi-window", | ||
"about", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::borrow::Cow; | ||
|
||
use crate::Element; | ||
|
||
pub struct ContextDrawer<'a, Message: Clone + 'static> { | ||
pub title: Option<Cow<'a, str>>, | ||
pub header_actions: Vec<Element<'a, Message>>, | ||
pub header: Option<Element<'a, Message>>, | ||
pub content: Element<'a, Message>, | ||
pub footer: Option<Element<'a, Message>>, | ||
pub on_close: Message, | ||
} | ||
|
||
#[cfg(feature = "about")] | ||
pub fn about<'a, Message: Clone + 'static>( | ||
about: &'a crate::widget::about::About, | ||
on_url_press: impl Fn(String) -> Message, | ||
on_close: Message, | ||
) -> ContextDrawer<'a, Message> { | ||
context_drawer(crate::widget::about(about, on_url_press), on_close) | ||
} | ||
|
||
pub fn context_drawer<'a, Message: Clone + 'static>( | ||
content: impl Into<Element<'a, Message>>, | ||
on_close: Message, | ||
) -> ContextDrawer<'a, Message> { | ||
ContextDrawer { | ||
title: None, | ||
content: content.into(), | ||
header_actions: vec![], | ||
footer: None, | ||
on_close, | ||
header: None, | ||
} | ||
} | ||
|
||
impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { | ||
/// Set a context drawer header title | ||
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self { | ||
self.title = Some(title.into()); | ||
self | ||
} | ||
/// App-specific actions at the start of the context drawer header | ||
pub fn header_actions( | ||
mut self, | ||
header_actions: impl IntoIterator<Item = Element<'a, Message>>, | ||
) -> Self { | ||
self.header_actions = header_actions.into_iter().collect(); | ||
self | ||
} | ||
/// Non-scrolling elements placed below the context drawer title row | ||
pub fn header(mut self, header: impl Into<Element<'a, Message>>) -> Self { | ||
self.header = Some(header.into()); | ||
self | ||
} | ||
|
||
/// Elements placed below the context drawer scrollable | ||
pub fn footer(mut self, footer: impl Into<Element<'a, Message>>) -> Self { | ||
self.footer = Some(footer.into()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright 2023 System76 <[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use std::borrow::Cow; | ||
|
||
use crate::widget::{button, column, container, icon, row, scrollable, text, LayerContainer}; | ||
use crate::{Apply, Element, Renderer, Theme}; | ||
|
||
|
@@ -24,7 +26,7 @@ pub struct ContextDrawer<'a, Message> { | |
|
||
impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { | ||
pub fn new_inner<Drawer>( | ||
title: &'a str, | ||
title: Option<Cow<'a, str>>, | ||
header_actions: Vec<Element<'a, Message>>, | ||
header_opt: Option<Element<'a, Message>>, | ||
footer_opt: Option<Element<'a, Message>>, | ||
|
@@ -44,12 +46,6 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { | |
.. | ||
} = crate::theme::active().cosmic().spacing; | ||
|
||
let title_opt = if title.is_empty() { | ||
None | ||
} else { | ||
Some(text::heading(title).width(Length::FillPortion(1)).center()) | ||
}; | ||
|
||
let horizontal_padding = if max_width < 392.0 { space_s } else { space_l }; | ||
|
||
let header_row = row::with_capacity(3) | ||
|
@@ -60,7 +56,9 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { | |
.spacing(space_xxs) | ||
.width(Length::FillPortion(1)), | ||
) | ||
.push_maybe(title_opt) | ||
.push_maybe( | ||
title.map(|title| text::heading(title).width(Length::FillPortion(1)).center()), | ||
) | ||
.push( | ||
button::text("Close") | ||
.trailing_icon(icon::from_name("go-next-symbolic")) | ||
|
@@ -114,7 +112,7 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> { | |
|
||
/// Creates an empty [`ContextDrawer`]. | ||
pub fn new<Content, Drawer>( | ||
title: &'a str, | ||
title: Option<Cow<'a, str>>, | ||
header_actions: Vec<Element<'a, Message>>, | ||
header_opt: Option<Element<'a, Message>>, | ||
footer_opt: Option<Element<'a, Message>>, | ||
|