fix textbox scrolling

This commit is contained in:
MihailRis 2026-05-03 21:14:56 +03:00
parent 1d4abd7758
commit bebb5049ef
3 changed files with 28 additions and 15 deletions

View file

@ -43,20 +43,28 @@ std::shared_ptr<UINode> Container::getAt(const glm::vec2& pos) {
return UINode::getAt(pos);
}
void Container::click(int x, int y) {
UINode::click(x, y);
if (scrollable) {
auto pos = calcPos();
x -= pos.x;
y -= pos.y;
if (x >= size.x - scrollBarWidth) {
scrollbarTriggered = true;
prevScrollY = y;
}
}
}
void Container::mouseMove(int x, int y) {
UINode::mouseMove(x, y);
if (!scrollable) {
if (!scrollable || !scrollbarTriggered) {
return;
}
auto pos = calcPos();
x -= pos.x;
y -= pos.y;
if (prevScrollY == -1) {
if (x >= size.x - scrollBarWidth) {
prevScrollY = y;
}
return;
}
int diff = (actualLength-size.y);
if (diff > 0) {
scroll -= (y - prevScrollY) / static_cast<float>(size.y) * actualLength;
@ -69,7 +77,7 @@ void Container::mouseMove(int x, int y) {
void Container::mouseRelease(int x, int y) {
UINode::mouseRelease(x, y);
prevScrollY = -1;
scrollbarTriggered = false;
}
void Container::act(float delta) {