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