1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibGUI: Make NumericInput work well in GML

- Register the widget
- Register property getters and setters
- Rename getters and setters to match the property names, as required by
  the GML compiler. The names min/max/value are chosen to match SpinBox.
- Prevent a crash when the minimum is less than the maximum (which can
  happen while editing the GML).
This commit is contained in:
Sam Atkins 2024-01-09 16:24:11 +00:00 committed by Sam Atkins
parent da349607a3
commit 5f0230a57e
3 changed files with 46 additions and 35 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -18,9 +19,12 @@ public:
Function<void(i64)> on_number_changed;
void set_min_number(i64 number);
void set_max_number(i64 number);
void set_current_number(i64 number, GUI::AllowCallback allow_callback = GUI::AllowCallback::Yes);
i64 min() const { return m_min; }
void set_min(i64 number);
i64 max() const { return m_max; }
void set_max(i64 number);
i64 value() const { return m_value; }
void set_value(i64 number, GUI::AllowCallback allow_callback = GUI::AllowCallback::Yes);
virtual void mousewheel_event(GUI::MouseEvent&) override;
@ -29,9 +33,9 @@ private:
void on_focus_lost();
bool m_needs_text_reset { false };
i64 m_current_number { 0 };
i64 m_min_number { NumericLimits<i64>::min() };
i64 m_max_number { NumericLimits<i64>::max() };
i64 m_value { 0 };
i64 m_min { NumericLimits<i64>::min() };
i64 m_max { NumericLimits<i64>::max() };
};
}