page suppliers
This commit is contained in:
parent
c7bc4bb463
commit
2fba78a5f5
7
res/layouts/pages/main.xml
Normal file
7
res/layouts/pages/main.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<panel size='400' color='0' interval='1' context='menu'>
|
||||||
|
<button onclick='menu.page="new-world"' padding='10'>@New World</button>
|
||||||
|
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>
|
||||||
|
</panel>
|
||||||
|
<button onclick='menu.page="settings"' padding='10'>@Settings</button>
|
||||||
|
<button onclick='core.quit()' padding='10'>@Quit</button>
|
||||||
|
</panel>
|
||||||
@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using runnable = std::function<void()>;
|
using runnable = std::function<void()>;
|
||||||
|
template<class T> using supplier = std::function<T()>;
|
||||||
|
|
||||||
// data sources
|
// data sources
|
||||||
using wstringsupplier = std::function<std::wstring()>;
|
using wstringsupplier = std::function<std::wstring()>;
|
||||||
|
|||||||
@ -257,10 +257,22 @@ void PagesControl::addPage(std::string name, std::shared_ptr<UINode> panel) {
|
|||||||
pages[name] = Page{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) {
|
void PagesControl::setPage(std::string name, bool history) {
|
||||||
auto found = pages.find(name);
|
auto found = pages.find(name);
|
||||||
|
Page page;
|
||||||
if (found == pages.end()) {
|
if (found == pages.end()) {
|
||||||
|
auto supplier = pageSuppliers.find(name);
|
||||||
|
if (supplier == pageSuppliers.end()) {
|
||||||
throw std::runtime_error("no page found");
|
throw std::runtime_error("no page found");
|
||||||
|
} else {
|
||||||
|
page.panel = supplier->second();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
page = found->second;
|
||||||
}
|
}
|
||||||
if (current.panel) {
|
if (current.panel) {
|
||||||
Container::remove(current.panel);
|
Container::remove(current.panel);
|
||||||
@ -269,7 +281,7 @@ void PagesControl::setPage(std::string name, bool history) {
|
|||||||
pageStack.push(curname);
|
pageStack.push(curname);
|
||||||
}
|
}
|
||||||
curname = name;
|
curname = name;
|
||||||
current = found->second;
|
current = page;
|
||||||
Container::add(current.panel);
|
Container::add(current.panel);
|
||||||
setSize(current.panel->getSize());
|
setSize(current.panel->getSize());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
#ifndef GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
|
#ifndef GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
|
||||||
#define GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
|
#define GRAPHICS_UI_ELEMENTS_CONTAINERS_H_
|
||||||
|
|
||||||
|
#include "UINode.h"
|
||||||
|
#include "../../../delegates.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "UINode.h"
|
|
||||||
|
|
||||||
class Batch2D;
|
class Batch2D;
|
||||||
class Assets;
|
class Assets;
|
||||||
@ -96,12 +98,14 @@ namespace gui {
|
|||||||
std::stack<std::string> pageStack;
|
std::stack<std::string> pageStack;
|
||||||
Page current;
|
Page current;
|
||||||
std::string curname = "";
|
std::string curname = "";
|
||||||
|
std::unordered_map<std::string, supplier<std::shared_ptr<UINode>>> pageSuppliers;
|
||||||
public:
|
public:
|
||||||
PagesControl();
|
PagesControl();
|
||||||
|
|
||||||
bool has(const std::string& name);
|
bool has(const std::string& name);
|
||||||
void setPage(std::string name, bool history=true);
|
void setPage(std::string name, bool history=true);
|
||||||
void addPage(std::string name, std::shared_ptr<UINode> panel);
|
void addPage(std::string name, std::shared_ptr<UINode> panel);
|
||||||
|
void addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier);
|
||||||
void back();
|
void back();
|
||||||
void clearHistory();
|
void clearHistory();
|
||||||
void reset();
|
void reset();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user