Skip to content
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

Emit slider's drag_started signal before the first value change #86377

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion doc/classes/Slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</signal>
<signal name="drag_started">
<description>
Emitted when dragging is started.
Emitted when dragging is started. This is emitted before the corresponding [signal Range.value_changed] signal.
</description>
</signal>
</signals>
Expand Down
5 changes: 3 additions & 2 deletions scene/gui/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
}

grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;
grab.value_before_dragging = get_as_ratio();
emit_signal(SNAME("drag_started"));

double grab_width = (double)grabber->get_width();
double grab_height = (double)grabber->get_height();
Expand All @@ -78,12 +80,11 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
grab.active = true;
grab.uvalue = get_as_ratio();

emit_signal(SNAME("drag_started"));
_notify_shared_value_changed();
} else {
grab.active = false;

const bool value_changed = !Math::is_equal_approx((double)grab.uvalue, get_as_ratio());
const bool value_changed = !Math::is_equal_approx((double)grab.value_before_dragging, get_as_ratio());
emit_signal(SNAME("drag_ended"), value_changed);
}
} else if (scrollable) {
Expand Down
3 changes: 2 additions & 1 deletion scene/gui/slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Slider : public Range {

struct Grab {
int pos = 0;
double uvalue = 0.0;
double uvalue = 0.0; // Value at `pos`.
double value_before_dragging = 0.0;
bool active = false;
} grab;

Expand Down
Loading