add iframe ui element
This commit is contained in:
parent
6a7e71c614
commit
71d3756902
@ -368,3 +368,7 @@ Window& GUI::getWindow() {
|
||||
devtools::Editor& GUI::getEditor() {
|
||||
return engine.getEditor();
|
||||
}
|
||||
|
||||
Engine& GUI::getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@ -164,5 +164,6 @@ namespace gui {
|
||||
Input& getInput();
|
||||
Window& getWindow();
|
||||
devtools::Editor& getEditor();
|
||||
Engine& getEngine();
|
||||
};
|
||||
}
|
||||
|
||||
51
src/graphics/ui/elements/InlineFrame.cpp
Normal file
51
src/graphics/ui/elements/InlineFrame.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#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.get(), nullptr);
|
||||
document = nullptr;
|
||||
root = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void InlineFrame::setDocument(const std::shared_ptr<UiDocument>& document) {
|
||||
clear();
|
||||
if (document == nullptr) {
|
||||
return;
|
||||
}
|
||||
this->document = document;
|
||||
this->root = document->getRoot();
|
||||
add(root);
|
||||
|
||||
root->setSize(size);
|
||||
|
||||
gui.postRunnable([this]() {
|
||||
scripting::on_ui_open(this->document.get(), {});
|
||||
});
|
||||
}
|
||||
|
||||
void InlineFrame::act(float delta) {
|
||||
if (document || src.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto& assets = *gui.getEngine().getAssets();
|
||||
setDocument(assets.getShared<UiDocument>(src));
|
||||
}
|
||||
|
||||
void InlineFrame::setSize(glm::vec2 size) {
|
||||
Container::setSize(size);
|
||||
if (root) {
|
||||
root->setSize(size);
|
||||
}
|
||||
}
|
||||
23
src/graphics/ui/elements/InlineFrame.hpp
Normal file
23
src/graphics/ui/elements/InlineFrame.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Container.hpp"
|
||||
|
||||
class UiDocument;
|
||||
|
||||
namespace gui {
|
||||
class InlineFrame : public Container {
|
||||
public:
|
||||
explicit InlineFrame(GUI& gui);
|
||||
virtual ~InlineFrame();
|
||||
|
||||
void setSrc(const std::string& src);
|
||||
void setDocument(const std::shared_ptr<UiDocument>& document);
|
||||
|
||||
void act(float delta) override;
|
||||
void setSize(glm::vec2 size) override;
|
||||
private:
|
||||
std::string src;
|
||||
std::shared_ptr<UiDocument> document;
|
||||
std::shared_ptr<UINode> root;
|
||||
};
|
||||
}
|
||||
@ -12,6 +12,7 @@
|
||||
#include "elements/SplitBox.hpp"
|
||||
#include "elements/TrackBar.hpp"
|
||||
#include "elements/Image.hpp"
|
||||
#include "elements/InlineFrame.hpp"
|
||||
#include "elements/InputBindBox.hpp"
|
||||
#include "elements/InventoryView.hpp"
|
||||
#include "elements/Menu.hpp"
|
||||
@ -292,7 +293,7 @@ static std::wstring parse_inner_text(
|
||||
return text;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readLabel(
|
||||
static std::shared_ptr<UINode> read_label(
|
||||
const UiXmlReader& reader, const xml::xmlelement& element
|
||||
) {
|
||||
std::wstring text = parse_inner_text(element, reader.getContext());
|
||||
@ -739,11 +740,24 @@ static std::shared_ptr<UINode> read_page_box(
|
||||
return menu;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> read_iframe(
|
||||
UiXmlReader& reader, const xml::xmlelement& element
|
||||
) {
|
||||
auto& gui = reader.getGUI();
|
||||
auto iframe = std::make_shared<InlineFrame>(gui);
|
||||
read_container_impl(reader, element, *iframe);
|
||||
|
||||
std::string src = element.attr("src", "").getText();
|
||||
iframe->setSrc(src);
|
||||
return iframe;
|
||||
}
|
||||
|
||||
UiXmlReader::UiXmlReader(gui::GUI& gui, const scriptenv& env) : gui(gui), env(env) {
|
||||
contextStack.emplace("");
|
||||
add("image", read_image);
|
||||
add("canvas", read_canvas);
|
||||
add("label", readLabel);
|
||||
add("iframe", read_iframe);
|
||||
add("label", read_label);
|
||||
add("panel", read_panel);
|
||||
add("button", read_button);
|
||||
add("textbox", read_text_box);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user