diff --git a/Userland/Libraries/LibGUI/UIDimensions.h b/Userland/Libraries/LibGUI/UIDimensions.h index 97eba9de55b..f1beab0991c 100644 --- a/Userland/Libraries/LibGUI/UIDimensions.h +++ b/Userland/Libraries/LibGUI/UIDimensions.h @@ -285,6 +285,13 @@ inline auto clamp(GUI::UIDimension const& input, GUI::UIDimens return result.has_value(); \ }); +#define REGISTER_READONLY_UI_DIMENSION_PROPERTY(property_name, getter) \ + register_property( \ + property_name, \ + [this] { \ + return this->getter().as_json_value(); \ + }); + #define REGISTER_UI_SIZE_PROPERTY(property_name, getter, setter) \ register_property( \ property_name, \ @@ -309,3 +316,14 @@ inline auto clamp(GUI::UIDimension const& input, GUI::UIDimens } \ return false; \ }); + +#define REGISTER_READONLY_UI_SIZE_PROPERTY(property_name, getter) \ + 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; \ + }); diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 3c8a8262b34..e605bfca30b 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -50,8 +50,10 @@ Widget::Widget() REGISTER_STRING_PROPERTY("tooltip", tooltip, set_tooltip); REGISTER_UI_SIZE_PROPERTY("min_size", min_size, set_min_size); + REGISTER_READONLY_UI_SIZE_PROPERTY("effective_min_size", effective_min_size); REGISTER_UI_SIZE_PROPERTY("max_size", max_size, set_max_size); REGISTER_UI_SIZE_PROPERTY("preferred_size", preferred_size, set_preferred_size); + REGISTER_READONLY_UI_SIZE_PROPERTY("effective_preferred_size", effective_preferred_size); REGISTER_INT_PROPERTY("width", width, set_width); REGISTER_UI_DIMENSION_PROPERTY("min_width", min_width, set_min_width); REGISTER_UI_DIMENSION_PROPERTY("max_width", max_width, set_max_width);