Browse Source

updateCursor() refactor - fixes cursor start position

master
Odilitime 5 years ago
parent
commit
ee54d12d98
  1. 33
      src/graphics/components/InputComponent.cpp
  2. 3
      src/graphics/components/InputComponent.h

33
src/graphics/components/InputComponent.cpp

@ -43,12 +43,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r @@ -43,12 +43,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
onFocus=[this]() {
this->focused = true;
this->cursorBox->x = x ;
this->cursorBox->y = y;
if (this->boundToPage) {
this->cursorBox->y = this->windowHeight + y - 13;
}
this->cursorBox->resize(this->windowWidth, this->windowHeight);
this->updateCursor();
this->win->renderDirty = true;
};
onBlur=[this]() {
@ -290,6 +285,18 @@ void InputComponent::backSpace() { @@ -290,6 +285,18 @@ void InputComponent::backSpace() {
updateText();
}
void InputComponent::updateCursor() {
// this is texture shader coordinates now (not text shader coords)
cursorBox->x = x + this->estWidth;
if (boundToPage) {
cursorBox->y = windowHeight + y - 13;
} else {
cursorBox->y = y;
}
//std::cout << "placing cursor at " << (int)cursorBox->x << "," << (int)cursorBox->y << std::endl;
cursorBox->resize(windowWidth, windowHeight);
}
void InputComponent::updateText() {
//std::cout << "InputComponent::updateText - input value is now: " << value << std::endl;
// maybe tie the fontsize to height
@ -322,7 +329,7 @@ void InputComponent::updateText() { @@ -322,7 +329,7 @@ void InputComponent::updateText() {
return;
}
//int textWidth = textInfo->first;
int estWidth = std::get<0>(*textInfo.get());
this->estWidth = std::get<0>(*textInfo.get());
//int estHeight = std::get<1>(*textInfo.get());
userInputText->rasterStartX = 0;
userInputText->rasterStartY = 0;
@ -331,16 +338,8 @@ void InputComponent::updateText() { @@ -331,16 +338,8 @@ void InputComponent::updateText() {
//std::cout << "scrolling text" << std::endl;
userInputText->rasterStartX = estWidth - width;
}
// this is texture shader coordinates now (not text shader coords)
cursorBox->x = x + estWidth;
if (boundToPage) {
cursorBox->y = windowHeight + y - 13;
} else {
cursorBox->y = y;
}
//std::cout << "placing cursor at " << (int)cursorBox->x << "," << (int)cursorBox->y << std::endl;
cursorBox->resize(windowWidth, windowHeight);
this->updateCursor();
userInputText->noWrap = true;
// why does changing the width mess shit up?
//std::cout << "InputComponent::updateText - our width: " << static_cast<int>(width) << " windowWidth: " << windowWidth << std::endl;

3
src/graphics/components/InputComponent.h

@ -20,6 +20,7 @@ public: @@ -20,6 +20,7 @@ public:
void render();
void addChar(char c);
void backSpace();
void updateCursor();
void updateText();
std::string value="";
TextComponent *userInputText = nullptr;
@ -32,6 +33,8 @@ public: @@ -32,6 +33,8 @@ public:
std::shared_ptr<timer_handle> cursorTimer = nullptr;
// handle to signal that a redraw is needed, and access to shader programs
Window *win;
// store for cursor
int estWidth;
};
#endif

Loading…
Cancel
Save