mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00:00
LibGUI: Introduce GML - a simple GUI Markup Language :^)
This patch replaces the UI-from-JSON mechanism with a more
human-friendly DSL.
The current implementation simply converts the GML into a JSON object
that can be consumed by GUI::Widget::load_from_json(). The parser is
not very helpful if you make a mistake.
The language offers a very simple way to instantiate any registered
Core::Object class by simply saying @ClassName
@GUI::Label {
text: "Hello friends!"
tooltip: ":^)"
}
Layouts are Core::Objects and can be assigned to the "layout" property:
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
spacing: 2
margins: [8, 8, 8, 8]
}
}
And finally, child objects are simply nested within their parent:
@GUI::Widget {
layout: @GUI::HorizontalBoxLayout {
}
@GUI::Button {
text: "OK"
}
@GUI::Button {
text: "Cancel"
}
}
This feels a *lot* more pleasant to write than the JSON we had. The fact
that no new code was being written with the JSON mechanism was pretty
telling, so let's approach this with developer convenience in mind. :^)
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/ColorInput.h>
|
||||
#include <LibGUI/Event.h>
|
||||
#include <LibGUI/GMLParser.h>
|
||||
#include <LibGUI/GroupBox.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Layout.h>
|
||||
@@ -926,18 +927,11 @@ void Widget::set_override_cursor(Gfx::StandardCursor cursor)
|
||||
window->update_cursor({});
|
||||
}
|
||||
|
||||
bool Widget::load_from_json(const StringView& json_string)
|
||||
bool Widget::load_from_gml(const StringView& gml_string)
|
||||
{
|
||||
auto json_value = JsonValue::from_string(json_string);
|
||||
if (!json_value.has_value()) {
|
||||
dbg() << "load_from_json parse failed: _" << json_string << "_";
|
||||
return false;
|
||||
}
|
||||
if (!json_value.value().is_object()) {
|
||||
dbg() << "load_from_json parse non-object";
|
||||
return false;
|
||||
}
|
||||
return load_from_json(json_value.value().as_object());
|
||||
auto value = parse_gml(gml_string);
|
||||
ASSERT(value.is_object());
|
||||
return load_from_json(value.as_object());
|
||||
}
|
||||
|
||||
bool Widget::load_from_json(const JsonObject& json)
|
||||
|
||||
Reference in New Issue
Block a user