Skip to content

Commit 3b445bc

Browse files
committed
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)
1 parent fa836a4 commit 3b445bc

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Libraries/LibGUI/AbstractSlider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ namespace GUI {
3636
AbstractSlider::AbstractSlider(Orientation orientation)
3737
: m_orientation(orientation)
3838
{
39+
REGISTER_INT_PROPERTY("value", value, set_value);
3940
REGISTER_INT_PROPERTY("min", min, set_min);
4041
REGISTER_INT_PROPERTY("max", max, set_max);
4142
REGISTER_INT_PROPERTY("step", step, set_step);
43+
REGISTER_INT_PROPERTY("page_step", page_step, set_page_step);
4244
REGISTER_ENUM_PROPERTY("orientation", this->orientation, set_orientation, Orientation,
4345
{ Orientation::Horizontal, "Horizontal" },
4446
{ Orientation::Vertical, "Vertical" });
@@ -56,6 +58,11 @@ void AbstractSlider::set_orientation(Orientation value)
5658
update();
5759
}
5860

61+
void AbstractSlider::set_page_step(int page_step)
62+
{
63+
m_page_step = AK::max(0, page_step);
64+
}
65+
5966
void AbstractSlider::set_range(int min, int max)
6067
{
6168
ASSERT(min <= max);

Libraries/LibGUI/AbstractSlider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ class AbstractSlider : public Widget {
4343
int min() const { return m_min; }
4444
int max() const { return m_max; }
4545
int step() const { return m_step; }
46+
int page_step() const { return m_page_step; }
4647

4748
void set_range(int min, int max);
4849
void set_value(int);
4950

5051
void set_min(int min) { set_range(min, max()); }
5152
void set_max(int max) { set_range(min(), max); }
5253
void set_step(int step) { m_step = step; }
54+
void set_page_step(int page_step);
5355

5456
Function<void(int)> on_value_changed;
5557

@@ -63,6 +65,7 @@ class AbstractSlider : public Widget {
6365
int m_min { 0 };
6466
int m_max { 100 };
6567
int m_step { 1 };
68+
int m_page_step { 10 };
6669
Orientation m_orientation { Orientation::Horizontal };
6770
};
6871

Libraries/LibGUI/Slider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ void Slider::mousedown_event(MouseEvent& event)
105105
return;
106106
} else {
107107
if (event.position().primary_offset_for_orientation(orientation()) > knob_rect().last_edge_for_orientation(orientation()))
108-
set_value(value() + 1);
108+
set_value(value() + page_step());
109109
else if (event.position().primary_offset_for_orientation(orientation()) < knob_rect().first_edge_for_orientation(orientation()))
110-
set_value(value() - 1);
110+
set_value(value() - page_step());
111111
}
112112
}
113113
return Widget::mousedown_event(event);

0 commit comments

Comments
 (0)