1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:57:42 +00:00

LibGUI+Userland: Improve error and font handling for InputBox

Adds fallible factories, ports DeprecatedString, and rebuilds the
layout to accomodate system font changes.
This commit is contained in:
thankyouverycool 2023-04-16 16:02:07 -04:00 committed by Andreas Kling
parent 9c2bcffe83
commit 02a9e5d3f6
19 changed files with 135 additions and 124 deletions

View file

@ -75,9 +75,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Word Length", [&](auto&) {
auto word_length = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);
auto word_length_string = DeprecatedString::number(word_length);
auto word_length_string = String::number(word_length).release_value_but_fixme_should_propagate_errors();
if (GUI::InputBox::show(window, word_length_string, "Word length:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_word_length = word_length_string.template to_uint();
auto maybe_word_length = AK::StringUtils::convert_to_uint(word_length_string);
if (!maybe_word_length.has_value() || maybe_word_length.value() < shortest_word || maybe_word_length.value() > longest_word) {
GUI::MessageBox::show(window, DeprecatedString::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord"sv);
return;
@ -90,9 +90,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
})));
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Number Of Guesses", [&](auto&) {
auto max_guesses = Config::read_i32("MasterWord"sv, ""sv, "max_guesses"sv, 5);
auto max_guesses_string = DeprecatedString::number(max_guesses);
auto max_guesses_string = String::number(max_guesses).release_value_but_fixme_should_propagate_errors();
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_max_guesses = max_guesses_string.template to_uint();
auto maybe_max_guesses = AK::StringUtils::convert_to_uint(max_guesses_string);
if (!maybe_max_guesses.has_value() || maybe_max_guesses.value() < 1 || maybe_max_guesses.value() > 20) {
GUI::MessageBox::show(window, "Please enter a number between 1 and 20."sv, "MasterWord"sv);
return;