Skip to main content

Module toolbar

Module toolbar 

Source
Expand description

Toolbar — a command bar with automatic overflow.

Excess actions collapse into a trailing chevron () that opens a popover menu, mirroring Qt’s QToolBar extension button, macOS NSToolbar’s overflow menu, and WinUI CommandBar. Synthesized API:

  • Actions (ToolbarAction) — a command with a label + icon (both required), an optional tooltip, enabled state, optional toggle (checkable) or dropdown menu, an overflow priority (NSToolbar: lowest priority collapses first), and an always_overflow flag (WinUI secondary commands). Each action has a toolbar form (an IconButton, or a PopoverIconButton when it carries a menu) and a menu form (a MenuItem, or a submenu), so it renders correctly whether inline or in the overflow menu.
  • Pinned widgets (ToolbarItem::custom) — arbitrary widgets (a search field, a SegmentedControl) that never collapse.
  • Collapsible widgets — an arbitrary widget that does overflow, by supplying an overflow representation (NSToolbar menuFormRepresentation / Qt QWidgetAction): a menu row (ToolbarAction) via ToolbarItem::custom(w).overflow_as(action) (or ToolbarOverflow + ToolbarItem::collapsible; an icon-only control reuses its icon as the menu glyph), or a live embedded widget via ToolbarItem::custom(w).overflow_widget(f) (the factory rebuilds the control — e.g. a ComboBox bound to the same signal — inside the menu so it stays usable while collapsed). When the bar is tight the inline widget is hidden and its overflow form appears in the menu.
  • Separators and flexible space (NSToolbar flexibleSpace).
  • Toolbar-wide button_size (default Compact), button_style (a shared [IconButtonStyle] for every action), and orientation.

Overflow is computed every layout pass from each item’s intrinsic size (measured even while collapsed, via LayoutContext::measure_intrinsic), so items reappear correctly as the bar widens — no stale-width glitches.

The chevron’s drop-down is a real MenuList whose rows are gated by MenuList::item_when, so it sizes compactly to the currently-collapsed rows, carries standard menu chrome, takes focus when opened, and supports arrow / Home / End / Enter keyboard navigation (skipping the hidden rows).

Accessibility (ARIA toolbar pattern). The bar emits Role::Toolbar with its orientation and name. It is a single Tab stop with roving tab-index: arrow keys move focus among the visible controls (and the chevron), Home/End jump to the ends. The chevron announces HasPopup::Menu and its expanded state; overflowed actions are dormant (absent from the AT tree), represented instead by their menu items — so no action is announced twice. Toggle actions carry Toggled.

// on_activate requires an EventContext — use ignore.
use teksilo_widgets::toolbar::{Toolbar, ToolbarAction, ToolbarItem};
use teksilo_i18n::lit;
let _bar = Toolbar::new()
    .action(ToolbarAction::new(lit!("Save"), save_icon).on_activate(|ctx| { /* ... */ }))
    .action(ToolbarAction::new(lit!("Undo"), undo_icon).priority(-1))
    .item(ToolbarItem::flexible_space());

Structs§

Toolbar
A command bar with automatic overflow. See the module docs.
ToolbarAction
A toolbar command: a label + an icon (both required), plus optional tooltip/toggle, an activation handler, an overflow priority, and an always_overflow flag. Renders as an icon-only IconButton inline (the label is its tooltip + accessible name) and as a labelled MenuItem in the overflow menu.
ToolbarItem
One slot in a Toolbar.

Enums§

ToolbarOrientation
Layout axis of the toolbar.

Constants§

TOOLBAR_HEIGHT_DEFAULT
Toolbar design tokens.
TOOLBAR_SPACING

Traits§

ToolbarOverflow
A widget that knows how to represent itself in a Toolbar’s overflow menu when it is collapsed (NSToolbar menuFormRepresentation / Qt QWidgetAction). Implement this on a widget and add it with ToolbarItem::collapsible to make it overflow into the chevron menu as the returned ToolbarAction (a menu row), instead of staying pinned.