pub struct PageManager<'a, D> { /* private fields */ }Expand description
The PageManager is responsible for switching among pages while pages do not know about other pages. The PageManager also dispatches events and updates the current page.
Only a “home” page is mandatory. Any other pages are optional. Startup and Shutdown pages are purely information pages and not activated only by SystemStartup and SystemShutdown events.
h2. Example
let mut input = SomeInput(); // artificial code
let display = SomeDisplay::new(); // artificial code
let home = HomePage::new("!!! This is the home page !!!");
let mut m = PageManager::new(display, Box::new(home));
// Optional startup page has a mandatory lifetime.
let startup = StartupPage::new("Welcome message", 8);
m.register_startup(Box::new(startup));
// Optional Shutdown page has a mandatory lifetime.
let shutdown = ShutdownPage::new("Bye bye message", 10);
m.register_shutdown(Box::new(shutdown));
// Additional pages reachable by next button
// A predefined Information text page with lifetime
let page_one = TextPage::new(
BasicPage::new("First", Some(PageLifetime::new(PageNavigation::Left, 6))),
"First Information Page with 3 seconds lifetime; moving to next page",
);
m.register(Box::new(page_one));
// Enter the event loop
let mut navigation = m.dispatch(PageNavigation::SystemStart).unwrap();
loop {
match input.next() {
None => m.dispatch(navigation),
Some(interaction) => m.dispatch_interaction(interaction),
}
}Implementations§
Source§impl<'a, D> PageManager<'a, D>
impl<'a, D> PageManager<'a, D>
Sourcepub fn new(display: D, home: Box<dyn PageInterface<D> + 'a>) -> Self
pub fn new(display: D, home: Box<dyn PageInterface<D> + 'a>) -> Self
PageManager Constructor
Arguments
display: The display data structure where all output is rendered to The display data structure and the logic attached makes the rendered output appear on some output facility viewable by a human.home: The “home” page. There must be at least one page. Other pages are added by register_* calls.
Sourcepub fn update(&mut self) -> Result<(), PageError>
pub fn update(&mut self) -> Result<(), PageError>
Update the content of the active page on the display
Potentially initiate a page change before displaying, since the update responsibility is the responsibility of the specific active page
Sourcepub fn register(&mut self, page: Box<dyn PageInterface<D> + 'a>)
pub fn register(&mut self, page: Box<dyn PageInterface<D> + 'a>)
Register a new page
The page is registered in the “left” direction of the active page. The registered page will be the new active page.
Arguments
page- The page to be registered and activated.
Sourcepub fn register_sub(&mut self, page: Box<dyn PageInterface<D> + 'a>)
pub fn register_sub(&mut self, page: Box<dyn PageInterface<D> + 'a>)
Register a new sub page
The page is registered in the “down” direction of the active page. The registered page will be the new active page.
Arguments
page: - The page to be registered and activated.
Sourcepub fn register_startup(&mut self, page: Box<dyn PageInterface<D> + 'a>)
pub fn register_startup(&mut self, page: Box<dyn PageInterface<D> + 'a>)
Register a startup page
There can be just one startup page. Multiple calls to this function overwrite the previously set startup page.
Arguments
page: - The page that should serve for startup.
Sourcepub fn register_shutdown(&mut self, page: Box<dyn PageInterface<D> + 'a>)
pub fn register_shutdown(&mut self, page: Box<dyn PageInterface<D> + 'a>)
Register a shutdown page
There can be just one shutdown page. Multiple calls to this function overwrite the previously set shutdown page.
Arguments
page: - The page that should serve for startup.
Sourcepub fn dispatch_interaction(
&mut self,
interaction: Interaction,
) -> Result<PageNavigation, PageError>
pub fn dispatch_interaction( &mut self, interaction: Interaction, ) -> Result<PageNavigation, PageError>
Dispatch an interaction event
Let the active page process the interaction event and eventually turn The interaction event into a executed page navigation
Arguments
interaction: - The interaction event to dispatch
Sourcepub fn dispatch(
&mut self,
navigation: PageNavigation,
) -> Result<PageNavigation, PageError>
pub fn dispatch( &mut self, navigation: PageNavigation, ) -> Result<PageNavigation, PageError>
Dispatch a navigation event
The event can cause a change of the active page or lead to an update of the active page content.
Arguments
navigation: - The navigation event to dispatch