Skip to main content

SidePanel

Struct SidePanel 

Source
pub struct SidePanel<'a, Msg> { /* private fields */ }
Expand description

A panel docked to the left or right of a body, on its own surface.

The application owns whether the panel is open, how wide it is and which view it shows. The plain panel is just a surface next to the body; capabilities are opt-in:

  • SidePanel::on_toggle makes the edge between panel and body interactive. The edge is a tone difference, never a line: on hover it brightens one step and a two-cell toggle appears at its middle, a or on a raised surface reaching one cell into the body. Pointing at the toggle raises it a step more and shows the pillar in its first cell, pressing it raises it one more; clicking toggles. Tab reaches the edge and shows the same toggle, where Enter or Space toggles, and the global action toggle-panel (alt+b by default) toggles from anywhere inside the panel or the body. Opening and closing slide over twice motion.enter. Dragging a closed edge half the minimum width into the body opens the panel.
  • SidePanel::on_resize lets the edge be dragged, and moved with ←/→ while focused, within SidePanel::limits.
  • SidePanel::strip adds an activity bar: a column of view icons at the outer edge, beside the open panel and left behind when it collapses. SidePanel::active_view marks the shown view’s icon, raised with the pillar. Clicking another icon switches to its view (opening the panel if it is closed); clicking the shown view’s icon closes the panel. Tab reaches the strip, where ↑/↓ move and Enter or Space act like a click.
  • SidePanel::closed chooses what closing leaves: the strip (Closed::Collapse, the default) or only an invisible edge column (Closed::Hide).

Style keys: side-panel (bg), side-strip (bg), side-strip-item (fg, bg, pillar) with hover, selected, focus and pressed, split-handle for the edge and side-toggle (bg, fg, pillar) with hover, focus and pressed for the toggle. Icons: edge-left, edge-right.

Implementations§

Source§

impl<'a, Msg: 'static> SidePanel<'a, Msg>

Source

pub fn new(width: u16) -> Self

An open panel width columns wide, docked left.

Source

pub fn side(self, side: Side) -> Self

Docks the panel to side.

Source

pub fn open(self, open: bool) -> Self

Whether the panel is open; true by default.

Source

pub fn closed(self, closed: Closed) -> Self

What closing leaves behind: Closed::Collapse (the default) keeps the icon strip, Closed::Hide hides the strip too and leaves only the edge column.

Source

pub fn on_toggle(self, message: impl Fn(bool) -> Msg + 'static) -> Self

Makes the edge toggle the panel; the message carries the new open state.

Source

pub fn on_resize(self, message: impl Fn(u16) -> Msg + 'static) -> Self

Makes the edge resize the panel; the message carries the new width within the limits.

Source

pub fn limits(self, min: u16, max: impl Into<Option<u16>>) -> Self

The narrowest and widest the panel can be, in columns: limits(18, 48) for a range, or limits(18, None) for no upper limit. By default 8 and no upper limit; whatever the limits, the body keeps at least a quarter of the area. A max below min counts as min.

Source

pub fn strip( self, icons: impl IntoIterator<Item = impl Into<String>>, message: impl Fn(u16) -> Msg + 'static, ) -> Self

Adds an activity bar of these view icons at the outer edge. Clicking an icon sends its index, meaning “show this view”: set the view and open the panel in update. The icon of the active_view instead closes the open panel through on_toggle.

Source

pub fn active_view(self, index: u16) -> Self

The index of the strip icon whose view the panel shows; it is raised with the pillar while the panel is open.

Source

pub fn panel(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self

The panel’s content.

Source

pub fn body(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self

The body beside the panel.

Source

pub fn show<'v>(self, ui: &'v mut View<'_, Msg>) -> NodeMut<'v, Msg>

Adds the panel and its body to ui, filling the space they get.

Auto Trait Implementations§

§

impl<'a, Msg> !RefUnwindSafe for SidePanel<'a, Msg>

§

impl<'a, Msg> !Send for SidePanel<'a, Msg>

§

impl<'a, Msg> !Sync for SidePanel<'a, Msg>

§

impl<'a, Msg> !UnwindSafe for SidePanel<'a, Msg>

§

impl<'a, Msg> Freeze for SidePanel<'a, Msg>
where Option<Rc<dyn Fn(bool) -> Msg>>: Freeze, Option<Box<dyn Fn(u16) -> Msg>>: Freeze, Option<Rc<dyn Fn(u16) -> Msg>>: Freeze, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: Freeze,

§

impl<'a, Msg> Unpin for SidePanel<'a, Msg>
where Option<Rc<dyn Fn(bool) -> Msg>>: Unpin, Option<Box<dyn Fn(u16) -> Msg>>: Unpin, Option<Rc<dyn Fn(u16) -> Msg>>: Unpin, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: Unpin,

§

impl<'a, Msg> UnsafeUnpin for SidePanel<'a, Msg>
where Option<Rc<dyn Fn(bool) -> Msg>>: UnsafeUnpin, Option<Box<dyn Fn(u16) -> Msg>>: UnsafeUnpin, Option<Rc<dyn Fn(u16) -> Msg>>: UnsafeUnpin, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: UnsafeUnpin,

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