#include "InlineFrame.hpp" #include "frontend/UiDocument.hpp" #include "logic/scripting/scripting.hpp" #include "assets/Assets.hpp" #include "engine/Engine.hpp" #include "../GUI.hpp" using namespace gui; InlineFrame::InlineFrame(GUI& gui) : Container(gui, glm::vec2(1)) {} InlineFrame::~InlineFrame() = default; void InlineFrame::setSrc(const std::string& src) { this->src = src; if (document) { scripting::on_ui_close(*document, nullptr); clear(); document = nullptr; root = nullptr; } } void InlineFrame::setDocument(const std::shared_ptr& document) { clear(); if (document == nullptr) { return; } auto newRoot = document->getRoot(); if (newRoot->hasParent()) { return; } this->document = document; this->root = std::move(newRoot); add(root); root->setSize(size); gui.postRunnable([this]() { scripting::on_ui_open(*this->document, {}); }); } void InlineFrame::act(float delta) { if (document == nullptr && !src.empty()) { const auto& assets = *gui.getEngine().getAssets(); setDocument(assets.getShared(src)); } Container::act(delta); } void InlineFrame::setSize(const glm::vec2& size) { Container::setSize(size); if (root) { root->setSize(size); } } const std::string& InlineFrame::getSrc() const { return src; }