Skip to main content

ShellApp

Trait ShellApp 

Source
pub trait ShellApp<D> {
    // Required method
    fn screen_ui(&mut self, ui: &mut Ui, screen: D, side: &mut Side);

    // Provided methods
    fn side_ui(&mut self, ui: &mut Ui, screen: D, side: &mut Side) { ... }
    fn foot_ui(&mut self, ui: &mut Ui) -> Option<D> { ... }
    fn status_ui(&mut self, ui: &mut Ui) { ... }
    fn action(&mut self, id: &'static str, side: &mut Side) { ... }
}
Expand description

An app as the shell draws it, each frame, with Shell::show: its screens, its side pane, its foot and status, and what its actions do. The shell calls these in turn, each with the app’s &mut self, so a screen and the side pane share the app’s state freely.

#[derive(Clone, Copy, PartialEq)]
enum Screen { Entries, Settings }

struct Journal { draft: Option<String> }

impl ShellApp<Screen> for Journal {
    fn screen_ui(&mut self, ui: &mut egui::Ui, screen: Screen, side: &mut Side) {
        egui::CentralPanel::default().show(ui, |ui| ui.label("…"));
    }

    fn side_ui(&mut self, ui: &mut egui::Ui, screen: Screen, side: &mut Side) {
        match &mut self.draft {
            Some(text) => {
                ui.text_edit_multiline(text);
                if ui.button("Save").clicked() {
                    self.draft = None;
                    side.close();
                }
            }
            None => { ui.weak("Nothing selected"); }
        }
    }

    fn action(&mut self, id: &'static str, side: &mut Side) {
        if id == "new-entry" {
            self.draft = Some(String::new());
            side.open();
        }
    }
}

let mut shell = Shell::from_items(vec![
    Action::new("new-entry", icons::plus(), "new-entry").into(),
    Destination::new(Screen::Entries, icons::file_text(), "entries").into(),
])
.with_footer(vec![Destination::new(Screen::Settings, icons::settings(), "settings")]);
let mut journal = Journal { draft: None };
// Every frame:
shell.show(ui, &mut journal);

Required Methods§

Source

fn screen_ui(&mut self, ui: &mut Ui, screen: D, side: &mut Side)

Draw screen into what the frame leaves of ui, as it would at the root: its own panels, then a CentralPanel. Through side it opens the side pane — on a card, or on a phone in the screen’s place — when the person picks an item.

Provided Methods§

Source

fn side_ui(&mut self, ui: &mut Ui, screen: D, side: &mut Side)

Fill the side pane (no panels of its own): the new entry being written, else screen’s item, else a word that there is none. Through side it closes the pane once the entry is saved or dropped.

Source

fn foot_ui(&mut self, ui: &mut Ui) -> Option<D>

Draw the foot — a status dot, say — at the rail’s foot, at the bottom bar’s end, or on the status bar; a destination it returns is opened.

Source

fn status_ui(&mut self, ui: &mut Ui)

Fill the status bar from the left, when wide.

Source

fn action(&mut self, id: &'static str, side: &mut Side)

Do what the Action id names: it was clicked on the rail or in the More menu. A “new entry” begins the entry and opens it in the side pane through side.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§