mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 02:48:11 +00: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
3 changed files with 12 additions and 2 deletions
|
@ -36,9 +36,11 @@ namespace GUI {
|
||||||
AbstractSlider::AbstractSlider(Orientation orientation)
|
AbstractSlider::AbstractSlider(Orientation orientation)
|
||||||
: m_orientation(orientation)
|
: m_orientation(orientation)
|
||||||
{
|
{
|
||||||
|
REGISTER_INT_PROPERTY("value", value, set_value);
|
||||||
REGISTER_INT_PROPERTY("min", min, set_min);
|
REGISTER_INT_PROPERTY("min", min, set_min);
|
||||||
REGISTER_INT_PROPERTY("max", max, set_max);
|
REGISTER_INT_PROPERTY("max", max, set_max);
|
||||||
REGISTER_INT_PROPERTY("step", step, set_step);
|
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,
|
REGISTER_ENUM_PROPERTY("orientation", this->orientation, set_orientation, Orientation,
|
||||||
{ Orientation::Horizontal, "Horizontal" },
|
{ Orientation::Horizontal, "Horizontal" },
|
||||||
{ Orientation::Vertical, "Vertical" });
|
{ Orientation::Vertical, "Vertical" });
|
||||||
|
@ -56,6 +58,11 @@ void AbstractSlider::set_orientation(Orientation value)
|
||||||
update();
|
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)
|
void AbstractSlider::set_range(int min, int max)
|
||||||
{
|
{
|
||||||
ASSERT(min <= max);
|
ASSERT(min <= max);
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
int min() const { return m_min; }
|
int min() const { return m_min; }
|
||||||
int max() const { return m_max; }
|
int max() const { return m_max; }
|
||||||
int step() const { return m_step; }
|
int step() const { return m_step; }
|
||||||
|
int page_step() const { return m_page_step; }
|
||||||
|
|
||||||
void set_range(int min, int max);
|
void set_range(int min, int max);
|
||||||
void set_value(int);
|
void set_value(int);
|
||||||
|
@ -50,6 +51,7 @@ public:
|
||||||
void set_min(int min) { set_range(min, max()); }
|
void set_min(int min) { set_range(min, max()); }
|
||||||
void set_max(int max) { set_range(min(), max); }
|
void set_max(int max) { set_range(min(), max); }
|
||||||
void set_step(int step) { m_step = step; }
|
void set_step(int step) { m_step = step; }
|
||||||
|
void set_page_step(int page_step);
|
||||||
|
|
||||||
Function<void(int)> on_value_changed;
|
Function<void(int)> on_value_changed;
|
||||||
|
|
||||||
|
@ -63,6 +65,7 @@ private:
|
||||||
int m_min { 0 };
|
int m_min { 0 };
|
||||||
int m_max { 100 };
|
int m_max { 100 };
|
||||||
int m_step { 1 };
|
int m_step { 1 };
|
||||||
|
int m_page_step { 10 };
|
||||||
Orientation m_orientation { Orientation::Horizontal };
|
Orientation m_orientation { Orientation::Horizontal };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -105,9 +105,9 @@ void Slider::mousedown_event(MouseEvent& event)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (event.position().primary_offset_for_orientation(orientation()) > knob_rect().last_edge_for_orientation(orientation()))
|
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()))
|
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);
|
return Widget::mousedown_event(event);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue