Skip to content

Commit

Permalink
LibGUI: Use on_up_pressed/on_down_pressed events in SpinBox
Browse files Browse the repository at this point in the history
Fixes keyboard increment/decrement of SpinBox values.

After PR SerenityOS#2412 the TextBox class started not propagating arrow key
events to the parent widgets because it handles them itself now.
It also added two new events for these arrow keys, so use them instead
in SpinBox.
  • Loading branch information
xTibor authored and awesomekling committed Sep 23, 2020
1 parent 5eefce1 commit 1fa5a52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
20 changes: 6 additions & 14 deletions Libraries/LibGUI/SpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ SpinBox::SpinBox()
else
m_editor->set_text(String::number(m_value));
};
m_editor->on_up_pressed = [this] {
set_value(m_value + 1);
};
m_editor->on_down_pressed = [this] {
set_value(m_value - 1);
};

m_increment_button = add<ControlBoxButton>(ControlBoxButton::UpArrow);
m_increment_button->set_focusable(false);
Expand Down Expand Up @@ -88,20 +94,6 @@ void SpinBox::set_range(int min, int max)
update();
}

void SpinBox::keydown_event(KeyEvent& event)
{
if (event.key() == KeyCode::Key_Up) {
set_value(m_value + 1);
return;
}
if (event.key() == KeyCode::Key_Down) {
set_value(m_value - 1);
return;
}

event.ignore();
}

void SpinBox::mousewheel_event(MouseEvent& event)
{
set_value(m_value - event.wheel_delta());
Expand Down
1 change: 0 additions & 1 deletion Libraries/LibGUI/SpinBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class SpinBox : public Widget {
protected:
SpinBox();

virtual void keydown_event(KeyEvent&) override;
virtual void mousewheel_event(MouseEvent&) override;
virtual void resize_event(ResizeEvent&) override;

Expand Down

0 comments on commit 1fa5a52

Please sign in to comment.