textbox text scroll
This commit is contained in:
@@ -252,6 +252,8 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
|||||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||||
add(label);
|
add(label);
|
||||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
||||||
|
|
||||||
|
textInitX = label->getCoord().x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
||||||
@@ -318,6 +320,11 @@ void TextBox::paste(const std::wstring& text) {
|
|||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBox::setTextOffset(uint x) {
|
||||||
|
label->setCoord(glm::vec2(textInitX - int(x), label->getCoord().y));
|
||||||
|
textOffset = x;
|
||||||
|
}
|
||||||
|
|
||||||
void TextBox::typed(unsigned int codepoint) {
|
void TextBox::typed(unsigned int codepoint) {
|
||||||
paste(std::wstring({(wchar_t)codepoint}));
|
paste(std::wstring({(wchar_t)codepoint}));
|
||||||
}
|
}
|
||||||
@@ -356,10 +363,6 @@ void TextBox::refresh() {
|
|||||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::clicked(GUI*, int button) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBox::mouseMove(GUI*, int x, int y) {
|
void TextBox::mouseMove(GUI*, int x, int y) {
|
||||||
if (font == nullptr)
|
if (font == nullptr)
|
||||||
return;
|
return;
|
||||||
@@ -471,6 +474,14 @@ uint TextBox::getCaret() const {
|
|||||||
void TextBox::setCaret(uint position) {
|
void TextBox::setCaret(uint position) {
|
||||||
this->caret = position;
|
this->caret = position;
|
||||||
caretLastMove = Window::time();
|
caretLastMove = Window::time();
|
||||||
|
|
||||||
|
int width = label->getSize().x;
|
||||||
|
int realoffset = font->calcWidth(input, caret)-int(textOffset);
|
||||||
|
if (realoffset-width > 0) {
|
||||||
|
setTextOffset(textOffset + realoffset-width);
|
||||||
|
} else if (realoffset < 0) {
|
||||||
|
setTextOffset(std::max(textOffset + realoffset, 0U));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================== InputBindBox ================================
|
// ============================== InputBindBox ================================
|
||||||
|
|||||||
@@ -112,10 +112,13 @@ namespace gui {
|
|||||||
bool valid = true;
|
bool valid = true;
|
||||||
/// @brief text input pointer, value may be greather than text length
|
/// @brief text input pointer, value may be greather than text length
|
||||||
uint caret = 0;
|
uint caret = 0;
|
||||||
|
uint textOffset = 0;
|
||||||
|
int textInitX;
|
||||||
double caretLastMove = 0.0;
|
double caretLastMove = 0.0;
|
||||||
Font* font = nullptr;
|
Font* font = nullptr;
|
||||||
|
|
||||||
void paste(const std::wstring& text);
|
void paste(const std::wstring& text);
|
||||||
|
void setTextOffset(uint x);
|
||||||
public:
|
public:
|
||||||
TextBox(std::wstring placeholder,
|
TextBox(std::wstring placeholder,
|
||||||
glm::vec4 padding=glm::vec4(4.0f));
|
glm::vec4 padding=glm::vec4(4.0f));
|
||||||
@@ -148,7 +151,6 @@ namespace gui {
|
|||||||
virtual void setOnEditStart(runnable oneditstart);
|
virtual void setOnEditStart(runnable oneditstart);
|
||||||
virtual void focus(GUI*) override;
|
virtual void focus(GUI*) override;
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
virtual void clicked(GUI*, int button) override;
|
|
||||||
virtual void mouseMove(GUI*, int x, int y) override;
|
virtual void mouseMove(GUI*, int x, int y) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user