Skip to content

core_widgets example slider fix #19810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions examples/ui/core_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -398,13 +398,15 @@ fn update_slider_style(
&SliderValue,
&SliderRange,
&Hovered,
&CoreSliderDragState,
Has<InteractionDisabled>,
),
(
Or<(
Changed<SliderValue>,
Changed<SliderRange>,
Changed<Hovered>,
Changed<CoreSliderDragState>,
Added<InteractionDisabled>,
)>,
With<DemoSlider>,
Expand All @@ -413,30 +415,38 @@ fn update_slider_style(
children: Query<&Children>,
mut thumbs: Query<(&mut Node, &mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
) {
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);
}
}
}
}
}

fn update_slider_style2(
sliders: Query<(Entity, &Hovered, Has<InteractionDisabled>), With<DemoSlider>>,
sliders: Query<
(
Entity,
&Hovered,
&CoreSliderDragState,
Has<InteractionDisabled>,
),
With<DemoSlider>,
>,
children: Query<&Children>,
mut thumbs: Query<(&mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
mut removed_disabled: RemovedComponents<InteractionDisabled>,
) {
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);
}
}
}
Expand Down