From: rexim Date: Sat, 20 Jul 2019 18:51:29 +0000 (+0700) Subject: (#892) Make slider correctly identify its changes X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=525b52343e0fda598fbc7089e9b9574e9636c4df;hp=abb5e559db536b2a3e7a3777bb89c52404d2aadc;p=nothing.git (#892) Make slider correctly identify its changes --- diff --git a/src/ui/slider.c b/src/ui/slider.c index a66576d7..8a0fb76d 100644 --- a/src/ui/slider.c +++ b/src/ui/slider.c @@ -39,28 +39,36 @@ int slider_event(Slider *slider, const SDL_Event *event, Rect boundary, int *sel trace_assert(slider); trace_assert(event); - switch (event->type) { - case SDL_MOUSEBUTTONDOWN: { - Point position = vec((float) event->button.x, (float) event->button.y); - if (rect_contains_point(boundary, position)) { - slider->drag = 1; + if (!slider->drag) { + switch (event->type) { + case SDL_MOUSEBUTTONDOWN: { + Point position = vec((float) event->button.x, (float) event->button.y); + if (rect_contains_point(boundary, position)) { + slider->drag = 1; + if (selected) { + *selected = 1; + } + } + } break; + } + } else { + switch (event->type) { + case SDL_MOUSEBUTTONUP: { + slider->drag = 0; if (selected) { *selected = 1; } - } - } break; - - case SDL_MOUSEBUTTONUP: { - slider->drag = 0; - } break; + } break; - case SDL_MOUSEMOTION: { - if (slider->drag) { + case SDL_MOUSEMOTION: { const float x = fminf(fmaxf((float) event->button.x - boundary.x, 0.0f), (float) boundary.w); const float ratio = x / (float) boundary.w; slider->value = ratio * slider->max_value; + if (selected) { + *selected = 1; + } + } break; } - } break; } return 0;