Add canvas UI node

This commit is contained in:
ShadelessFox 2025-01-19 14:10:52 +01:00
parent cb960ceaad
commit ee31f401aa
No known key found for this signature in database
GPG key ID: 1CF8D77ADDADADD9
12 changed files with 279 additions and 2 deletions

View file

@ -4,6 +4,7 @@
#include "elements/Image.hpp"
#include "elements/Menu.hpp"
#include "elements/Button.hpp"
#include "elements/Canvas.hpp"
#include "elements/CheckBox.hpp"
#include "elements/TextBox.hpp"
#include "elements/TrackBar.hpp"
@ -455,6 +456,18 @@ static std::shared_ptr<UINode> readImage(
return image;
}
static std::shared_ptr<UINode> readCanvas(
const UiXmlReader& reader, const xml::xmlelement& element
) {
auto size = glm::uvec2{32, 32};
if (element.has("size")) {
size = element.attr("size").asVec2();
}
auto image = std::make_shared<Canvas>(ImageFormat::rgba8888, size);
_readUINode(reader, element, *image);
return image;
}
static std::shared_ptr<UINode> readTrackBar(
const UiXmlReader& reader, const xml::xmlelement& element
) {
@ -634,6 +647,7 @@ static std::shared_ptr<UINode> readPageBox(UiXmlReader& reader, const xml::xmlel
UiXmlReader::UiXmlReader(const scriptenv& env) : env(env) {
contextStack.emplace("");
add("image", readImage);
add("canvas", readCanvas);
add("label", readLabel);
add("panel", readPanel);
add("button", readButton);