improv(context_drawer): move title out of header row
This moves the title below the header row containing actions and the close button, allowing more room for the title and actions. Also makes actions an `Element` instead of a `Vec<Element>`, providing more flexibility for developers.
This commit is contained in:
parent
2299b46862
commit
b6c6d1cb7b
4 changed files with 60 additions and 91 deletions
|
|
@ -7,7 +7,7 @@ use crate::Element;
|
|||
|
||||
pub struct ContextDrawer<'a, Message: Clone + 'static> {
|
||||
pub title: Option<Cow<'a, str>>,
|
||||
pub header_actions: Vec<Element<'a, Message>>,
|
||||
pub actions: Option<Element<'a, Message>>,
|
||||
pub header: Option<Element<'a, Message>>,
|
||||
pub content: Element<'a, Message>,
|
||||
pub footer: Option<Element<'a, Message>>,
|
||||
|
|
@ -29,29 +29,28 @@ pub fn context_drawer<'a, Message: Clone + 'static>(
|
|||
) -> ContextDrawer<'a, Message> {
|
||||
ContextDrawer {
|
||||
title: None,
|
||||
actions: None,
|
||||
header: 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
|
||||
/// Set a context drawer 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();
|
||||
|
||||
/// App-specific actions at the top-left corner of the context drawer
|
||||
pub fn actions(mut self, actions: impl Into<Element<'a, Message>>) -> Self {
|
||||
self.actions = Some(actions.into());
|
||||
self
|
||||
}
|
||||
/// Non-scrolling elements placed below the context drawer title row
|
||||
|
||||
/// Elements placed above the context drawer scrollable
|
||||
pub fn header(mut self, header: impl Into<Element<'a, Message>>) -> Self {
|
||||
self.header = Some(header.into());
|
||||
self
|
||||
|
|
@ -64,20 +63,16 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
|
|||
}
|
||||
|
||||
pub fn map<Out: Clone + 'static>(
|
||||
mut self,
|
||||
self,
|
||||
on_message: fn(Message) -> Out,
|
||||
) -> ContextDrawer<'a, Out> {
|
||||
ContextDrawer {
|
||||
title: self.title,
|
||||
content: self.content.map(on_message),
|
||||
actions: self.actions.map(|el| el.map(on_message)),
|
||||
header: self.header.map(|el| el.map(on_message)),
|
||||
content: self.content.map(on_message),
|
||||
footer: self.footer.map(|el| el.map(on_message)),
|
||||
on_close: on_message(self.on_close),
|
||||
header_actions: self
|
||||
.header_actions
|
||||
.into_iter()
|
||||
.map(|el| el.map(on_message))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -603,7 +603,7 @@ impl<App: Application> ApplicationExt for App {
|
|||
widgets.push(
|
||||
crate::widget::context_drawer(
|
||||
context.title,
|
||||
context.header_actions,
|
||||
context.actions,
|
||||
context.header,
|
||||
context.footer,
|
||||
context.on_close,
|
||||
|
|
@ -640,7 +640,7 @@ impl<App: Application> ApplicationExt for App {
|
|||
widgets.push(
|
||||
crate::widget::ContextDrawer::new_inner(
|
||||
context.title,
|
||||
context.header_actions,
|
||||
context.actions,
|
||||
context.header,
|
||||
context.footer,
|
||||
context.content,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue