CamoToolbar
Concept
1. Why
A toolbar is a row of actions for the current context: formatting buttons in an editor, a bottom bar of a message list, a floating toolbar over a canvas (Material docked and floating toolbars and the bottom app bar, Apple's toolbars, Fluent's Toolbar). It is not navigation (that is the bar, rail and drawer) and not a title bar (CamoTopBar). Actions that don't fit move into an overflow menu.
2. Shape
Split of duties
| Core | Skin (renderer) |
|---|---|
the action model, overflow measuring and the overflow menu (reusing CamoMenuAnchor), roving focus and the toolbar role, insets for the docked bottom placement | container color, shape, depth, spacing, the action look (icon, icon + label), the separator |
Material mapping preview: the M3 docked and floating toolbars.
- Docked: 64 tall,
surfaceContainer, full width. Floating: 64 tall,shapes.full,level3, detached by 16. - Actions are 48 icon buttons in
onSurfaceVariant; the overflow is a "⋮" at the end.
3. API
Contract
data class CamoToolbarAction(
val key: Any,
val label: String, // names the action, shows in the overflow menu and beside the icon when asked
val icon: Widget,
val onClick: () -> Unit,
val enabled: Boolean = true,
val selected: Boolean? = null, // non-null → a toggle (Bold, Italic): pressed state
val tone: Tone = Default,
)
fun CamoToolbar(
actions: List<CamoToolbarAction>,
placement: ToolbarPlacement = Docked, // Docked | Floating
leading: Widget? = null, // a menu button, a title
trailing: Widget? = null, // a FAB-like primary action
overflowLabel: String = "More",
)
// building block (ADR-30): the skin's toolbar surface, the toolbar role and arrow keys, for custom content
fun CamoToolbarContainer(placement: ToolbarPlacement = Docked, content: Slot)
Overflow: actions are measured in order; those that don't fit collapse into a trailing "⋮" CamoMenuAnchor whose items are the actions' labels, icons and toggles. CamoButtonGroups and CamoSplitButtons can also be placed in leading/trailing or in the container.
State → renderer: ToolbarState(placement, count, overflowing). The renderer draws the container; each action is drawn by skin.iconButton (a toggle uses its checked look) unless the skin's ToolbarRenderer.Action overrides. Slots: ToolbarSlots(leading?, trailing?).
Tokens used
colors.surfaceContainer,onSurfaceVariant,outlineVariantshapes.full(floating),elevation.level3(floating)spacing.sbetween actions,spacing.lside paddingmotion.durationShort(a floating toolbar shows and hides)
Component theme
theme.components.toolbar: ToolbarTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
placement | Docked | Floating | Docked | docked: edge to edge on the inset; floating: detached |
height | Dp | 64 | toolbar height (plus the bottom inset when docked at the bottom) |
floatingMargin / floatingShape | Dp / Shape | 16 / shapes.full | the floating container |
floatingElevation | ElevationLevel | Level3 | the floating depth |
showLabels | LabelVisibility | Never | labels beside icons (Apple and Fluent can show them) |
actionSpacing | Dp | 4 | between actions |
showDivider | Boolean | false | a hairline on the docked edge |
colors | ToolbarColors(container, icon, selected, divider) | surfaceContainer, onSurfaceVariant, primary, outlineVariant | every color it uses |
Accessibility
- Role toolbar, named by the app (
contentDescription/semanticLabel), with the actions as buttons ("Bold, toggle button, pressed"). - One Tab stop; the arrow keys move between actions, Home and End jump, and a disabled action is skipped.
- The overflow button announces "More, has popup" and its items are menu items.
4. Build steps
CamoToolbarAction, the measuring overflow,ToolbarTheme/Style, state, slots, renderer, theCamoSkinfield.CamoToolbar,CamoToolbarContainer, the DebugSkin renderer.- Sample: an editor toolbar with grouped and split buttons, a popover and a properties side sheet (the milestone screen).
- Tests: overflow at narrow widths (and back), toggles, roving focus, the menu items, the bottom inset, floating placement.
Done when
- The editor sample's toolbar overflows gracefully, works by touch, keyboard and screen reader.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Nothing fits | Only the overflow button shows. |
| Vertical toolbars | Later (orientation). |
| A toggle in the overflow | A checkable menu item with the same state. |
| Hide on scroll | visible like the bar and the FAB (rememberHideOnScroll). |
- The renderer has one part, the container:
Container(state, theme, style, modifier, content)withToolbarState(placement, count). The actions are ghostskin.iconButtons and core measures and lays out the row; there is noToolbarSlotsand nooverflowingflag, because the fit is known only after the container is drawn. - The theme gains
actionSize(the width one action takes when measuring),paddingandoverflowIcon;ToolbarColorsis(container, divider).showLabelsis not built (labels beside icons come later). - Overflow: all actions, or as many as fit beside the overflow button, in order; the rest become menu items with their labels, icons, tones and enabled state, and a toggle becomes a checkable item. Arrow keys move over the actions and the overflow button without pressing them.
- Neither Compose nor Flutter has a toolbar role: the toolbar is a named container. It measures its room as it lays out, so it has no intrinsic size; give it a width.
- Not built: insets for a docked bottom toolbar, hide on scroll (
visible), vertical toolbars, tooltips on the actions. Minimal draws a 48 bar with a hairline (floating: Level2); Fluent a flat 44 bar (floating: Level4).
- Actions as data vs. children: the data form gives automatic overflow; custom children (button groups, split buttons) go in
leading/trailingor the building-block container and do not overflow. Say if you want children to overflow too (it needs a measured custom layout).- Vertical toolbars are Later.
Implementation
1. Why
Compose has no toolbar below Material's. Core measures with a SubcomposeLayout to decide which actions fit, draws those with the skin's icon button and moves the rest into the overflow menu.
2. Shape
3. API
@Composable public fun CamoToolbar(actions: List<CamoToolbarAction>, modifier: Modifier = Modifier,
placement: ToolbarPlacement = ToolbarPlacement.Docked, leading: (@Composable () -> Unit)? = null,
trailing: (@Composable () -> Unit)? = null, overflowLabel: String = "More", visible: Boolean = true)
@Composable public fun CamoToolbarContainer(modifier: Modifier = Modifier, placement: ToolbarPlacement = Docked,
content: @Composable RowScope.() -> Unit)
SubcomposeLayoutmeasures every action once, reserves the overflow button and the leading and trailing slots, and composes only the actions that fit; resizing recomposes the split.- Roving focus (
rememberRovingFocus) across the fitting actions and the overflow button;Role.Button, andtoggleablefor toggles. - Docked placement pads by the bottom navigation-bar inset;
visibleslides it like the navigation bar.
4. Build steps
- The overflow layout,
ToolbarTheme/Style, state, slots, renderer, theCamoSkinfield. CamoToolbar,CamoToolbarContainer, the DebugSkin renderer.- Tests: overflow at widths, toggle semantics, arrows, the inset, the menu items.
Done when
- Overflow, toggles and keyboard work on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Window resize | The split recomputes; focus stays on the same action when it is still visible, else on the overflow button. |
| RTL | The row and the overflow mirror. |
- Measuring is a
SubcomposeLayout: the leading and trailing content are measured first, the actions are composed last withfitActions(count, available, action, spacing)(a pure function, tested alone). Each action is aCamoIconButtonwithrovingFocusItem; the overflow is aCamoMenuAnchorover the rest. CamoToolbarContainer(modifier, placement, contentDescription, content)is the building block. Tests: the fit function, overflow at narrow widths and back, toggles in the toolbar and in the overflow, arrows skipping a disabled action, leading and trailing content, the floating placement.- Sample: the editor screen (a command bar in a
CamoToolbarContainerwith a split button and two groups, a floating action bar with a popover and a properties side sheet).
- None specific.