mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibGUI: Add page_step setting to AbstractSlider and use it in Slider
This makes clicking on the track of a GUI::Slider actually move the knob more than 1 value unit (assuming page_step > 1)
This commit is contained in:
parent
fa836a4dda
commit
3b445bc66a
Notes:
sideshowbarker
2024-07-19 00:22:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3b445bc66ac
@ -36,9 +36,11 @@ namespace GUI {
|
||||
AbstractSlider::AbstractSlider(Orientation orientation)
|
||||
: m_orientation(orientation)
|
||||
{
|
||||
REGISTER_INT_PROPERTY("value", value, set_value);
|
||||
REGISTER_INT_PROPERTY("min", min, set_min);
|
||||
REGISTER_INT_PROPERTY("max", max, set_max);
|
||||
REGISTER_INT_PROPERTY("step", step, set_step);
|
||||
REGISTER_INT_PROPERTY("page_step", page_step, set_page_step);
|
||||
REGISTER_ENUM_PROPERTY("orientation", this->orientation, set_orientation, Orientation,
|
||||
{ Orientation::Horizontal, "Horizontal" },
|
||||
{ Orientation::Vertical, "Vertical" });
|
||||
@ -56,6 +58,11 @@ void AbstractSlider::set_orientation(Orientation value)
|
||||
update();
|
||||
}
|
||||
|
||||
void AbstractSlider::set_page_step(int page_step)
|
||||
{
|
||||
m_page_step = AK::max(0, page_step);
|
||||
}
|
||||
|
||||
void AbstractSlider::set_range(int min, int max)
|
||||
{
|
||||
ASSERT(min <= max);
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
int min() const { return m_min; }
|
||||
int max() const { return m_max; }
|
||||
int step() const { return m_step; }
|
||||
int page_step() const { return m_page_step; }
|
||||
|
||||
void set_range(int min, int max);
|
||||
void set_value(int);
|
||||
@ -50,6 +51,7 @@ public:
|
||||
void set_min(int min) { set_range(min, max()); }
|
||||
void set_max(int max) { set_range(min(), max); }
|
||||
void set_step(int step) { m_step = step; }
|
||||
void set_page_step(int page_step);
|
||||
|
||||
Function<void(int)> on_value_changed;
|
||||
|
||||
@ -63,6 +65,7 @@ private:
|
||||
int m_min { 0 };
|
||||
int m_max { 100 };
|
||||
int m_step { 1 };
|
||||
int m_page_step { 10 };
|
||||
Orientation m_orientation { Orientation::Horizontal };
|
||||
};
|
||||
|
||||
|
@ -105,9 +105,9 @@ void Slider::mousedown_event(MouseEvent& event)
|
||||
return;
|
||||
} else {
|
||||
if (event.position().primary_offset_for_orientation(orientation()) > knob_rect().last_edge_for_orientation(orientation()))
|
||||
set_value(value() + 1);
|
||||
set_value(value() + page_step());
|
||||
else if (event.position().primary_offset_for_orientation(orientation()) < knob_rect().first_edge_for_orientation(orientation()))
|
||||
set_value(value() - 1);
|
||||
set_value(value() - page_step());
|
||||
}
|
||||
}
|
||||
return Widget::mousedown_event(event);
|
||||
|
Loading…
Reference in New Issue
Block a user