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. crate::material::material takes
a corner radius and paints the backdrop blur to it, and a mismatch frosts
square corners outside a round border. One radius comes out of Shape and
feeds both, so there is no second number to keep in step.
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.
diameteris 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.
centreis optional — a toolbar with only clusters passesNoneand the rails still hold their ends.