Expand description
ToolbarHoverTracker — host-side state holder that converts
MouseMoved events into hovered_id: Option<WidgetId> for the
Toolbar primitive.
The toolbar rasterisers accept a hovered_id so they can tint the
matching button’s background, but the host has to track which
button the mouse is over across mouse-move events — the rasteriser
itself is stateless. Doing that by hand means converting from
screen-space coordinates back through a ToolbarLayout per move
event, plus remembering to clear the hover when the cursor leaves
the bar. Easy to forget; easy to get wrong.
This helper owns that bookkeeping: feed it mouse-move events
together with the current layout, ask it for the active
hovered_id at render time, and pass that straight to
Backend::draw_toolbar.
§Usage
struct App {
hover: ToolbarHoverTracker,
// ...
}
impl AppLogic for App {
fn handle(&mut self, ev: UiEvent, backend: &mut dyn Backend) -> Reaction {
if let UiEvent::MouseMoved { position, .. } = ev {
let layout = backend.toolbar_layout(self.bar_rect(backend), &self.bar());
if self.hover.update(&layout, position.x, position.y) {
return Reaction::Redraw;
}
}
// ...
}
fn render(&self, backend: &mut dyn Backend, _area: ()) {
backend.draw_toolbar_interactive(
self.bar_rect(backend),
&self.bar(),
&InteractionState::from_parts(self.hover.hovered_id().cloned(), None),
);
}
}Structs§
- Toolbar
Hover Tracker - Tracks the toolbar button currently under the mouse. Cheap to keep
per toolbar (or per panel, if a panel hosts multiple) — one
Option<WidgetId>plus a singlehit_testcall per mouse-move.