Merge pull request #645 from MihailRis/fix-panel-attrs

fix: some container attributes not available in panel
This commit is contained in:
MihailRis 2025-10-06 22:02:17 +03:00 committed by GitHub
commit 51a8ed6737
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 30 deletions

View File

@ -1,5 +1,4 @@
<panel size='400' color='0' interval='1' context='menu'>
<button onclick='menu.page="new_world"'>@New World</button>
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>

View File

@ -8,19 +8,17 @@
#include "elements/Button.hpp"
#include "elements/Canvas.hpp"
#include "elements/CheckBox.hpp"
#include "elements/TextBox.hpp"
#include "elements/SplitBox.hpp"
#include "elements/TrackBar.hpp"
#include "elements/SelectBox.hpp"
#include "elements/Image.hpp"
#include "elements/InlineFrame.hpp"
#include "elements/InputBindBox.hpp"
#include "elements/InventoryView.hpp"
#include "elements/Menu.hpp"
#include "elements/ModelViewer.hpp"
#include "elements/Panel.hpp"
#include "elements/SelectBox.hpp"
#include "elements/SplitBox.hpp"
#include "elements/TextBox.hpp"
#include "elements/TrackBar.hpp"
#include "elements/ModelViewer.hpp"
#include "engine/Engine.hpp"
#include "frontend/locale.hpp"
#include "frontend/menu.hpp"
@ -197,7 +195,10 @@ static void read_uinode(
}
static void read_container_impl(
UiXmlReader& reader, const xml::xmlelement& element, Container& container
UiXmlReader& reader,
const xml::xmlelement& element,
Container& container,
bool subnodes
) {
read_uinode(reader, element, container);
@ -207,6 +208,9 @@ static void read_container_impl(
if (element.has("scroll-step")) {
container.setScrollStep(element.attr("scroll-step").asInt());
}
if (!subnodes) {
return;
}
for (auto& sub : element.getElements()) {
if (sub->isText()) continue;
auto subnode = reader.readUINode(*sub);
@ -219,7 +223,7 @@ static void read_container_impl(
void UiXmlReader::readUINode(
UiXmlReader& reader, const xml::xmlelement& element, Container& container
) {
read_container_impl(reader, element, container);
read_container_impl(reader, element, container, true);
}
void UiXmlReader::readUINode(
@ -229,11 +233,9 @@ void UiXmlReader::readUINode(
}
static void read_base_panel_impl(
UiXmlReader& reader,
const xml::xmlelement& element,
BasePanel& panel
UiXmlReader& reader, const xml::xmlelement& element, BasePanel& panel
) {
read_uinode(reader, element, panel);
read_container_impl(reader, element, panel, false);
if (element.has("padding")) {
glm::vec4 padding = element.attr("padding").asVec4();
@ -244,7 +246,7 @@ static void read_base_panel_impl(
));
}
if (element.has("orientation")) {
auto &oname = element.attr("orientation").getText();
auto& oname = element.attr("orientation").getText();
if (oname == "horizontal") {
panel.setOrientation(Orientation::horizontal);
}
@ -348,7 +350,7 @@ static std::shared_ptr<UINode> read_container(
UiXmlReader& reader, const xml::xmlelement& element
) {
auto container = std::make_shared<Container>(reader.getGUI(), glm::vec2());
read_container_impl(reader, element, *container);
read_container_impl(reader, element, *container, true);
return container;
}
@ -365,8 +367,7 @@ static std::shared_ptr<UINode> read_split_box(
);
read_base_panel_impl(reader, element, *splitBox);
for (auto& sub : element.getElements()) {
if (sub->isText())
continue;
if (sub->isText()) continue;
auto subnode = reader.readUINode(*sub);
if (subnode) {
splitBox->add(subnode);
@ -379,15 +380,15 @@ static std::shared_ptr<UINode> read_model_viewer(
UiXmlReader& reader, const xml::xmlelement& element
) {
auto model = element.attr("src", "").getText();
auto viewer = std::make_shared<ModelViewer>(
reader.getGUI(), glm::vec2(), model
);
read_container_impl(reader, element, *viewer);
auto viewer =
std::make_shared<ModelViewer>(reader.getGUI(), glm::vec2(), model);
read_container_impl(reader, element, *viewer, true);
if (element.has("center")) {
viewer->setCenter(element.attr("center").asVec3());
}
if (element.has("cam-rotation")) {
viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3()));
viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3())
);
}
return viewer;
}
@ -450,7 +451,8 @@ static std::shared_ptr<UINode> read_select(
}
auto value = elem->attr("value").getText();
auto text = parse_inner_text(*elem, reader.getContext());
options.push_back(SelectBox::Option {std::move(value), std::move(text)});
options.push_back(SelectBox::Option {std::move(value), std::move(text)}
);
}
if (element.has("selected")) {
@ -485,10 +487,9 @@ static std::shared_ptr<UINode> read_select(
element.attr("onselect").getText(),
reader.getFilename()
);
selectBox->listenChange(
[callback=std::move(callback)](GUI&, const std::string& value) {
callback(value);
});
selectBox->listenChange([callback = std::move(callback)](
GUI&, const std::string& value
) { callback(value); });
}
read_panel_impl(reader, element, *selectBox, false);
return selectBox;
@ -539,7 +540,7 @@ static std::shared_ptr<UINode> read_text_box(
);
textbox->setHint(hint);
read_container_impl(reader, element, *textbox);
read_container_impl(reader, element, *textbox, true);
if (element.has("padding")) {
glm::vec4 padding = element.attr("padding").asVec4();
textbox->setPadding(padding);
@ -839,7 +840,7 @@ static std::shared_ptr<UINode> read_page_box(
auto& gui = reader.getGUI();
auto menu = std::make_shared<Menu>(gui);
menu->setPageLoader(gui.getMenu()->getPageLoader());
read_container_impl(reader, element, *menu);
read_container_impl(reader, element, *menu, true);
return menu;
}
@ -849,14 +850,15 @@ static std::shared_ptr<UINode> read_iframe(
) {
auto& gui = reader.getGUI();
auto iframe = std::make_shared<InlineFrame>(gui);
read_container_impl(reader, element, *iframe);
read_container_impl(reader, element, *iframe, true);
std::string src = element.attr("src", "").getText();
iframe->setSrc(src);
return iframe;
}
UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env) : gui(gui), env(std::move(env)) {
UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env)
: gui(gui), env(std::move(env)) {
contextStack.emplace("");
add("image", read_image);
add("canvas", read_canvas);