From acadf37c6d860654b8aa9566dad7f0b8f84eae35 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 25 Jun 2025 10:20:30 +0100 Subject: [PATCH] Added a check for drag state to the slider systems that update the colour of the thumb so that it keeps the active colour during drags even when the pointer is not hovering the slider. --- examples/ui/core_widgets.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/ui/core_widgets.rs b/examples/ui/core_widgets.rs index ca91605206373..7bf1e99966928 100644 --- a/examples/ui/core_widgets.rs +++ b/examples/ui/core_widgets.rs @@ -3,8 +3,8 @@ use bevy::{ color::palettes::basic::*, core_widgets::{ - CoreButton, CoreCheckbox, CoreRadio, CoreRadioGroup, CoreSlider, CoreSliderThumb, - CoreWidgetsPlugin, SliderRange, SliderValue, TrackClick, + CoreButton, CoreCheckbox, CoreRadio, CoreRadioGroup, CoreSlider, CoreSliderDragState, + CoreSliderThumb, CoreWidgetsPlugin, SliderRange, SliderValue, TrackClick, }, ecs::system::SystemId, input_focus::{ @@ -398,6 +398,7 @@ fn update_slider_style( &SliderValue, &SliderRange, &Hovered, + &CoreSliderDragState, Has, ), ( @@ -405,6 +406,7 @@ fn update_slider_style( Changed, Changed, Changed, + Changed, Added, )>, With, @@ -413,12 +415,12 @@ fn update_slider_style( children: Query<&Children>, mut thumbs: Query<(&mut Node, &mut BackgroundColor, Has), Without>, ) { - for (slider_ent, value, range, hovered, disabled) in sliders.iter() { + for (slider_ent, value, range, hovered, drag_state, disabled) in sliders.iter() { for child in children.iter_descendants(slider_ent) { if let Ok((mut thumb_node, mut thumb_bg, is_thumb)) = thumbs.get_mut(child) { if is_thumb { thumb_node.left = Val::Percent(range.thumb_position(value.0) * 100.0); - thumb_bg.0 = thumb_color(disabled, hovered.0); + thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging); } } } @@ -426,17 +428,25 @@ fn update_slider_style( } fn update_slider_style2( - sliders: Query<(Entity, &Hovered, Has), With>, + sliders: Query< + ( + Entity, + &Hovered, + &CoreSliderDragState, + Has, + ), + With, + >, children: Query<&Children>, mut thumbs: Query<(&mut BackgroundColor, Has), Without>, mut removed_disabled: RemovedComponents, ) { removed_disabled.read().for_each(|entity| { - if let Ok((slider_ent, hovered, disabled)) = sliders.get(entity) { + if let Ok((slider_ent, hovered, drag_state, disabled)) = sliders.get(entity) { for child in children.iter_descendants(slider_ent) { if let Ok((mut thumb_bg, is_thumb)) = thumbs.get_mut(child) { if is_thumb { - thumb_bg.0 = thumb_color(disabled, hovered.0); + thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging); } } }