diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index ad2dfa53..7bb4c75c 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -21,7 +21,7 @@ GUI::GUI() { uicamera->perspective = false; uicamera->flipped = true; - menu = std::make_shared(); + menu = std::make_shared(); menu->setId("menu"); container->add(menu); container->setScrollable(false); @@ -30,7 +30,7 @@ GUI::GUI() { GUI::~GUI() { } -std::shared_ptr GUI::getMenu() { +std::shared_ptr GUI::getMenu() { return menu; } diff --git a/src/graphics/ui/GUI.h b/src/graphics/ui/GUI.h index a519d870..9aeda7c6 100644 --- a/src/graphics/ui/GUI.h +++ b/src/graphics/ui/GUI.h @@ -49,7 +49,7 @@ class Camera; namespace gui { class UINode; class Container; - class PagesControl; + class Menu; /// @brief The main UI controller class GUI { @@ -60,15 +60,15 @@ namespace gui { std::unordered_map> storage; std::unique_ptr uicamera; - std::shared_ptr menu; + std::shared_ptr menu; std::queue postRunnables; void actMouse(float delta); public: GUI(); ~GUI(); - /// @brief Get the main menu (PagesControl) node - std::shared_ptr getMenu(); + /// @brief Get the main menu (Menu) node + std::shared_ptr getMenu(); /// @brief Get current focused node /// @return focused node or nullptr diff --git a/src/graphics/ui/elements/containers.cpp b/src/graphics/ui/elements/containers.cpp index 01aae0b0..f0a6ff52 100644 --- a/src/graphics/ui/elements/containers.cpp +++ b/src/graphics/ui/elements/containers.cpp @@ -246,22 +246,23 @@ Orientation Panel::getOrientation() const { return orientation; } -PagesControl::PagesControl() : Container(glm::vec2(1)){ +Menu::Menu() : Container(glm::vec2(1)){ } -bool PagesControl::has(const std::string& name) { - return pages.find(name) != pages.end(); +bool Menu::has(const std::string& name) { + return pages.find(name) != pages.end() || + pageSuppliers.find(name) != pageSuppliers.end(); } -void PagesControl::addPage(std::string name, std::shared_ptr panel) { +void Menu::addPage(std::string name, std::shared_ptr panel) { pages[name] = Page{panel}; } -void PagesControl::addSupplier(std::string name, supplier> pageSupplier) { +void Menu::addSupplier(std::string name, supplier> 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); Page page; if (found == pages.end()) { @@ -270,6 +271,7 @@ void PagesControl::setPage(std::string name, bool history) { throw std::runtime_error("no page found"); } else { page.panel = supplier->second(); + // supplied pages caching is not implemented } } else { page = found->second; @@ -286,7 +288,7 @@ void PagesControl::setPage(std::string name, bool history) { setSize(current.panel->getSize()); } -void PagesControl::back() { +void Menu::back() { if (pageStack.empty()) return; std::string name = pageStack.top(); @@ -294,19 +296,19 @@ void PagesControl::back() { setPage(name, false); } -Page& PagesControl::getCurrent() { +Page& Menu::getCurrent() { return current; } -const std::string& PagesControl::getCurrentName() const { +const std::string& Menu::getCurrentName() const { return curname; } -void PagesControl::clearHistory() { +void Menu::clearHistory() { pageStack = std::stack(); } -void PagesControl::reset() { +void Menu::reset() { clearHistory(); if (current.panel) { curname = ""; diff --git a/src/graphics/ui/elements/containers.h b/src/graphics/ui/elements/containers.h index 54d67b1d..1569e991 100644 --- a/src/graphics/ui/elements/containers.h +++ b/src/graphics/ui/elements/containers.h @@ -92,7 +92,7 @@ namespace gui { } }; - class PagesControl : public Container { + class Menu : public Container { protected: std::unordered_map pages; std::stack pageStack; @@ -100,17 +100,36 @@ namespace gui { std::string curname = ""; std::unordered_map>> pageSuppliers; public: - PagesControl(); + Menu(); + /// @brief Check menu have page or page supplier + /// @param name page 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 addPage(std::string name, std::shared_ptr 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> pageSupplier); + + /// @brief Set page to previous saved in history void back(); + + /// @brief Clear pages history void clearHistory(); + + /// @brief Clear history and remove and set page to null void reset(); + /// @brief Get current page Page& getCurrent(); + + /// @brief Get current page name const std::string& getCurrentName() const; }; } diff --git a/src/graphics/ui/gui_util.cpp b/src/graphics/ui/gui_util.cpp index ce862747..dbc9fd62 100644 --- a/src/graphics/ui/gui_util.cpp +++ b/src/graphics/ui/gui_util.cpp @@ -12,7 +12,7 @@ using namespace gui; -std::shared_ptr" )); @@ -21,7 +21,7 @@ std::shared_ptr