fix(CustomMultiLineTextArea): recalculate scroll offset on text change and scale factor update
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -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>
|
||||
|
||||
@@ -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,11 +448,19 @@ 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();
|
||||
final int currentWrappedLine = getWrappedLineIndexAtCaret();
|
||||
|
||||
Reference in New Issue
Block a user