page suppliers

This commit is contained in:
MihailRis
2024-03-21 10:23:33 +03:00
parent c7bc4bb463
commit 2fba78a5f5
4 changed files with 27 additions and 3 deletions
+14 -2
View File
@@ -257,10 +257,22 @@ void PagesControl::addPage(std::string name, std::shared_ptr<UINode> panel) {
pages[name] = Page{panel};
}
void PagesControl::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier) {
pageSuppliers[name] = pageSupplier;
}
void PagesControl::setPage(std::string name, bool history) {
auto found = pages.find(name);
Page page;
if (found == pages.end()) {
throw std::runtime_error("no page found");
auto supplier = pageSuppliers.find(name);
if (supplier == pageSuppliers.end()) {
throw std::runtime_error("no page found");
} else {
page.panel = supplier->second();
}
} else {
page = found->second;
}
if (current.panel) {
Container::remove(current.panel);
@@ -269,7 +281,7 @@ void PagesControl::setPage(std::string name, bool history) {
pageStack.push(curname);
}
curname = name;
current = found->second;
current = page;
Container::add(current.panel);
setSize(current.panel->getSize());
}