mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:37:45 +00:00
Calculator: Add a "Custom" entry to the rounding menu
This entry pop a dialog to ask the user to enter a value. The Calculator will automatically put itself in this mode if you enter a number with more digits in the fractional part than the actual maximum length.
This commit is contained in:
parent
de568f87fd
commit
e3b22c395d
8 changed files with 157 additions and 10 deletions
71
Userland/Applications/Calculator/RoundingDialog.cpp
Normal file
71
Userland/Applications/Calculator/RoundingDialog.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Lucas Chollet <lucas.chollet@free.fr>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "RoundingDialog.h"
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/SpinBox.h>
|
||||
#include <LibGUI/TextEditor.h>
|
||||
|
||||
RoundingDialog::ExecResult RoundingDialog::show(GUI::Window* parent_window, unsigned& rounding_value)
|
||||
{
|
||||
auto dialog = RoundingDialog::construct(parent_window);
|
||||
|
||||
if (parent_window) {
|
||||
dialog->set_icon(parent_window->icon());
|
||||
dialog->center_within(*parent_window);
|
||||
}
|
||||
|
||||
dialog->m_rounding_spinbox->set_value(rounding_value);
|
||||
|
||||
auto const result = dialog->exec();
|
||||
|
||||
if (result != GUI::Dialog::ExecResult::OK)
|
||||
return result;
|
||||
|
||||
rounding_value = dialog->m_rounding_spinbox->value();
|
||||
|
||||
return GUI::Dialog::ExecResult::OK;
|
||||
}
|
||||
|
||||
RoundingDialog::RoundingDialog(GUI::Window* parent_window)
|
||||
: Dialog(parent_window)
|
||||
{
|
||||
resize(m_dialog_length, m_dialog_height);
|
||||
set_resizable(false);
|
||||
set_title("Choose custom rounding");
|
||||
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
m_rounding_spinbox = GUI::SpinBox::construct();
|
||||
m_buttons_container = GUI::Widget::construct();
|
||||
m_ok_button = GUI::DialogButton::construct("OK");
|
||||
m_cancel_button = GUI::DialogButton::construct("Cancel");
|
||||
|
||||
main_widget.add_child(*m_rounding_spinbox);
|
||||
main_widget.add_child(*m_buttons_container);
|
||||
|
||||
m_buttons_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
m_buttons_container->layout()->add_spacer();
|
||||
m_buttons_container->add_child(*m_ok_button);
|
||||
m_buttons_container->add_child(*m_cancel_button);
|
||||
|
||||
m_rounding_spinbox->on_return_pressed = [this] {
|
||||
m_ok_button->click();
|
||||
};
|
||||
|
||||
m_ok_button->on_click = [this](auto) {
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue