summaryrefslogtreecommitdiff
path: root/Userland/Applications/Calculator/main.cpp
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2022-01-16 22:45:09 +0100
committerTim Flynn <trflynn89@pm.me>2022-10-03 15:12:47 -0400
commit2ff773a6ba4b8ab81bf1f2eacc180a666a2ea204 (patch)
treef27d65c9fd62c10b57aa4d2e4384999b7f23b8c8 /Userland/Applications/Calculator/main.cpp
parente3b22c395d7bef1897284f88ae0bacc77a8659a9 (diff)
downloadserenity-2ff773a6ba4b8ab81bf1f2eacc180a666a2ea204.zip
Calculator: Add a Shrinking action
This action allow the user to shrink a number to a finite number of decimal.
Diffstat (limited to 'Userland/Applications/Calculator/main.cpp')
-rw-r--r--Userland/Applications/Calculator/main.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Applications/Calculator/main.cpp b/Userland/Applications/Calculator/main.cpp
index 3a8750b338..4b6b7802e9 100644
--- a/Userland/Applications/Calculator/main.cpp
+++ b/Userland/Applications/Calculator/main.cpp
@@ -92,7 +92,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto round_custom = GUI::Action::create_checkable(String::formatted(format, 0), [&](auto& action) {
unsigned custom_rounding_length = widget->rounding_length();
- if (RoundingDialog::show(window, custom_rounding_length) == GUI::Dialog::ExecResult::OK) {
+ if (RoundingDialog::show(window, "Choose custom rounding"sv, custom_rounding_length) == GUI::Dialog::ExecResult::OK) {
action.set_text(String::formatted(format, custom_rounding_length));
widget->set_rounding_length(custom_rounding_length);
last_rounding_mode.clear();
@@ -102,9 +102,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
widget->set_rounding_custom(round_custom, format);
+ auto shrink_action = GUI::Action::create("&Shrink...", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-cut.png"sv)), [&](auto&) {
+ unsigned shrink_length = widget->rounding_length();
+
+ if (RoundingDialog::show(window, "Choose shrinking length"sv, shrink_length) == GUI::Dialog::ExecResult::OK) {
+ round_custom->set_checked(true);
+ round_custom->set_text(String::formatted(format, shrink_length));
+ widget->set_rounding_length(shrink_length);
+ widget->shrink(shrink_length);
+ }
+ });
+
preview_actions.add_action(*round_custom);
preview_actions.set_exclusive(true);
round_menu.add_action(*round_custom);
+ round_menu.add_action(*shrink_action);
round_menu.action_at(last_rounding_mode.value())->activate();