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 dropdownmenu, an overflow priority (NSToolbar: lowest priority collapses first), and analways_overflowflag (WinUI secondary commands). Each action has a toolbar form (anIconButton, or aPopoverIconButtonwhen it carries a menu) and a menu form (aMenuItem, or a submenu), so it renders correctly whether inline or in the overflow menu. - Pinned widgets (
ToolbarItem::custom) — arbitrary widgets (a search field, aSegmentedControl) that never collapse. - Collapsible widgets — an arbitrary widget that does overflow, by
supplying an overflow representation (NSToolbar
menuFormRepresentation/ QtQWidgetAction): a menu row (ToolbarAction) viaToolbarItem::custom(w).overflow_as(action)(orToolbarOverflow+ToolbarItem::collapsible; an icon-only control reuses its icon as the menu glyph), or a live embedded widget viaToolbarItem::custom(w).overflow_widget(f)(the factory rebuilds the control — e.g. aComboBoxbound 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(defaultCompact),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.
- Toolbar
Action - A toolbar command: a label + an icon (both required), plus optional
tooltip/toggle, an activation handler, an overflow priority, and an
always_overflowflag. Renders as an icon-onlyIconButtoninline (the label is its tooltip + accessible name) and as a labelledMenuItemin the overflow menu. - Toolbar
Item - One slot in a
Toolbar.
Enums§
- Toolbar
Orientation - Layout axis of the toolbar.
Constants§
- TOOLBAR_
HEIGHT_ DEFAULT - Toolbar design tokens.
- TOOLBAR_
SPACING
Traits§
- Toolbar
Overflow - A widget that knows how to represent itself in a
Toolbar’s overflow menu when it is collapsed (NSToolbarmenuFormRepresentation/ QtQWidgetAction). Implement this on a widget and add it withToolbarItem::collapsibleto make it overflow into the chevron menu as the returnedToolbarAction(a menu row), instead of staying pinned.