From d029f8e09a62330162484440b102b9cd372ab772 Mon Sep 17 00:00:00 2001 From: extio-de Date: Sat, 16 May 2026 17:10:57 +0200 Subject: [PATCH] fix(CustomMultiLineTextArea): recalculate scroll offset on text change and scale factor update --- pom.xml | 2 +- .../control/components/CustomMultiLineTextArea.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e0f2d62..172a824 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.extio game-engine - 1.0.16 + 1.0.17 25 diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/components/CustomMultiLineTextArea.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/components/CustomMultiLineTextArea.java index eb9e518..5cc4016 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/components/CustomMultiLineTextArea.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/components/CustomMultiLineTextArea.java @@ -101,6 +101,7 @@ public class CustomMultiLineTextArea extends Component { this.caretPosition = Math.min(this.caretPosition, this.text.length()); this.selectionAnchor = this.caretPosition; this.cachedWrappedLines = null; + this.recalculateScrollOffset(); this.dirty = true; } @@ -123,6 +124,7 @@ public class CustomMultiLineTextArea extends Component { public void setScaleFactor(final double scaleFactor) { this.scaleFactor = scaleFactor; this.cachedWrappedLines = null; + this.recalculateScrollOffset(); this.dirty = true; } @@ -446,10 +448,18 @@ public class CustomMultiLineTextArea extends Component { } private void notifyTextChanged() { + this.recalculateScrollOffset(); if (this.onTextChanged != null) { this.onTextChanged.accept(this.text); } } + + private void recalculateScrollOffset() { + final var lineHeight = this.getLineHeight(); + final var totalContentHeight = this.getWrappedLines().size() * lineHeight; + final var maxScroll = Math.max(0, totalContentHeight - this.getVisibleHeight()); + this.scrollOffsetY = Math.max(0, Math.min(maxScroll, this.scrollOffsetY)); + } private void moveCaretUp() { final List wrappedLines = getWrappedLines();