feat: inner-app dialog API support

This commit is contained in:
Michael Aaron Murphy 2024-03-27 16:01:35 +01:00 committed by Michael Murphy
parent 43b478ee68
commit 29f0489c8a
3 changed files with 23 additions and 2 deletions

View file

@ -136,13 +136,20 @@ impl<Message: 'static> Binder<Message> {
page.downcast_ref::<P>()
}
/// Obtain a reference to a page by its type ID.
/// Create a context drawer for the given page.
#[must_use]
pub fn context_drawer(&self, id: crate::Entity) -> Option<Element<'_, Message>> {
let page = self.page.get(id)?;
page.context_drawer()
}
/// Create a dialog for the given page.
#[must_use]
pub fn dialog(&self, id: crate::Entity) -> Option<Element<'_, Message>> {
let page = self.page.get(id)?;
page.dialog()
}
/// Obtain a reference to a page by its type ID.
#[must_use]
pub fn page_mut<P: Page<Message>>(&mut self) -> Option<&mut P> {

View file

@ -28,6 +28,7 @@ pub trait Page<Message: 'static>: Downcast {
/// Information about the page
fn info(&self) -> Info;
/// Initialize the sections used by this page.
#[must_use]
fn content(
&self,
@ -36,20 +37,28 @@ pub trait Page<Message: 'static>: Downcast {
None
}
/// Display a context drawer for the page.
#[must_use]
fn context_drawer(&self) -> Option<Element<'_, Message>> {
None
}
/// Display an inner app dialog for the page.
fn dialog(&self) -> Option<Element<'_, Message>> {
None
}
/// Response from a file chooser dialog request.
fn file_chooser(&mut self, _selected: Vec<url::Url>) -> Command<Message> {
Command::none()
}
/// Alter the contents of the page's header view.
fn header_view(&self) -> Option<Element<'_, Message>> {
None
}
/// Reload page metadata via a Command.
#[must_use]
#[allow(unused)]
fn reload(&mut self, page: crate::Entity) -> Command<Message> {