mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
LibGUI: Improve SpinBox usability
Previously the value of the SpinBox is re-evaluated after every change to the TextBox control. This leads to very unintuitive behavior such as the user deleting the contents of the box and it having no visible effect. This happens because the TextBox no longer has a valid number and so gets reset to the current m_value of the SpinBox. By defering the update of to the SpinBox value until focus leaves the control we provide a much more intuitive experience with the text box. We do still validate when a user types something that it parses to an int. If it does not we delete the most recent character. This in effect prevents non-numeric numbers from being entered. Upon losing focus the value will be checked. If empty we set the SpinBox value to the minimum allowed value.
This commit is contained in:
parent
1183bc5184
commit
e43e412fc8
1 changed files with 7 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -24,10 +25,15 @@ SpinBox::SpinBox()
|
|||
return;
|
||||
|
||||
auto value = m_editor->text().to_uint();
|
||||
if (!value.has_value() && m_editor->text().length() > 0)
|
||||
m_editor->do_delete();
|
||||
};
|
||||
m_editor->on_focusout = [this] {
|
||||
auto value = m_editor->text().to_int();
|
||||
if (value.has_value())
|
||||
set_value(value.value());
|
||||
else
|
||||
m_editor->set_text(String::number(m_value));
|
||||
set_value(min());
|
||||
};
|
||||
m_editor->on_up_pressed = [this] {
|
||||
set_value(m_value + 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue