diff options
author | Conor Byrne <71222289+cbyrneee@users.noreply.github.com> | 2021-07-28 20:58:16 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-29 11:33:16 +0200 |
commit | 6aa2b7d4cc99e8c29988f9f48bddb57d89bad9e2 (patch) | |
tree | 8d9315e368bf0b74d4955dae54dfe86e0afed77e /Userland/DevTools/HackStudio/GMLPreviewWidget.cpp | |
parent | 0295cf96a88e40bf620ed4d734fdf9870337d7c7 (diff) | |
download | serenity-6aa2b7d4cc99e8c29988f9f48bddb57d89bad9e2.zip |
HackStudio: Add GML Preview action tab
This allows us to show a GML Preview in realtime via
HackStudio::GMLPreviewWidget! :^)
Diffstat (limited to 'Userland/DevTools/HackStudio/GMLPreviewWidget.cpp')
-rw-r--r-- | Userland/DevTools/HackStudio/GMLPreviewWidget.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/GMLPreviewWidget.cpp b/Userland/DevTools/HackStudio/GMLPreviewWidget.cpp new file mode 100644 index 0000000000..e2f07af251 --- /dev/null +++ b/Userland/DevTools/HackStudio/GMLPreviewWidget.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021, Conor Byrne <cbyrneee@protonmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "GMLPreviewWidget.h" +#include <LibGUI/BoxLayout.h> +#include <LibGUI/Label.h> + +namespace HackStudio { + +GMLPreviewWidget::GMLPreviewWidget(String const& gml_content) +{ + set_layout<GUI::VerticalBoxLayout>(); + load_gml(gml_content); +} + +void GMLPreviewWidget::load_gml(String const& gml) +{ + remove_all_children(); + + if (gml.is_empty()) { + auto& label = add<GUI::Label>(); + label.set_text("Open a .gml file to show the preview"); + + return; + } + + load_from_gml(gml, [](const String& name) -> RefPtr<Core::Object> { + return GUI::Label::construct(String::formatted("{} is not registered as a GML element!", name)); + }); + + if (children().is_empty()) { + auto& label = add<GUI::Label>(); + label.set_text("Failed to load GML!"); + } +} + +} |