Text Input Form proper cursor behavior.
This commit is contained in:
7
main.cpp
7
main.cpp
@@ -106,6 +106,7 @@ JUI::Scene* CreateScene() {
|
||||
auto* input_form = new TextInputForm(s1_vert);
|
||||
input_form->Size({0,30, 1, 0});
|
||||
input_form->SetContent("This Diqq");
|
||||
input_form->SetTextSize(14);
|
||||
|
||||
|
||||
//auto* main_wnd = new Window(root);
|
||||
@@ -268,9 +269,9 @@ public:
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // NOTE: This MUST be called for text rendering to work properly!!!
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(float elapsed)
|
||||
{
|
||||
scene->Update(0.f);
|
||||
scene->Update(elapsed);
|
||||
}
|
||||
|
||||
void Draw()
|
||||
@@ -280,7 +281,7 @@ public:
|
||||
|
||||
JUIDevelopmentTestWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h) {}
|
||||
void OnRefresh(float elapsed) override {
|
||||
Update();
|
||||
Update(elapsed);
|
||||
JGL::Update(GetSize());
|
||||
scene->SetViewportSize(GetSize());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@@ -34,7 +34,10 @@ namespace JUI {
|
||||
if (focused) {
|
||||
cursor_blink_time += elapsed;
|
||||
|
||||
if (std::fmod( cursor_blink_time, 2) < 1) {
|
||||
if (cursor_blink_time > 1.f)
|
||||
cursor_blink_time = 0.f;
|
||||
|
||||
if (cursor_blink_time > 0.5f) {
|
||||
std::string result = input_buffer;
|
||||
|
||||
result.insert(cursor_position, 1, '|');
|
||||
@@ -83,11 +86,13 @@ namespace JUI {
|
||||
}
|
||||
|
||||
if (key == Keys::LeftArrow) {
|
||||
cursor_blink_time -= 1;
|
||||
cursor_position -= 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == Keys::RightArrow) {
|
||||
cursor_blink_time += 1;
|
||||
cursor_position += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == Keys::LeftShift || key == Keys::RightShift || key == Keys::LeftControl || key == Keys::RightControl
|
||||
@@ -99,14 +104,17 @@ namespace JUI {
|
||||
|
||||
|
||||
if (key == Keys::Backspace) {
|
||||
input_buffer = input_buffer.substr(0, input_buffer.length()-1);
|
||||
cursor_position--;
|
||||
if (cursor_position > 0) {
|
||||
input_buffer = input_buffer.erase(cursor_position-1, 1);
|
||||
//input_buffer = input_buffer.substr(0, input_buffer.length()-1);
|
||||
cursor_position--;
|
||||
}
|
||||
} else {
|
||||
if (InputService::IsKeyDown(Keys::LeftShift) || InputService::IsKeyDown(Keys::RightShift)) {
|
||||
input_buffer = input_buffer + uppercase( key.Mnemonic);
|
||||
input_buffer = input_buffer.insert(cursor_position, uppercase( key.Mnemonic));
|
||||
cursor_position++;
|
||||
} else {
|
||||
input_buffer = input_buffer + lowercase( key.Mnemonic);
|
||||
input_buffer = input_buffer.insert(cursor_position, lowercase( key.Mnemonic));
|
||||
cursor_position++;
|
||||
}
|
||||
//SetContent(GetContent() + key.Mnemonic);
|
||||
|
Reference in New Issue
Block a user