mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibGUI: Allow generating C++ "constructor" code for UIDimension
This will be used in the proper GML generator to initialize UI dimension properties.
This commit is contained in:
parent
d385adf6bd
commit
e2dbce8fd7
1 changed files with 18 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
@ -148,6 +149,23 @@ public:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The returned source code, if any, can be used to construct this UIDimension in C++.
|
||||||
|
ErrorOr<String> as_cpp_source() const
|
||||||
|
{
|
||||||
|
String value_source = {};
|
||||||
|
if (is_int())
|
||||||
|
value_source = TRY(String::number(m_value));
|
||||||
|
else if (is_shrink())
|
||||||
|
value_source = TRY(String::from_utf8("GUI::SpecialDimension::Shrink"sv));
|
||||||
|
else if (is_grow())
|
||||||
|
value_source = TRY(String::from_utf8("GUI::SpecialDimension::Grow"sv));
|
||||||
|
else if (is_opportunistic_grow())
|
||||||
|
value_source = TRY(String::from_utf8("GUI::SpecialDimension::OpportunisticGrow"sv));
|
||||||
|
else if (is_fit())
|
||||||
|
value_source = TRY(String::from_utf8("GUI::SpecialDimension::Fit"sv));
|
||||||
|
return String::formatted("GUI::UIDimension {{ {} }}", value_source);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static Optional<UIDimension> construct_from_json_value(AK::JsonValue const value)
|
[[nodiscard]] static Optional<UIDimension> construct_from_json_value(AK::JsonValue const value)
|
||||||
{
|
{
|
||||||
if (value.is_string()) {
|
if (value.is_string()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue