GMLCompiler+LibGUI: Add support for object properties and undo hack

Previously the GML compiler did not support object properties such as
`content_widget: @GUI::Widget{}` for GUI::ScrollableContainerWidget;
this commit adds support for such properties by simply calling
`set_<key>(<TProperty>&)` on the object.
This commit also removes the previous hack where
ScrollableContainerWidget was special-cased to have its singular child
used as the content widget; the only GML file using this behaviour was
also changed to be in line with 'proper' GML as handled by the GML
Playground.
This commit is contained in:
Ali Mohammad Pur 2024-04-23 12:02:13 +02:00 committed by Andrew Kaster
commit f3a4118aee
Notes: sideshowbarker 2024-07-16 22:24:48 +09:00
4 changed files with 55 additions and 5 deletions

View file

@ -188,6 +188,18 @@ public:
}
}
template<typename Callback>
void for_each_object_property(Callback callback) const
{
for (auto const& child : m_properties) {
if (is<KeyValuePair>(child)) {
auto const& property = static_cast<KeyValuePair const&>(*child);
if (is<Object>(property.value().ptr()))
callback(property.key(), static_ptr_cast<Object>(property.value()));
}
}
}
template<FallibleFunction<StringView, NonnullRefPtr<JsonValueNode>> Callback>
ErrorOr<void> try_for_each_property(Callback callback) const
{
@ -201,6 +213,19 @@ public:
return {};
}
template<FallibleFunction<StringView, NonnullRefPtr<Object>> Callback>
ErrorOr<void> try_for_each_object_property(Callback callback) const
{
for (auto const& child : m_properties) {
if (is<KeyValuePair>(child)) {
auto const& property = static_cast<KeyValuePair const&>(*child);
if (is<Object>(property.value().ptr()))
TRY(callback(property.key(), static_ptr_cast<Object>(property.value())));
}
}
return {};
}
template<typename Callback>
void for_each_child_object(Callback callback) const
{