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

LibCore: Allow array-like rectangle specifications for rect properties

This allows rectangle specifications in the form [x, y, width, height],
which mirrors margin properties and is much more convenient than the
JSON object specifications that were allowed before. Those are still
allowed, of course.
This commit is contained in:
kleines Filmröllchen 2022-10-20 22:00:41 +02:00 committed by Andrew Kaster
parent 3b03077abb
commit 4777dc75c5

View file

@ -324,14 +324,22 @@ T* Object::find_descendant_of_type_named(String const& name) requires IsBaseOf<O
return rect_object; \
}, \
[this](auto& value) { \
if (!value.is_object()) \
return false; \
Gfx::IntRect rect; \
if (value.is_object()) { \
rect.set_x(value.as_object().get("x"sv).to_i32()); \
rect.set_y(value.as_object().get("y"sv).to_i32()); \
rect.set_width(value.as_object().get("width"sv).to_i32()); \
rect.set_height(value.as_object().get("height"sv).to_i32()); \
} else if (value.is_array() && value.as_array().size() == 4) { \
rect.set_x(value.as_array()[0].to_i32()); \
rect.set_y(value.as_array()[1].to_i32()); \
rect.set_width(value.as_array()[2].to_i32()); \
rect.set_height(value.as_array()[3].to_i32()); \
} else { \
return false; \
} \
setter(rect); \
\
return true; \
});