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