feat: key pressed event interception & 'owner' input.add_callback third argument
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
|
||||
#include "UINode.hpp"
|
||||
#include "commons.hpp"
|
||||
#include "util/ObjectsKeeper.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace gui {
|
||||
class Container : public UINode {
|
||||
class Container : public UINode, public util::ObjectsKeeper {
|
||||
int prevScrollY = -1;
|
||||
protected:
|
||||
std::vector<std::shared_ptr<UINode>> nodes;
|
||||
|
||||
@@ -13,11 +13,15 @@ bool Menu::has(const std::string& name) {
|
||||
pageSuppliers.find(name) != pageSuppliers.end();
|
||||
}
|
||||
|
||||
void Menu::addPage(const std::string& name, const std::shared_ptr<UINode> &panel) {
|
||||
pages[name] = Page{name, panel};
|
||||
void Menu::addPage(const std::string& name, const std::shared_ptr<UINode>& panel) {
|
||||
pages[name] = Page {name, panel};
|
||||
}
|
||||
|
||||
void Menu::addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier) {
|
||||
void Menu::removePage(const std::string& name) {
|
||||
pages.erase(name);
|
||||
}
|
||||
|
||||
void Menu::addSupplier(const std::string& name, const supplier<std::shared_ptr<UINode>>& pageSupplier) {
|
||||
pageSuppliers[name] = pageSupplier;
|
||||
}
|
||||
|
||||
@@ -89,6 +93,6 @@ void Menu::reset() {
|
||||
clearHistory();
|
||||
if (current.panel) {
|
||||
Container::remove(current.panel);
|
||||
current = Page{"", nullptr};
|
||||
current = Page {"", nullptr};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace gui {
|
||||
void setPage(const std::string &name, bool history=true);
|
||||
void setPage(Page page, bool history=true);
|
||||
void addPage(const std::string& name, const std::shared_ptr<UINode>& panel);
|
||||
void removePage(const std::string& name);
|
||||
std::shared_ptr<UINode> fetchPage(const std::string& name);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "util/stringutil.hpp"
|
||||
#include "delegates.hpp"
|
||||
|
||||
#include "window/Events.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace gui;
|
||||
@@ -50,7 +53,7 @@ void guiutil::alert(
|
||||
}
|
||||
|
||||
void guiutil::confirm(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
Engine& engine,
|
||||
const std::wstring& text,
|
||||
const runnable& on_confirm,
|
||||
const runnable& on_deny,
|
||||
@@ -66,19 +69,45 @@ void guiutil::confirm(
|
||||
auto subpanel = std::make_shared<Panel>(glm::vec2(600, 53));
|
||||
subpanel->setColor(glm::vec4(0));
|
||||
|
||||
subpanel->add(std::make_shared<Button>(yestext, glm::vec4(8.f), [=](GUI*){
|
||||
if (on_confirm)
|
||||
auto menu = engine.getGUI()->getMenu();
|
||||
|
||||
runnable on_confirm_final = [on_confirm, menu, &engine]() {
|
||||
if (on_confirm) {
|
||||
on_confirm();
|
||||
}
|
||||
menu->back();
|
||||
engine.postRunnable([menu]() {
|
||||
menu->removePage("<confirm>");
|
||||
});
|
||||
};
|
||||
|
||||
runnable on_deny_final = [on_deny, menu, &engine]() {
|
||||
if (on_deny) {
|
||||
on_deny();
|
||||
}
|
||||
menu->back();
|
||||
engine.postRunnable([menu]() {
|
||||
menu->removePage("<confirm>");
|
||||
});
|
||||
};
|
||||
|
||||
subpanel->add(std::make_shared<Button>(yestext, glm::vec4(8.f), [=](GUI*){
|
||||
on_confirm_final();
|
||||
}));
|
||||
|
||||
subpanel->add(std::make_shared<Button>(notext, glm::vec4(8.f), [=](GUI*){
|
||||
if (on_deny)
|
||||
on_deny();
|
||||
menu->back();
|
||||
on_deny_final();
|
||||
}));
|
||||
|
||||
panel->add(subpanel);
|
||||
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([=](){
|
||||
on_confirm_final();
|
||||
return true;
|
||||
}));
|
||||
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([=](){
|
||||
on_deny_final();
|
||||
return true;
|
||||
}));
|
||||
|
||||
panel->refresh();
|
||||
menu->addPage("<confirm>", panel);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Engine;
|
||||
|
||||
namespace guiutil {
|
||||
/// @brief Create element from XML
|
||||
/// @param source XML
|
||||
@@ -19,7 +21,7 @@ namespace guiutil {
|
||||
);
|
||||
|
||||
void confirm(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
Engine& engine,
|
||||
const std::wstring& text,
|
||||
const runnable& on_confirm=nullptr,
|
||||
const runnable& on_deny=nullptr,
|
||||
|
||||
Reference in New Issue
Block a user