TextBox::setOnEditStart(runnable)
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "../../graphics/Batch2D.h"
|
#include "../../graphics/Batch2D.h"
|
||||||
#include "../../graphics/Font.h"
|
#include "../../graphics/Font.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
@@ -194,6 +195,17 @@ bool TextBox::isValid() const {
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBox::setOnEditStart(gui::runnable oneditstart) {
|
||||||
|
onEditStart = oneditstart;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBox::focus(GUI* gui) {
|
||||||
|
Panel::focus(gui);
|
||||||
|
if (onEditStart){
|
||||||
|
onEditStart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TextBox::keyPressed(int key) {
|
void TextBox::keyPressed(int key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case KEY_BACKSPACE:
|
case KEY_BACKSPACE:
|
||||||
@@ -241,6 +253,10 @@ wstring TextBox::text() const {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBox::text(std::wstring value) {
|
||||||
|
this->input = value;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================== InputBindBox ================================
|
// ============================== InputBindBox ================================
|
||||||
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
||||||
: Panel(vec2(100,32), padding, 0, false),
|
: Panel(vec2(100,32), padding, 0, false),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include "GUI.h"
|
||||||
#include "UINode.h"
|
#include "UINode.h"
|
||||||
#include "panels.h"
|
#include "panels.h"
|
||||||
#include "../../window/input.h"
|
#include "../../window/input.h"
|
||||||
@@ -80,6 +81,7 @@ namespace gui {
|
|||||||
wstringsupplier supplier = nullptr;
|
wstringsupplier supplier = nullptr;
|
||||||
wstringconsumer consumer = nullptr;
|
wstringconsumer consumer = nullptr;
|
||||||
wstringchecker validator = nullptr;
|
wstringchecker validator = nullptr;
|
||||||
|
runnable onEditStart = nullptr;
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
public:
|
public:
|
||||||
TextBox(std::wstring placeholder,
|
TextBox(std::wstring placeholder,
|
||||||
@@ -95,9 +97,12 @@ namespace gui {
|
|||||||
virtual void textValidator(wstringchecker validator);
|
virtual void textValidator(wstringchecker validator);
|
||||||
virtual bool isfocuskeeper() const override {return true;}
|
virtual bool isfocuskeeper() const override {return true;}
|
||||||
virtual std::wstring text() const;
|
virtual std::wstring text() const;
|
||||||
|
virtual void text(std::wstring value);
|
||||||
virtual bool validate();
|
virtual bool validate();
|
||||||
virtual void setValid(bool valid);
|
virtual void setValid(bool valid);
|
||||||
virtual bool isValid() const;
|
virtual bool isValid() const;
|
||||||
|
virtual void setOnEditStart(runnable oneditstart);
|
||||||
|
virtual void focus(GUI*) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InputBindBox : public Panel {
|
class InputBindBox : public Panel {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
@@ -110,7 +111,7 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
TextBox* box = new TextBox(L"");
|
TextBox* box = new TextBox(L"");
|
||||||
box->textSupplier([=]() {
|
box->textSupplier([=]() {
|
||||||
Hitbox* hitbox = level->player->hitbox.get();
|
Hitbox* hitbox = level->player->hitbox.get();
|
||||||
return std::to_wstring(hitbox->position[ax]);
|
return util::to_wstring(hitbox->position[ax], 2);
|
||||||
});
|
});
|
||||||
box->textConsumer([=](std::wstring text) {
|
box->textConsumer([=](std::wstring text) {
|
||||||
try {
|
try {
|
||||||
@@ -120,6 +121,10 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
} catch (std::invalid_argument& _){
|
} catch (std::invalid_argument& _){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
box->setOnEditStart([=](){
|
||||||
|
Hitbox* hitbox = level->player->hitbox.get();
|
||||||
|
box->text(std::to_wstring(int(hitbox->position[ax])));
|
||||||
|
});
|
||||||
|
|
||||||
sub->add(box);
|
sub->add(box);
|
||||||
panel->add(sub);
|
panel->add(sub);
|
||||||
|
|||||||
Reference in New Issue
Block a user