Added gui_util
This commit is contained in:
@@ -19,7 +19,7 @@ using std::shared_ptr;
|
||||
using namespace gui;
|
||||
|
||||
GUI::GUI() {
|
||||
container = new Container(vec2(0, 0), vec2(Window::width, Window::height));
|
||||
container = new Container(vec2(0, 0), vec2(1000));
|
||||
|
||||
uicamera = new Camera(vec3(), Window::height);
|
||||
uicamera->perspective = false;
|
||||
|
||||
@@ -44,6 +44,8 @@ class Camera;
|
||||
*/
|
||||
|
||||
namespace gui {
|
||||
typedef std::function<void()> runnable;
|
||||
|
||||
class UINode;
|
||||
class Container;
|
||||
class PagesControl;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "gui_util.h"
|
||||
#include "controls.h"
|
||||
#include "panels.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace gui;
|
||||
using glm::vec2;
|
||||
using glm::vec4;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
Button* guiutil::backButton(PagesControl* menu) {
|
||||
return (new Button(L"Back", vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
menu->back();
|
||||
});
|
||||
}
|
||||
|
||||
Button* guiutil::gotoButton(wstring text, string page, PagesControl* menu) {
|
||||
return (new Button(text, vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
menu->set(page);
|
||||
});
|
||||
}
|
||||
|
||||
void guiutil::alert(GUI* gui, wstring text, gui::runnable on_hidden) {
|
||||
PagesControl* menu = gui->getMenu();
|
||||
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
|
||||
panel->color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
panel->add(new Label(text));
|
||||
panel->add((new Button(L"Ok", vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
if (on_hidden)
|
||||
on_hidden();
|
||||
menu->back();
|
||||
}));
|
||||
panel->refresh();
|
||||
menu->add("<alert>", panel);
|
||||
menu->set("<alert>");
|
||||
}
|
||||
|
||||
void guiutil::confirm(GUI* gui, wstring text, gui::runnable on_confirm) {
|
||||
PagesControl* menu = gui->getMenu();
|
||||
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
|
||||
panel->color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
panel->add(new Label(text));
|
||||
Panel* subpanel = new Panel(vec2(500, 53));
|
||||
subpanel->color(vec4(0));
|
||||
subpanel->add((new Button(L"Yes", vec4(8.0f)))->listenAction([=](GUI*){
|
||||
if (on_confirm)
|
||||
on_confirm();
|
||||
menu->back();
|
||||
}));
|
||||
subpanel->add((new Button(L"No", vec4(8.0f)))->listenAction([=](GUI*){
|
||||
menu->back();
|
||||
}));
|
||||
panel->add(subpanel);
|
||||
|
||||
panel->refresh();
|
||||
menu->add("<confirm>", panel);
|
||||
menu->set("<confirm>");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef FRONTEND_GUI_GUI_UTIL_H_
|
||||
#define FRONTEND_GUI_GUI_UTIL_H_
|
||||
|
||||
#include <string>
|
||||
#include "GUI.h"
|
||||
|
||||
namespace gui {
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace guiutil {
|
||||
gui::Button* backButton(gui::PagesControl* menu);
|
||||
gui::Button* gotoButton(std::wstring text, std::string page, gui::PagesControl* menu);
|
||||
void alert(gui::GUI* gui, std::wstring text, gui::runnable on_hidden=nullptr);
|
||||
void confirm(gui::GUI* gui, std::wstring text, gui::runnable on_confirm=nullptr);
|
||||
}
|
||||
|
||||
#endif // FRONTEND_GUI_GUI_UTIL_H_
|
||||
Reference in New Issue
Block a user