PageManager

Struct PageManager 

Source
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>

Source

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.
Source

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

Source

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.
Source

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.
Source

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.
Source

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.
Source

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
Source

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
Source§

impl<'a, D> PageManager<'a, D>

Source

pub fn sub_iter(&self) -> SubPageIterator<'_, Box<dyn PageInterface<D> + 'a>>

Trait Implementations§

Source§

impl<'a, D> Drop for PageManager<'a, D>

Source§

fn drop(&mut self)

TODO - update to remove everything

Auto Trait Implementations§

§

impl<'a, D> Freeze for PageManager<'a, D>
where D: Freeze,

§

impl<'a, D> !RefUnwindSafe for PageManager<'a, D>

§

impl<'a, D> !Send for PageManager<'a, D>

§

impl<'a, D> !Sync for PageManager<'a, D>

§

impl<'a, D> Unpin for PageManager<'a, D>
where D: Unpin,

§

impl<'a, D> !UnwindSafe for PageManager<'a, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.