mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
LibGUI: Introduce UIDimension properties
This commit is contained in:
parent
b47bf2fd7c
commit
a4aced7f3a
2 changed files with 44 additions and 6 deletions
|
@ -288,3 +288,41 @@ inline auto clamp<GUI::UIDimension>(GUI::UIDimension const& input, GUI::UIDimens
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#define REGISTER_UI_DIMENSION_PROPERTY(property_name, getter, setter) \
|
||||
register_property( \
|
||||
property_name, \
|
||||
[this] { \
|
||||
return this->getter().as_json_value(); \
|
||||
}, \
|
||||
[this](auto& value) { \
|
||||
auto result = GUI::UIDimension::construct_from_json_value(value); \
|
||||
if (result.has_value()) \
|
||||
this->setter(result.value()); \
|
||||
return result.has_value(); \
|
||||
});
|
||||
|
||||
#define REGISTER_UI_SIZE_PROPERTY(property_name, getter, setter) \
|
||||
register_property( \
|
||||
property_name, \
|
||||
[this] { \
|
||||
auto size = this->getter(); \
|
||||
JsonObject size_object; \
|
||||
size_object.set("width", size.width().as_json_value()); \
|
||||
size_object.set("height", size.height().as_json_value()); \
|
||||
return size_object; \
|
||||
}, \
|
||||
[this](auto& value) { \
|
||||
if (!value.is_object()) \
|
||||
return false; \
|
||||
auto result_width = GUI::UIDimension::construct_from_json_value( \
|
||||
value.as_object().get("width")); \
|
||||
auto result_height = GUI::UIDimension::construct_from_json_value( \
|
||||
value.as_object().get("height")); \
|
||||
if (result_width.has_value() && result_height.has_value()) { \
|
||||
GUI::UISize size(result_width.value(), result_height.value()); \
|
||||
setter(size); \
|
||||
return true; \
|
||||
} \
|
||||
return false; \
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue