Skip to main content

Module control_bar

Module control_bar 

Source
Expand description

control_bar — the floating control bar: a glass surface holding a leading cluster, an optional centre, and a trailing cluster. Apple Music’s transport, a desktop agent app’s composer, a floating toolbar.

Shape is the only thing that differs between those; everything below is shape-blind, which is why the module is named for the job rather than for the stadium it started as.

Two things it exists to get right.

The blur corners follow the border. Shape rounds the bar, and crate::surface::Surfaced::surface cuts the surface to the rounding it finds — a blur squarer than its border frosts the corners outside it.

The centre is centred on the bar, not on what the clusters leave. The two rails are equal-flex and the centre is not: clusters of five controls and three then keep the middle on axis. Flexing the centre between them instead is the classic toolbar bug — it lands wherever the wider cluster pushes it.

That second rule is why the bar takes the width it is given rather than hugging its controls. Equal rails need free space to be equal about; a shrink-to-fit bar has none, and its middle then lands wherever the clusters happen to put it. So width is the caller’s, and a max_w is how a wide window gets a floating bar instead of a docked one.

Placement is the caller’s too, and it is four lines. This bar floats over content and must never reflow it — the same overlay-never-a-gutter rule crate::scroll follows. A bar that does reflow its content is a dock, not this: no blur, no float, and nothing here to reuse.

div().relative().size_full()
    .child(page)
    .child(
        div().absolute().bottom(px(20.0)).left_0().right_0()
            .flex().justify_center()
            .child(div().w_full().max_w(px(880.0)).child(
                control_bar::control_bar(&theme, Shape::Pill, leading, Some(centre), trailing),
            )),
    )

Enums§

Shape
How the bar’s corners are cut. Two named cases rather than a radius, because this is a choice between two shapes and not a continuum — and because a bare number at the call site says nothing about which one you meant.

Constants§

BAR_HEIGHT
Height of the bar, and so half the radius of a Shape::Pill. One number rather than a parameter: a stadium’s radius has to be derived from it for the material’s blur to match the border, and a caller free to pick a height is a caller free to get that wrong.

Functions§

bar_button
A circular control inside a bar: the ring, and its glyph at half the diameter. diameter is a parameter because a transport’s primary action is deliberately bigger than its neighbours — that size difference is what makes the cluster readable at a glance.
control_bar
The bar. centre is optional — a toolbar with only clusters passes None and the rails still hold their ends.