mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibGUI: Make Layout a Core::Object and add basic serialization
This allows you to view layouts (as data) in Inspector.
This commit is contained in:
parent
ecc39678f5
commit
849fdc1c0b
8 changed files with 66 additions and 13 deletions
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <LibGUI/Layout.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
|
@ -120,4 +121,32 @@ void Layout::set_margins(const Margins& margins)
|
|||
m_owner->notify_layout_changed({});
|
||||
}
|
||||
|
||||
void Layout::save_to(JsonObject& json)
|
||||
{
|
||||
Core::Object::save_to(json);
|
||||
json.set("spacing", m_spacing);
|
||||
|
||||
JsonObject margins_object;
|
||||
margins_object.set("left", m_margins.left());
|
||||
margins_object.set("right", m_margins.right());
|
||||
margins_object.set("top", m_margins.top());
|
||||
margins_object.set("bottom", m_margins.bottom());
|
||||
json.set("margins", move(margins_object));
|
||||
|
||||
JsonArray entries_array;
|
||||
for (auto& entry : m_entries) {
|
||||
JsonObject entry_object;
|
||||
if (entry.type == Entry::Type::Widget) {
|
||||
entry_object.set("type", "Widget");
|
||||
entry_object.set("widget", (uintptr_t)entry.widget.ptr());
|
||||
} else if (entry.type == Entry::Type::Spacer) {
|
||||
entry_object.set("type", "Spacer");
|
||||
} else {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
entries_array.append(move(entry_object));
|
||||
}
|
||||
json.set("entries", move(entries_array));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue