Skip to main content

Shell

Struct Shell 

Source
pub struct Shell<D> { /* private fields */ }
Expand description

The window frame. Hold one as the app’s root; call show every frame with the app, a ShellApp.

Labels are message ids: each frame the hover text is looked up in the language installed (see i18n), so a language switch shows on the next frame.

The shell keeps clear of the system’s bars and notches (egui’s safe area, which iOS fills): the rail, the bar’s buttons and the screens stay inside it, and the bottom bar’s fill runs on under the home indicator, as a phone’s tab bar does. Give it the window’s whole root ui; the app adds no margin of its own. If the app does keep ui clear of them itself, the shell sees that and adds nothing, so the margin is never doubled. On Android, window::run_android keeps the app’s ui clear of the bars and the keyboard already.

The side pane is beside every screen: a right column when wide, which a button at the status bar’s right end hides; a card over the screen when it is hidden or there is no room; on a phone, the screen’s place, under a way back. Whether the column is on is kept with the rail’s order, in the store if one is attached.

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

struct Gallery;

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

    fn action(&mut self, id: &'static str, side: &mut Side) {
        if id == "import" {
            // …
        }
    }
}

let mut shell = Shell::from_items(vec![
    Action::new("import", icons::plus(), "import").into(),
    // The app's own Lucide SVGs: `egui::include_image!("../assets/icons/images.svg")`.
    Destination::new(Screen::Gallery, icons::folder(), "gallery").into(),
    Destination::new(Screen::Albums, icons::folder(), "albums").into(),
])
.with_footer(vec![Destination::new(Screen::Settings, icons::settings(), "settings")]);
// Every frame:
shell.show(ui, &mut Gallery);

Implementations§

Source§

impl<D: Copy + PartialEq> Shell<D>

Source

pub fn new(destinations: Vec<Destination<D>>) -> Shell<D>

A frame with destinations on the rail, the first one open.

Source

pub fn from_items(items: Vec<RailItem<D>>) -> Shell<D>

A frame with items — screens and actions — on the rail in this order, the first screen open.

Source

pub fn with_actions(self, actions: Vec<Action>) -> Shell<D>

Put actions on the rail after the items already there. To put one first, give the items to from_items instead.

Put footer at the rail’s foot (at the bottom bar’s end): where an app puts Settings. With no other destinations, the first of these is open. When some items are left off the rail, the footer moves into the More menu, which takes its place.

Source

pub fn with_rail_order(self, order: &RailOrder) -> Shell<D>

Lay the rail out in order, as set_rail_order.

Source

pub fn rail_order(&self) -> RailOrder

The order the rail’s items are in, and which of them it leaves to the menu.

Source

pub fn set_rail_order(&mut self, order: &RailOrder)

Lay the rail out in order. With the serde feature and a store attached, the order saved there replaces this on the first frame.

Source

pub fn take_action(&mut self) -> Option<&'static str>

👎Deprecated since 0.3.0:

draw with show, which hands the action to ShellApp::action

The Action clicked in the last ui, once: call it after ui every frame and do what it names.

Source

pub fn current(&self) -> Option<D>

The destination that is open; None only when there are none.

Source

pub fn open(&mut self, id: D)

Open the destination id.

Source

pub fn with_side_pane(self) -> Shell<D>

👎Deprecated since 0.3.0:

every shell has a side pane

The side pane is always there now.

Source

pub fn with_status_bar(self) -> Shell<D>

👎Deprecated since 0.3.0:

show always draws a status bar, wide

show always draws the status bar, wide, now.

Source

pub fn show(&mut self, ui: &mut Ui, app: &mut impl ShellApp<D>)

Render app into the window’s root ui: the rail, the open screen (ShellApp::screen_ui) and the side pane beside it (ShellApp::side_ui), and, wide, the status bar (ShellApp::status_ui, then ShellApp::foot_ui and the side column’s toggle at its right end); then hand an action clicked to ShellApp::action. The first frame installs the default theme and language if the app has not installed them, and takes the rail’s order and the side column from the store if one is attached.

Source

pub fn ui(&mut self, ui: &mut Ui, content: impl FnOnce(&mut Ui, D))

👎Deprecated since 0.3.0:

implement ShellApp and draw with show

Render into the window’s root ui. content draws the open destination into what the frame leaves of ui, as it would at the root: its own panels, then a CentralPanel. An action clicked waits for take_action. The first frame installs the default theme and language if the app has not installed them, and takes the rail’s order from the store if one is attached. An app with a side pane or state shared by its screens implements ShellApp and calls show. There is no side pane here.

Source

pub fn ui_with_foot( &mut self, ui: &mut Ui, foot: impl FnOnce(&mut Ui) -> Option<D>, content: impl FnOnce(&mut Ui, D), )

👎Deprecated since 0.3.0:

implement ShellApp (foot_ui) and draw with show

As ui, with foot drawn beside the footer — a status dot, say. A destination foot returns is opened, and drawn this frame.

Source

pub fn ui_with_status( &mut self, ui: &mut Ui, foot: impl FnOnce(&mut Ui) -> Option<D>, status: impl FnOnce(&mut Ui), content: impl FnOnce(&mut Ui, D), )

👎Deprecated since 0.3.0:

implement ShellApp (foot_ui, status_ui) and draw with show

As ui_with_foot, with a status bar along the window’s bottom when wide: status fills it from the left, and its right end holds foot. Narrow, as on a phone, there is no status bar: foot stays on the bottom bar, and status is not called.

Auto Trait Implementations§

§

impl<D> Freeze for Shell<D>

§

impl<D> RefUnwindSafe for Shell<D>

§

impl<D> Send for Shell<D>
where Vec<Destination<D>>: Send, Option<D>: Send,

§

impl<D> Sync for Shell<D>
where Vec<Destination<D>>: Sync, Option<D>: Sync,

§

impl<D> Unpin for Shell<D>
where Vec<Destination<D>>: Unpin, Option<D>: Unpin,

§

impl<D> UnsafeUnpin for Shell<D>

§

impl<D> UnwindSafe for Shell<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more