Skip to main content

TabRail

Struct TabRail 

Source
pub struct TabRail<Msg> { /* private fields */ }
Expand description

Tabs stacked down the side of the screen, such as the open projects of an IDE.

Every tab is a row with an icon, the name and optional status dot and badge. The open tab is raised with the accent pillar, which breathes while the rail has keyboard focus; a hovered tab rises softly and its icon and name slide one cell while the status dot, badge and close mark stay put. collapsed narrows the rail to a thin strip of four cells: the pillar, a one-cell icon (or the name’s first letter) that keeps its column when its tab is hovered or open, a cell of air and a column that becomes the scrollbar when tabs overflow. collapsed_marker and RailTab::marker make that cell the tab’s initial or position instead. on_add ends the rail with an add (+) row.

row_height makes every row a raised block several lines tall, with its content on the middle line, the close mark in its top right corner and the pillar down the whole block. Blocks taller than a line are one canvas line apart, so they do not read as one column; gap sets another distance, and gap(0) stacks them. Hover, presses, dragging, scrolling and the scrollbar count whole blocks; the collapsed strip, its name card and the add row keep the same height.

In a collapsed rail a name card beside the row shows the name and badge of the hovered tab, or of the open tab while the rail has keyboard focus. The pointer can move onto the card: it stays while the pointer is on the row or the card, rises under the pointer and opens its tab when clicked. With closing on, the card ends in the tab’s close mark, on the card’s middle line.

Keys while focused: ↑/↓ (or k/j) open the neighbouring tab, Home/End the first and last. The options are the same as Tabs and behave the same: closable (a faint ×, middle click, ctrl+w), pinned and reorderable (drag with a ghost over the slot where the tab lands, ctrl+shift+↑/↓; held on the first or last visible block or past the rail’s end, a dragged tab scrolls the rail one block after 400 ms and then every 150 ms, sooner the further past the end, with the scrollbar lit and the drop slot following, see on_drag_scroll) and context_menu (a right click on a tab opens its menu at the pointer, the menu key or shift+F10 the menu of the open tab; without it a right click does nothing). Rows that do not fit scroll with the wheel or the scrollbar (click or drag it) and follow the open tab.

Style keys: rail-tab with hover, selected, focus and the variant tall for blocks taller than a line; rail-badge with the same states; rail-hint (bg, fg) with hover for the name card of a collapsed rail; rail-add with hover and tall for the add row; close-mark, tab-ghost and tab-drop shared with Tabs; scrollbar; the keys of ContextItem for the context menu.

Implementations§

Source§

impl<Msg: 'static> TabRail<Msg>

Source

pub fn new(tabs: impl IntoIterator<Item = RailTab>) -> Self

A rail of tabs; the first is open.

Source

pub fn active(self, index: usize) -> Self

The open tab.

Source

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

Message for opening tab index.

Source

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

Narrows the rail to a four-cell strip of icons; a name card beside a hovered tab names it and takes clicks.

Source

pub fn collapsed_marker(self, marker: CollapsedMarker) -> Self

What the collapsed strip shows for tabs without their own RailTab::marker: their icon (the default), initial or position.

Source

pub fn row_height(self, lines: u16) -> Self

Makes every row a block lines tall (at least one), like the project tabs of an IDE: the name, icon, status and badge sit on the middle line (the upper one of an even block), the close mark flush right on the first line, and resting tabs are raised blocks too. One line, the default, is a plain list of rows. Blocks taller than one line are one canvas line apart unless gap is set. Any height works; the rail scrolls by whole blocks.

Source

pub fn gap(self, lines: u16) -> Self

Leaves lines of canvas between rows. By default one line separates rows taller than one line and none separates one-line rows; gap(0) stacks tall blocks.

Source

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

Ends the rail with an add row (+) that sends message when clicked, e.g. to open a new project.

Source

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

Makes tabs closable: message(index) asks the application to close tab index. TabEdit::Close applies it to the application’s list.

Source

pub fn pinned(self, indices: impl IntoIterator<Item = usize>) -> Self

Tabs that cannot be closed. They show no close mark.

Source

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

Makes tabs reorderable: message(from, to) asks the application to move a tab. TabEdit::Move applies it to the application’s list.

Source

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

Message for each step a dragged tab scrolls an overflowing rail, with the first row now in view (counted from 0), e.g. to log it. Only reorderable rails scroll this way.

Source

pub fn context_menu( self, items: impl Fn(usize) -> Vec<ContextItem<Msg>> + 'static, ) -> Self

Gives every tab a context menu: items(index) builds the entries for tab index, such as Close, Close others or Pin. A right click on a tab (or on the name card of a collapsed rail) opens its menu at the pointer; the menu key or shift+F10 opens the menu of the open tab below its block, scrolling the tab into view first. Choosing an entry sends its message.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for TabRail<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for TabRail<Msg>

§

impl<Msg> !Send for TabRail<Msg>

§

impl<Msg> !Sync for TabRail<Msg>

§

impl<Msg> !UnwindSafe for TabRail<Msg>

§

impl<Msg> Freeze for TabRail<Msg>
where Option<Box<dyn Fn() -> Msg>>: Freeze, TabModel<Msg>: Freeze,

§

impl<Msg> Unpin for TabRail<Msg>
where Option<Box<dyn Fn() -> Msg>>: Unpin, TabModel<Msg>: Unpin,

§

impl<Msg> UnsafeUnpin for TabRail<Msg>
where Option<Box<dyn Fn() -> Msg>>: UnsafeUnpin, TabModel<Msg>: 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.