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>
impl<Msg: 'static> TabRail<Msg>
Sourcepub fn new(tabs: impl IntoIterator<Item = RailTab>) -> Self
pub fn new(tabs: impl IntoIterator<Item = RailTab>) -> Self
A rail of tabs; the first is open.
Sourcepub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self
pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self
Message for opening tab index.
Sourcepub fn collapsed(self, collapsed: bool) -> Self
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.
Sourcepub fn collapsed_marker(self, marker: CollapsedMarker) -> Self
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.
Sourcepub fn row_height(self, lines: u16) -> Self
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.
Sourcepub fn gap(self, lines: u16) -> Self
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.
Sourcepub fn on_add(self, message: impl Fn() -> Msg + 'static) -> Self
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.
Sourcepub fn closable(self, message: impl Fn(usize) -> Msg + 'static) -> Self
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.
Sourcepub fn pinned(self, indices: impl IntoIterator<Item = usize>) -> Self
pub fn pinned(self, indices: impl IntoIterator<Item = usize>) -> Self
Tabs that cannot be closed. They show no close mark.
Sourcepub fn reorderable(
self,
message: impl Fn(usize, usize) -> Msg + 'static,
) -> Self
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.
Sourcepub fn on_drag_scroll(self, message: impl Fn(usize) -> Msg + 'static) -> Self
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.
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>
impl<Msg: 'static> Widget<Msg> for TabRail<Msg>
Source§fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
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>
impl<Msg> Unpin for TabRail<Msg>
impl<Msg> UnsafeUnpin for TabRail<Msg>
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
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