mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:55:09 +00:00
LibGUI: Dynamically process layouts from GML files
There are only two layouts at the moment, but that could (and probably will) change in the future. Why limit ourselves by hardcoding these checks when we can do it dynamically instead?
This commit is contained in:
parent
03b52e26f0
commit
eb3ca64819
1 changed files with 8 additions and 4 deletions
|
@ -1090,10 +1090,14 @@ bool Widget::load_from_json(const JsonObject& json, RefPtr<Core::Object> (*unreg
|
|||
return false;
|
||||
}
|
||||
|
||||
if (class_name.to_string() == "GUI::VerticalBoxLayout") {
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
} else if (class_name.to_string() == "GUI::HorizontalBoxLayout") {
|
||||
set_layout<GUI::HorizontalBoxLayout>();
|
||||
auto& layout_class = *Core::ObjectClassRegistration::find("GUI::Layout");
|
||||
if (auto* registration = Core::ObjectClassRegistration::find(class_name.as_string())) {
|
||||
auto layout = registration->construct();
|
||||
if (!layout || !registration->is_derived_from(layout_class)) {
|
||||
dbgln("Invalid layout class: '{}'", class_name.to_string());
|
||||
return false;
|
||||
}
|
||||
set_layout(static_ptr_cast<Layout>(layout).release_nonnull());
|
||||
} else {
|
||||
dbgln("Unknown layout class: '{}'", class_name.to_string());
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue