Skip to content

Commit

Permalink
Calculator: Accept more keyboard input (SerenityOS#1207)
Browse files Browse the repository at this point in the history
Allow user to clear/remove last numeral from input (Esc/Backspace
respectively) and type the decimal point.
  • Loading branch information
ignas-sa committed Feb 10, 2020
1 parent 077ef55 commit b67035c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Applications/Calculator/CalculatorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ void CalculatorWidget::keydown_event(GUI::KeyEvent& event)
} else if (event.key() >= KeyCode::Key_0 && event.key() <= KeyCode::Key_9) {
m_keypad.type_digit(atoi(event.text().characters()));

} else if (event.key() == KeyCode::Key_Period) {
m_keypad.type_decimal_point();

} else if (event.key() == KeyCode::Key_Escape) {
m_keypad.set_value(0.0);
m_calculator.clear_operation();

} else if (event.key() == KeyCode::Key_Backspace) {
m_keypad.type_backspace();

} else {
Calculator::Operation operation;

Expand Down Expand Up @@ -263,4 +273,4 @@ void CalculatorWidget::keydown_event(GUI::KeyEvent& event)
}

update_display();
}
}

0 comments on commit b67035c

Please sign in to comment.