mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-18 13:44:50 +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:
committed by
Jelle Raaijmakers
parent
d385adf6bd
commit
e2dbce8fd7
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <initializer_list>
|
||||
@@ -148,6 +149,23 @@ public:
|
||||
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)
|
||||
{
|
||||
if (value.is_string()) {
|
||||
|
||||
Reference in New Issue
Block a user