gui::PagesControl renamed to gui::Menu
This commit is contained in:
@@ -21,7 +21,7 @@ GUI::GUI() {
|
|||||||
uicamera->perspective = false;
|
uicamera->perspective = false;
|
||||||
uicamera->flipped = true;
|
uicamera->flipped = true;
|
||||||
|
|
||||||
menu = std::make_shared<PagesControl>();
|
menu = std::make_shared<Menu>();
|
||||||
menu->setId("menu");
|
menu->setId("menu");
|
||||||
container->add(menu);
|
container->add(menu);
|
||||||
container->setScrollable(false);
|
container->setScrollable(false);
|
||||||
@@ -30,7 +30,7 @@ GUI::GUI() {
|
|||||||
GUI::~GUI() {
|
GUI::~GUI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<PagesControl> GUI::getMenu() {
|
std::shared_ptr<Menu> GUI::getMenu() {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class Camera;
|
|||||||
namespace gui {
|
namespace gui {
|
||||||
class UINode;
|
class UINode;
|
||||||
class Container;
|
class Container;
|
||||||
class PagesControl;
|
class Menu;
|
||||||
|
|
||||||
/// @brief The main UI controller
|
/// @brief The main UI controller
|
||||||
class GUI {
|
class GUI {
|
||||||
@@ -60,15 +60,15 @@ namespace gui {
|
|||||||
std::unordered_map<std::string, std::shared_ptr<UINode>> storage;
|
std::unordered_map<std::string, std::shared_ptr<UINode>> storage;
|
||||||
|
|
||||||
std::unique_ptr<Camera> uicamera;
|
std::unique_ptr<Camera> uicamera;
|
||||||
std::shared_ptr<PagesControl> menu;
|
std::shared_ptr<Menu> menu;
|
||||||
std::queue<runnable> postRunnables;
|
std::queue<runnable> postRunnables;
|
||||||
void actMouse(float delta);
|
void actMouse(float delta);
|
||||||
public:
|
public:
|
||||||
GUI();
|
GUI();
|
||||||
~GUI();
|
~GUI();
|
||||||
|
|
||||||
/// @brief Get the main menu (PagesControl) node
|
/// @brief Get the main menu (Menu) node
|
||||||
std::shared_ptr<PagesControl> getMenu();
|
std::shared_ptr<Menu> getMenu();
|
||||||
|
|
||||||
/// @brief Get current focused node
|
/// @brief Get current focused node
|
||||||
/// @return focused node or nullptr
|
/// @return focused node or nullptr
|
||||||
|
|||||||
@@ -246,22 +246,23 @@ Orientation Panel::getOrientation() const {
|
|||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
PagesControl::PagesControl() : Container(glm::vec2(1)){
|
Menu::Menu() : Container(glm::vec2(1)){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PagesControl::has(const std::string& name) {
|
bool Menu::has(const std::string& name) {
|
||||||
return pages.find(name) != pages.end();
|
return pages.find(name) != pages.end() ||
|
||||||
|
pageSuppliers.find(name) != pageSuppliers.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagesControl::addPage(std::string name, std::shared_ptr<UINode> panel) {
|
void Menu::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) {
|
void Menu::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier) {
|
||||||
pageSuppliers[name] = pageSupplier;
|
pageSuppliers[name] = pageSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagesControl::setPage(std::string name, bool history) {
|
void Menu::setPage(std::string name, bool history) {
|
||||||
auto found = pages.find(name);
|
auto found = pages.find(name);
|
||||||
Page page;
|
Page page;
|
||||||
if (found == pages.end()) {
|
if (found == pages.end()) {
|
||||||
@@ -270,6 +271,7 @@ void PagesControl::setPage(std::string name, bool history) {
|
|||||||
throw std::runtime_error("no page found");
|
throw std::runtime_error("no page found");
|
||||||
} else {
|
} else {
|
||||||
page.panel = supplier->second();
|
page.panel = supplier->second();
|
||||||
|
// supplied pages caching is not implemented
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
page = found->second;
|
page = found->second;
|
||||||
@@ -286,7 +288,7 @@ void PagesControl::setPage(std::string name, bool history) {
|
|||||||
setSize(current.panel->getSize());
|
setSize(current.panel->getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagesControl::back() {
|
void Menu::back() {
|
||||||
if (pageStack.empty())
|
if (pageStack.empty())
|
||||||
return;
|
return;
|
||||||
std::string name = pageStack.top();
|
std::string name = pageStack.top();
|
||||||
@@ -294,19 +296,19 @@ void PagesControl::back() {
|
|||||||
setPage(name, false);
|
setPage(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Page& PagesControl::getCurrent() {
|
Page& Menu::getCurrent() {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& PagesControl::getCurrentName() const {
|
const std::string& Menu::getCurrentName() const {
|
||||||
return curname;
|
return curname;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagesControl::clearHistory() {
|
void Menu::clearHistory() {
|
||||||
pageStack = std::stack<std::string>();
|
pageStack = std::stack<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagesControl::reset() {
|
void Menu::reset() {
|
||||||
clearHistory();
|
clearHistory();
|
||||||
if (current.panel) {
|
if (current.panel) {
|
||||||
curname = "";
|
curname = "";
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace gui {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PagesControl : public Container {
|
class Menu : public Container {
|
||||||
protected:
|
protected:
|
||||||
std::unordered_map<std::string, Page> pages;
|
std::unordered_map<std::string, Page> pages;
|
||||||
std::stack<std::string> pageStack;
|
std::stack<std::string> pageStack;
|
||||||
@@ -100,17 +100,36 @@ namespace gui {
|
|||||||
std::string curname = "";
|
std::string curname = "";
|
||||||
std::unordered_map<std::string, supplier<std::shared_ptr<UINode>>> pageSuppliers;
|
std::unordered_map<std::string, supplier<std::shared_ptr<UINode>>> pageSuppliers;
|
||||||
public:
|
public:
|
||||||
PagesControl();
|
Menu();
|
||||||
|
|
||||||
|
/// @brief Check menu have page or page supplier
|
||||||
|
/// @param name page name
|
||||||
bool has(const std::string& name);
|
bool has(const std::string& name);
|
||||||
|
|
||||||
|
/// @brief Set current page to specified one.
|
||||||
|
/// @param name page or page supplier name
|
||||||
|
/// @param history previous page will not be saved in history if false
|
||||||
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);
|
||||||
|
|
||||||
|
/// @brief Add page supplier used if page is not found
|
||||||
|
/// @param name page name
|
||||||
|
/// @param pageSupplier page supplier function
|
||||||
void addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier);
|
void addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier);
|
||||||
|
|
||||||
|
/// @brief Set page to previous saved in history
|
||||||
void back();
|
void back();
|
||||||
|
|
||||||
|
/// @brief Clear pages history
|
||||||
void clearHistory();
|
void clearHistory();
|
||||||
|
|
||||||
|
/// @brief Clear history and remove and set page to null
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
/// @brief Get current page
|
||||||
Page& getCurrent();
|
Page& getCurrent();
|
||||||
|
|
||||||
|
/// @brief Get current page name
|
||||||
const std::string& getCurrentName() const;
|
const std::string& getCurrentName() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
std::shared_ptr<Button> guiutil::backButton(std::shared_ptr<PagesControl> menu) {
|
std::shared_ptr<Button> guiutil::backButton(std::shared_ptr<Menu> menu) {
|
||||||
return std::dynamic_pointer_cast<Button>(create(
|
return std::dynamic_pointer_cast<Button>(create(
|
||||||
"<button padding='10' onclick='menu:back()'>@Back</button>"
|
"<button padding='10' onclick='menu:back()'>@Back</button>"
|
||||||
));
|
));
|
||||||
@@ -21,7 +21,7 @@ std::shared_ptr<Button> guiutil::backButton(std::shared_ptr<PagesControl> menu)
|
|||||||
std::shared_ptr<Button> guiutil::gotoButton(
|
std::shared_ptr<Button> guiutil::gotoButton(
|
||||||
std::wstring text,
|
std::wstring text,
|
||||||
const std::string& page,
|
const std::string& page,
|
||||||
std::shared_ptr<PagesControl> menu
|
std::shared_ptr<Menu> menu
|
||||||
) {
|
) {
|
||||||
text = langs::get(text, L"menu");
|
text = langs::get(text, L"menu");
|
||||||
return std::dynamic_pointer_cast<Button>(create(
|
return std::dynamic_pointer_cast<Button>(create(
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ namespace gui {
|
|||||||
|
|
||||||
namespace guiutil {
|
namespace guiutil {
|
||||||
std::shared_ptr<gui::Button> backButton(
|
std::shared_ptr<gui::Button> backButton(
|
||||||
std::shared_ptr<gui::PagesControl> menu
|
std::shared_ptr<gui::Menu> menu
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<gui::Button> gotoButton(
|
std::shared_ptr<gui::Button> gotoButton(
|
||||||
std::wstring text,
|
std::wstring text,
|
||||||
const std::string& page,
|
const std::string& page,
|
||||||
std::shared_ptr<gui::PagesControl> menu
|
std::shared_ptr<gui::Menu> menu
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Create element from XML
|
/// @brief Create element from XML
|
||||||
|
|||||||
@@ -130,12 +130,12 @@ static gui::UINode* getDocumentNode(lua_State* L) {
|
|||||||
|
|
||||||
static int menu_back(lua_State* L) {
|
static int menu_back(lua_State* L) {
|
||||||
auto node = getDocumentNode(L);
|
auto node = getDocumentNode(L);
|
||||||
auto menu = dynamic_cast<gui::PagesControl*>(node);
|
auto menu = dynamic_cast<gui::Menu*>(node);
|
||||||
menu->back();
|
menu->back();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getattr(lua_State* L, gui::PagesControl* menu, const std::string& attr) {
|
static bool getattr(lua_State* L, gui::Menu* menu, const std::string& attr) {
|
||||||
if (menu == nullptr)
|
if (menu == nullptr)
|
||||||
return false;
|
return false;
|
||||||
if (attr == "page") {
|
if (attr == "page") {
|
||||||
@@ -193,7 +193,7 @@ static bool setattr(lua_State* L, gui::Label* label, const std::string& attr) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool setattr(lua_State* L, gui::PagesControl* menu, const std::string& attr) {
|
static bool setattr(lua_State* L, gui::Menu* menu, const std::string& attr) {
|
||||||
if (menu == nullptr)
|
if (menu == nullptr)
|
||||||
return false;
|
return false;
|
||||||
if (attr == "page") {
|
if (attr == "page") {
|
||||||
@@ -260,7 +260,7 @@ static int l_gui_getattr(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
if (getattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
if (getattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
||||||
return 1;
|
return 1;
|
||||||
if (getattr(L, dynamic_cast<gui::PagesControl*>(node), attr))
|
if (getattr(L, dynamic_cast<gui::Menu*>(node), attr))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -300,7 +300,7 @@ static int l_gui_setattr(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
if (setattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
if (setattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
||||||
return 0;
|
return 0;
|
||||||
if (setattr(L, dynamic_cast<gui::PagesControl*>(node), attr))
|
if (setattr(L, dynamic_cast<gui::Menu*>(node), attr))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user