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>
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 from_items(items: Vec<RailItem<D>>) -> Shell<D>
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.
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 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.
Sourcepub fn with_rail_order(self, order: &RailOrder) -> Shell<D>
pub fn with_rail_order(self, order: &RailOrder) -> Shell<D>
Lay the rail out in order, as set_rail_order.
Sourcepub fn rail_order(&self) -> RailOrder
pub fn rail_order(&self) -> RailOrder
The order the rail’s items are in, and which of them it leaves to the menu.
Sourcepub fn set_rail_order(&mut self, order: &RailOrder)
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.
Sourcepub fn take_action(&mut self) -> Option<&'static str>
👎Deprecated since 0.3.0: draw with show, which hands the action to ShellApp::action
pub fn take_action(&mut self) -> Option<&'static str>
draw with show, which hands the action to ShellApp::action
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 with_side_pane(self) -> Shell<D>
👎Deprecated since 0.3.0: every shell has a side pane
pub fn with_side_pane(self) -> Shell<D>
every shell has a side pane
The side pane is always there now.
Sourcepub fn with_status_bar(self) -> Shell<D>
👎Deprecated since 0.3.0: show always draws a status bar, wide
pub fn with_status_bar(self) -> Shell<D>
show always draws a status bar, wide
show always draws the status bar, wide, now.
Sourcepub fn show(&mut self, ui: &mut Ui, app: &mut impl ShellApp<D>)
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.
Sourcepub fn ui(&mut self, ui: &mut Ui, content: impl FnOnce(&mut Ui, D))
👎Deprecated since 0.3.0: implement ShellApp and draw with show
pub fn ui(&mut self, ui: &mut Ui, content: impl FnOnce(&mut Ui, D))
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.
Sourcepub 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
pub fn ui_with_foot( &mut self, ui: &mut Ui, foot: impl FnOnce(&mut Ui) -> Option<D>, content: impl FnOnce(&mut Ui, D), )
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.
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),
)
👎Deprecated since 0.3.0: implement ShellApp (foot_ui, status_ui) and draw with show
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), )
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>
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