mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:37:34 +00:00
LibGUI: Add layout spacer support to GML
This is a bit of a hack, but it is an easy way to finally get spacers into GML. This will translate well if spacers are later to become child objects of the continer widget.
This commit is contained in:
parent
d1d5602132
commit
8081a8a5de
13 changed files with 106 additions and 99 deletions
|
@ -1131,27 +1131,36 @@ bool Widget::load_from_gml_ast(NonnullRefPtr<GUI::GML::Node> ast, RefPtr<Core::O
|
|||
object->for_each_child_object_interruptible([&](auto child_data) {
|
||||
auto class_name = child_data->name();
|
||||
|
||||
RefPtr<Core::Object> child;
|
||||
if (auto* registration = Core::ObjectClassRegistration::find(class_name)) {
|
||||
child = registration->construct();
|
||||
if (!child || !registration->is_derived_from(widget_class)) {
|
||||
dbgln("Invalid widget class: '{}'", class_name);
|
||||
// It is very questionable if this pseudo object should exist, but it works fine like this for now.
|
||||
if (class_name == "GUI::Layout::Spacer") {
|
||||
if (!this->layout()) {
|
||||
dbgln("Specified GUI::Layout::Spacer in GML, but the parent has no Layout.");
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
this->layout()->add_spacer();
|
||||
} else {
|
||||
child = unregistered_child_handler(class_name);
|
||||
}
|
||||
if (!child)
|
||||
return IterationDecision::Break;
|
||||
RefPtr<Core::Object> child;
|
||||
if (auto* registration = Core::ObjectClassRegistration::find(class_name)) {
|
||||
child = registration->construct();
|
||||
if (!child || !registration->is_derived_from(widget_class)) {
|
||||
dbgln("Invalid widget class: '{}'", class_name);
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
} else {
|
||||
child = unregistered_child_handler(class_name);
|
||||
}
|
||||
if (!child)
|
||||
return IterationDecision::Break;
|
||||
add_child(*child);
|
||||
|
||||
add_child(*child);
|
||||
// This is possible as we ensure that Widget is a base class above.
|
||||
static_ptr_cast<Widget>(child)->load_from_gml_ast(child_data, unregistered_child_handler);
|
||||
// This is possible as we ensure that Widget is a base class above.
|
||||
static_ptr_cast<Widget>(child)->load_from_gml_ast(child_data, unregistered_child_handler);
|
||||
|
||||
if (is_tab_widget) {
|
||||
// FIXME: We need to have the child added before loading it so that it can access us. But the TabWidget logic requires the child to not be present yet.
|
||||
remove_child(*child);
|
||||
reinterpret_cast<TabWidget*>(this)->add_widget(*static_ptr_cast<Widget>(child));
|
||||
if (is_tab_widget) {
|
||||
// FIXME: We need to have the child added before loading it so that it can access us. But the TabWidget logic requires the child to not be present yet.
|
||||
remove_child(*child);
|
||||
reinterpret_cast<TabWidget*>(this)->add_widget(*static_ptr_cast<Widget>(child));
|
||||
}
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue