pub struct Shell<D> { /* private fields */ }Expand description
The window frame. Hold one as the app’s root; call ui every frame.
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.
#[derive(Clone, Copy, PartialEq)]
enum Screen { Gallery, Albums, Settings }
let mut shell = Shell::new(vec![
// The app's own Lucide SVGs: `egui::include_image!("../assets/icons/images.svg")`.
Destination::new(Screen::Gallery, icons::folder(), "gallery"),
Destination::new(Screen::Albums, icons::folder(), "albums"),
])
.with_footer(vec![Destination::new(Screen::Settings, icons::settings(), "settings")]);
shell.ui(ui, |ui, screen| match screen {
Screen::Gallery => { egui::CentralPanel::default().show(ui, |ui| ui.label("…")); }
Screen::Albums => { egui::CentralPanel::default().show(ui, |ui| ui.label("…")); }
Screen::Settings => { egui::CentralPanel::default().show(ui, |ui| ui.label("…")); }
});Implementations§
Source§impl<D: Copy + PartialEq> Shell<D>
impl<D: Copy + PartialEq> Shell<D>
Sourcepub fn new(destinations: Vec<Destination<D>>) -> Shell<D>
pub fn new(destinations: Vec<Destination<D>>) -> Shell<D>
A frame with destinations on the rail, the first one open.
Sourcepub fn with_actions(self, actions: Vec<Action>) -> Shell<D>
pub fn with_actions(self, actions: Vec<Action>) -> Shell<D>
Put actions on the rail, under the screens (on the bottom bar, after them).
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.
Sourcepub fn take_action(&mut self) -> Option<&'static str>
pub fn take_action(&mut self) -> Option<&'static str>
Sourcepub fn current(&self) -> Option<D>
pub fn current(&self) -> Option<D>
The destination that is open; None only when there are none.
Sourcepub fn ui_with_foot(
&mut self,
ui: &mut Ui,
foot: impl FnOnce(&mut Ui) -> Option<D>,
content: impl FnOnce(&mut Ui, D),
)
pub fn ui_with_foot( &mut self, ui: &mut Ui, foot: impl FnOnce(&mut Ui) -> Option<D>, content: impl FnOnce(&mut Ui, D), )
As ui, with foot drawn beside the footer — a status dot, say. A
destination foot returns is opened, and drawn this frame.
Sourcepub 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),
)
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), )
As ui_with_foot, with a status bar along the window’s
bottom when wide. status fills it from the left — a log’s last line, the services’
state, the track playing; the bar’s right end holds foot (there rather than at the
rail’s foot), then the detail pane’s toggle when the open screen has
one. 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>
impl<D> Sync for Shell<D>
impl<D> Unpin for Shell<D>
impl<D> UnsafeUnpin for Shell<D>
impl<D> UnwindSafe for Shell<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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