diff --git a/res/layouts/pages/main.xml b/res/layouts/pages/main.xml
new file mode 100644
index 00000000..29cbc9c8
--- /dev/null
+++ b/res/layouts/pages/main.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/delegates.h b/src/delegates.h
index debb7f59..74ecce28 100644
--- a/src/delegates.h
+++ b/src/delegates.h
@@ -6,6 +6,7 @@
#include
using runnable = std::function;
+template using supplier = std::function;
// data sources
using wstringsupplier = std::function;
diff --git a/src/graphics/ui/elements/containers.cpp b/src/graphics/ui/elements/containers.cpp
index 7817c514..01aae0b0 100644
--- a/src/graphics/ui/elements/containers.cpp
+++ b/src/graphics/ui/elements/containers.cpp
@@ -257,10 +257,22 @@ void PagesControl::addPage(std::string name, std::shared_ptr panel) {
pages[name] = Page{panel};
}
+void PagesControl::addSupplier(std::string name, supplier> 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());
}
diff --git a/src/graphics/ui/elements/containers.h b/src/graphics/ui/elements/containers.h
index 9ea0802c..54d67b1d 100644
--- a/src/graphics/ui/elements/containers.h
+++ b/src/graphics/ui/elements/containers.h
@@ -1,12 +1,14 @@
#ifndef GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
#define GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
+#include "UINode.h"
+#include "../../../delegates.h"
+
#include
#include
#include
#include
#include
-#include "UINode.h"
class Batch2D;
class Assets;
@@ -96,12 +98,14 @@ namespace gui {
std::stack pageStack;
Page current;
std::string curname = "";
+ std::unordered_map>> pageSuppliers;
public:
PagesControl();
bool has(const std::string& name);
void setPage(std::string name, bool history=true);
void addPage(std::string name, std::shared_ptr panel);
+ void addSupplier(std::string name, supplier> pageSupplier);
void back();
void clearHistory();
void reset();