Skip to main content

Module hover

Module hover 

Source
Expand description

Interaction-state paint primitives: hover, press, focus ring - all folded into a single Interaction fat component.

Interaction.hover_tint blends the Visuals solid fill toward a tint while the entity is Hovered or Focused. press_tint overrides that blend when the entity is Pressed - pressed > hovered/focused > idle. focus_outline paints a stroked ring around the entity while it has Focused. Gradient fills are skipped by the tween (no animation path); the gradient renders unchanged.

Tween state (HoverTween, PressTween) stays in separate transient components - they’re auto-attached / cleared by the systems below, never authored. The tinted fill and the swapped border are held in StyleOverrides while they show, so a restyle meanwhile keeps them and they let go onto whatever the element’s styles say by then.

Structs§

FocusOutlineSpec
Stored on Interaction::focus_outline. Was a free-standing FocusOutline component before the alpha2 collapse.
HoverTintPlugin
Plugin: registers apply_hover_tint then apply_press_tint in TickStage::Systems. Press runs second so it can stamp over whatever hover wrote on the same tick.
HoverTween
Per-entity timer driving the hover tween. progress runs 0 -> 1 toward the hover tint while hovered/focused, and 1 -> 0 toward what is under the tint when both interaction markers are gone. Idempotent across frames so the system can simply step progress by delta-time.
Interaction
Author-set interaction-state paint: hover tint + press tint + focus outline, all on one component. Each field is Option-shaped so markup can opt into any subset. Absent component = no hover / press / focus visual feedback.
PressTween
Per-entity press tween (mirror of HoverTween for the press state).
StateBorderHeld
Marks an element whose Visuals::border apply_state_borders holds, and names its layer in StyleOverrides.

Constants§

HOVER_TWEEN_DURATION
How long it takes for the hover-tint to fully blend in or out, in seconds. Picked to feel responsive but not jittery - comparable to a macOS button highlight, faster than a Material ripple.
PRESS_TWEEN_DURATION
Press tween duration - faster than hover, matches the snappy “click pulse” of native buttons.

Functions§

apply_hover_tint
Drive HoverTween’s progress toward target, then blend the solid Visuals::fill from what is under the tint toward Interaction::hover_tint.
apply_press_tint
Override the solid Visuals::fill with Interaction::press_tint while the entity is visually pressed. Tweens over PRESS_TWEEN_DURATION using ease-out.
apply_state_borders
Swap Visuals::border per interaction state: focused -> Interaction::focus_border, hovered -> Interaction::hover_border, idle -> whatever the element’s styles give it then. Focus wins over hover when both are active. Borders snap (no tween), matching CSS :hover / :focus border rules without a transition.
extract_focus_outlines
Extract: for every focused entity whose Interaction declares a focus outline, spawn an ExtractedOutline in the render world that draws on top of the matching rect.