Skip to content

Commit 6687279

Browse files
authored
Emit slider drag value change only when value changes (#21404)
# Objective Fixes #21376 ## Solution Just check if the value has changed with an `if`. The issue mentions `.set_if_neq` but I'm not sure if it's relevant as `slider_on_drag` doesn't directly change the component value but emits an event. ## Testing Checked on the feathers example: https://github.com/user-attachments/assets/ac5bb2fa-9054-4eed-985f-846ac15f310d
1 parent 6e73646 commit 6687279

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

crates/bevy_ui_widgets/src/slider.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ pub(crate) fn slider_on_drag(
330330
mut event: On<Pointer<Drag>>,
331331
mut q_slider: Query<
332332
(
333+
&SliderValue,
333334
&ComputedNode,
334335
&SliderRange,
335336
Option<&SliderPrecision>,
@@ -344,7 +345,8 @@ pub(crate) fn slider_on_drag(
344345
mut commands: Commands,
345346
ui_scale: Res<UiScale>,
346347
) {
347-
if let Ok((node, range, precision, transform, drag, disabled)) = q_slider.get_mut(event.entity)
348+
if let Ok((value, node, range, precision, transform, drag, disabled)) =
349+
q_slider.get_mut(event.entity)
348350
{
349351
event.propagate(false);
350352
if drag.dragging && !disabled {
@@ -369,10 +371,12 @@ pub(crate) fn slider_on_drag(
369371
.unwrap_or(new_value),
370372
);
371373

372-
commands.trigger(ValueChange {
373-
source: event.entity,
374-
value: rounded_value,
375-
});
374+
if rounded_value != value.0 {
375+
commands.trigger(ValueChange {
376+
source: event.entity,
377+
value: rounded_value,
378+
});
379+
}
376380
}
377381
}
378382
}

0 commit comments

Comments
 (0)