mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-03-22 21:37:22 +00:00
This was regressed at some point though I never saw it working. Basically, while jump to slider works correctly it doesn't even get actioned. While the user is clicking the slider it's very likely that a buffer finishes playing and the callback for that changes the slider value. This means that the user click just gets lost. There's some additional weird behavior where values are lost in even more cases, so an additional fix that is needed is to store the slider value in the AutoSlider while we're dragging and apply it on mouse up.
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGUI/Slider.h>
|
|
|
|
class AutoSlider final : public GUI::Slider {
|
|
C_OBJECT(AutoSlider)
|
|
public:
|
|
~AutoSlider() override = default;
|
|
Function<void(int)> on_knob_released;
|
|
virtual void set_value(int value, GUI::AllowCallback allow_callback = GUI::AllowCallback::Yes) override
|
|
{
|
|
m_in_drag_value = value;
|
|
if (!knob_dragging() && !mouse_is_down())
|
|
GUI::Slider::set_value(value, allow_callback);
|
|
}
|
|
|
|
bool mouse_is_down() const { return m_mouse_is_down; }
|
|
|
|
private:
|
|
AutoSlider(Orientation orientation)
|
|
: GUI::Slider(orientation)
|
|
{
|
|
}
|
|
|
|
virtual void mousedown_event(GUI::MouseEvent& event) override
|
|
{
|
|
m_mouse_is_down = true;
|
|
GUI::Slider::mousedown_event(event);
|
|
}
|
|
|
|
virtual void mouseup_event(GUI::MouseEvent& event) override
|
|
{
|
|
m_mouse_is_down = false;
|
|
set_value(m_in_drag_value);
|
|
if (on_knob_released && is_enabled())
|
|
on_knob_released(value());
|
|
|
|
GUI::Slider::mouseup_event(event);
|
|
}
|
|
|
|
bool m_mouse_is_down { false };
|
|
// Keeps track of the value while we're dragging
|
|
int m_in_drag_value { 0 };
|
|
};
|