Skip to main content

Tabs

Struct Tabs 

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

A row of tabs. The open tab is a raised surface; tabs are never boxed or bracketed.

With no options it is the plainest strip: keys while focused are ←/→ (or h/l) to open the neighbouring tab, and 1–9 open a tab by number when numbers are shown. When the tabs do not fit, arrow controls appear at both ends: a click scrolls one tab, and ctrl+PgUp, ctrl+PgDn and the wheel do the same. Opening a tab brings it into view.

Capabilities are independent options:

  • closable: a faint × on every tab that brightens on hover; clicking it, a middle click on the tab or ctrl+w closes the tab. pinned tabs cannot be closed.
  • tab_width: fit, fixed or filling tabs.
  • overflow: scroll arrows or a menu of hidden tabs.
  • reorderable: drag a tab to move it; a ghost follows the pointer and the tabs make room where it will land. ctrl+shift+←/→ moves the open tab. Held on a scroll arrow or past an end of an overflowing strip, the dragged tab scrolls the strip: one tab after 400 ms, then one every 150 ms (sooner the further past the end) until the pointer leaves or the strip ends; the arrow lights up meanwhile and the drop slot follows the tabs coming into view. on_drag_scroll reports each step.
  • context_menu: a right click on a tab opens a menu of actions for it at the pointer; the menu key or shift+F10 opens the menu of the open tab. Without it a right click does nothing.
  • badge: a count right after a tab’s name, such as the updates waiting in an Updates tab. A narrow tab shortens its name and keeps the count.
  • on_add: a + button right after the last tab, or at the strip’s right end while tabs hide, that asks for a new tab. Tab from the tabs reaches it; Enter and Space press it; resting on it, or reaching it with the keyboard, shows what it does. A tab dragged onto it moves to the end.

Style keys: tab with hover, selected, focus; tab-index for numbers; tab-badge with the same states for counts; close-mark (with active on a raised tab, hover under the pointer); tab-arrow (bg, fg, pillar) with hover, pressed, disabled; tab-menu (bg, fg, pillar) with hover, active while its menu is open; tab-ghost and tab-drop (bg) while dragging; popup-menu, popup-item, popup-check for the menu of hidden tabs; tab-add (bg, fg, pillar) with hover, focus, pressed and tooltip for its hint; the keys of ContextItem for the context menu.

Implementations§

Source§

impl<Msg: 'static> Tabs<Msg>

Source

pub fn new(labels: impl IntoIterator<Item = impl Into<String>>) -> Self

Tabs with labels; the first is open.

Source

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

The open tab.

Source

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

Shows 1, 2, 3… before the labels and lets number keys open tabs.

Source

pub fn badge(self, index: usize, count: u32) -> Self

Shows count right after the name of tab index, one space after it, in a quieter tone than the name, such as the updates waiting in an Updates tab; counts above 99 read 99+. A count of zero shows nothing and takes no room, so the count can be passed as it is. The count stays in place while the name slides, and a tab too narrow for both shortens its name and keeps the count. An index past the last tab is ignored.

Source

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

Message for opening tab index.

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, such as a pinned start page. They show no close mark.

Source

pub fn tab_width(self, width: TabWidth) -> Self

How wide the tabs are; TabWidth::Fit by default.

Source

pub fn overflow(self, overflow: Overflow) -> Self

What happens when the tabs do not fit; Overflow::Arrows by default.

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 strip, with the position of the first tab now in view (counted from 0), e.g. to log it. Only reorderable strips scroll this way.

Source

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

Adds a + button that sends message when pressed, e.g. to open a new tab. It stands one gap after the last tab; while tabs hide it keeps its place at the strip’s right end, after the arrows or the menu control, and with no tabs it starts the strip. Tab moves keyboard focus from the tabs to it; Enter and Space press it.

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 opens its menu at the pointer; the menu key or shift+F10 opens the menu of the open tab below it, scrolling the tab into view first. Choosing an entry sends its message.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for Tabs<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 Tabs<Msg>

§

impl<Msg> !Send for Tabs<Msg>

§

impl<Msg> !Sync for Tabs<Msg>

§

impl<Msg> !UnwindSafe for Tabs<Msg>

§

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

§

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

§

impl<Msg> UnsafeUnpin for Tabs<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.