fix(CustomMultiLineTextArea): recalculate scroll offset on text change and scale factor update

This commit is contained in:
extio-de
2026-05-16 17:10:57 +02:00
parent 46659361e2
commit d029f8e09a
2 changed files with 11 additions and 1 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.extio</groupId>
<artifactId>game-engine</artifactId>
<version>1.0.16</version>
<version>1.0.17</version>
<properties>
<java.version>25</java.version>

View File

@@ -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<String> wrappedLines = getWrappedLines();