You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
1.7 KiB

#ifndef INPUTCOMPONENT_H
#define INPUTCOMPONENT_H
#include <GL/glew.h>
#include <string>
#include "BoxComponent.h"
#include "TextComponent.h"
#include "../../scheduler.h"
class Window;
class TextBlock {
public:
// methods
void addChar(char chr);
void delLastChar();
void insertCharAt(char chr, size_t pos);
void delCharAt(size_t pos);
std::pair<size_t, size_t> getXYPos(size_t pos);
size_t getPosXY(size_t x, size_t y);
// properties
size_t lines;
std::vector<size_t> lineChars;
size_t currentLineChars = 0;
std::string text;
};
class InputComponent : public BoxComponent {
public:
//: BoxComponent(rawX, rawY, rawWidth, rawHeight, passedWindowWidth, passedWindowHeight) { }
InputComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
// or
//using BoxComponent::BoxComponent;
void resize(const int passedWindowWidth, const int passedWindowHeight);
void render();
std::string getValue();
void setValue(std::string newValue);
void addChar(char c);
void backSpace();
void updateCursor();
void updateText();
TextComponent *userInputText = nullptr;
BoxComponent *cursorBox = nullptr;
std::function<void(std::string value)> onEnter = nullptr;
// needed for our shader's resizing
int lastRenderedWindowHeight;
bool focused = false;
bool showCursor = true;
std::shared_ptr<timer_handle> cursorTimer = nullptr;
// store for cursor
int cursorStartAtX;
int cursorStartAtY;
int cursorCharX = 0;
int cursorCharY = 0;
TagNode *node = nullptr;
bool multiLine = false; // textarea control
protected:
std::string value="";
};
#endif