Skip to main content

apply_state_visuals

Function apply_state_visuals 

Source
pub fn apply_state_visuals(
    commands: Commands<'_, '_>,
    pointer: Option<Res<'_, PointerState>>,
    active: Query<'_, '_, (Entity, &StateVisuals, Option<&mut TextStyle>, Option<&mut Visuals>, Option<&Opacity>, &mut StyleOverrides, Has<StatePatched>, Option<&Hovered>, Option<&Focused>, Option<&FocusVisible>, Option<&Pressed>, Has<Disabled>, Has<DropHovered>), Or<(With<Hovered>, With<Focused>, With<Pressed>, With<Disabled>, With<DropHovered>)>>,
    idle: Query<'_, '_, (Entity, Option<&mut TextStyle>, Option<&mut Visuals>, Option<&Opacity>, &mut StyleOverrides), (With<StatePatched>, With<StateVisuals>, Without<Hovered>, Without<Focused>, Without<Pressed>, Without<Disabled>, Without<DropHovered>)>,
    orphaned: Query<'_, '_, (Entity, Option<&mut TextStyle>, Option<&mut Visuals>, Option<&Opacity>, &mut StyleOverrides), (With<StatePatched>, Without<StateVisuals>)>,
)
Expand description

Swap text color / opacity / shadows / background per interaction state, and let them go when every state ends.

The swapped values are held in StyleOverrides, so a restyle while a state is on keeps them, and letting go lands on what the element’s styles say by then. Only the fields some active state authors are held; the rest stay the element’s own.

Every component this system attaches goes through try_insert. The entity under the pointer is the one most likely to leave the tree on this very tick: a click on a nav link runs the handler that swaps the page, and the <if> reconciler despawns the outgoing tree in this same stage with nothing ordering it against this system. A plain insert against an element the swap already took away fails the whole command buffer rather than just itself.