scripting: PagesControl

This commit is contained in:
MihailRis
2024-03-20 10:01:07 +03:00
parent 93acc5ce57
commit b3ca4b8efc
8 changed files with 95 additions and 43 deletions
+1
View File
@@ -22,6 +22,7 @@ GUI::GUI() {
uicamera->flipped = true;
menu = std::make_shared<PagesControl>();
menu->setId("menu");
container->add(menu);
container->setScrollable(false);
}
+4
View File
@@ -285,6 +285,10 @@ Page& PagesControl::getCurrent() {
return current;
}
const std::string& PagesControl::getCurrentName() const {
return curname;
}
void PagesControl::clearHistory() {
pageStack = std::stack<std::string>();
}
+1
View File
@@ -107,6 +107,7 @@ namespace gui {
void reset();
Page& getCurrent();
const std::string& getCurrentName() const;
};
}
#endif // GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
+6 -7
View File
@@ -7,6 +7,7 @@
#include "../../logic/scripting/scripting.h"
#include "../../frontend/locale/langs.h"
#include "../../util/stringutil.h"
#include "../../delegates.h"
using namespace gui;
@@ -25,13 +26,11 @@ std::shared_ptr<Button> guiutil::gotoButton(
std::shared_ptr<PagesControl> menu
) {
text = langs::get(text, L"menu");
return std::make_shared<Button>(text, glm::vec4(10.f), [=](GUI* gui) {
if (menu->has(page)) {
menu->setPage(page);
} else {
menu->setPage("404");
}
});
return std::dynamic_pointer_cast<Button>(create(
"<button onclick='menu.page=\""+page+"\"' padding='10,10,10,10'>"+
util::wstr2str_utf8(text)+
"</button>"
));
}
std::shared_ptr<gui::UINode> guiutil::create(const std::string& source) {