1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibCore+LibGUI: Add fallible versions of Widget::load_from_gml()

The existing `load_from_gml()` methods look the same as before from the
outside. Inside though, they now forward to `try_load_from_gml()` which
returns Error when things go wrong. It also now calls the `try_create()`
factory method for Objects instead of the `construct()` one.
This commit is contained in:
Sam Atkins 2022-12-28 20:35:16 +00:00 committed by Tim Flynn
parent e58fe1cdd7
commit b32f5dbcff
8 changed files with 73 additions and 69 deletions

View file

@ -202,18 +202,18 @@ public:
}
}
// Uses IterationDecision to allow the callback to interrupt the iteration, like a for-loop break.
template<IteratorFunction<NonnullRefPtr<Object>> Callback>
void for_each_child_object_interruptible(Callback callback)
template<FallibleFunction<NonnullRefPtr<Object>> Callback>
ErrorOr<void> try_for_each_child_object(Callback callback)
{
for (NonnullRefPtr<Node> child : m_sub_objects) {
// doesn't capture layout as intended, as that's behind a kv-pair
if (is<Object>(child.ptr())) {
auto object = static_ptr_cast<Object>(child);
if (callback(object) == IterationDecision::Break)
return;
TRY(callback(object));
}
}
return {};
}
RefPtr<Object> layout_object() const