GMLPreviewWidget.cpp 914 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021, Conor Byrne <cbyrneee@protonmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GMLPreviewWidget.h"
  7. #include <LibGUI/BoxLayout.h>
  8. #include <LibGUI/Label.h>
  9. namespace HackStudio {
  10. GMLPreviewWidget::GMLPreviewWidget(String const& gml_content)
  11. {
  12. set_layout<GUI::VerticalBoxLayout>();
  13. load_gml(gml_content);
  14. }
  15. void GMLPreviewWidget::load_gml(String const& gml)
  16. {
  17. remove_all_children();
  18. if (gml.is_empty()) {
  19. auto& label = add<GUI::Label>();
  20. label.set_text("Open a .gml file to show the preview");
  21. return;
  22. }
  23. load_from_gml(gml, [](const String& name) -> RefPtr<Core::Object> {
  24. return GUI::Label::construct(String::formatted("{} is not registered as a GML element!", name));
  25. });
  26. if (children().is_empty()) {
  27. auto& label = add<GUI::Label>();
  28. label.set_text("Failed to load GML!");
  29. }
  30. }
  31. }