Rework text area

This commit is contained in:
crschnick 2024-01-09 01:34:17 +00:00
parent f454e6d905
commit 720e5edfdc

View file

@ -1,6 +1,7 @@
package io.xpipe.app.fxcomps.impl; package io.xpipe.app.fxcomps.impl;
import io.xpipe.app.fxcomps.SimpleComp; import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.CompStructure;
import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.fxcomps.util.SimpleChangeListener; import io.xpipe.app.fxcomps.util.SimpleChangeListener;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
@ -8,11 +9,24 @@ import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Region; import lombok.Builder;
import lombok.Value;
import java.util.Objects; import java.util.Objects;
public class TextAreaComp extends SimpleComp { public class TextAreaComp extends Comp<TextAreaComp.Structure> {
@Value
@Builder
public static class Structure implements CompStructure<AnchorPane> {
AnchorPane pane;
TextArea textArea;
@Override
public AnchorPane get() {
return pane;
}
}
private final Property<String> currentValue; private final Property<String> currentValue;
private final Property<String> lastAppliedValue; private final Property<String> lastAppliedValue;
@ -32,7 +46,7 @@ public class TextAreaComp extends SimpleComp {
} }
@Override @Override
protected Region createSimple() { public Structure createBase() {
var text = new TextArea(currentValue.getValue() != null ? currentValue.getValue() : null); var text = new TextArea(currentValue.getValue() != null ? currentValue.getValue() : null);
text.setPrefRowCount(5); text.setPrefRowCount(5);
text.textProperty().addListener((c, o, n) -> { text.textProperty().addListener((c, o, n) -> {
@ -57,6 +71,12 @@ public class TextAreaComp extends SimpleComp {
} }
}); });
var anchorPane = new AnchorPane(text);
AnchorPane.setBottomAnchor(text, 0.0);
AnchorPane.setTopAnchor(text, 0.0);
AnchorPane.setLeftAnchor(text, 0.0);
AnchorPane.setRightAnchor(text, 0.0);
if (lazy) { if (lazy) {
var isEqual = Bindings.createBooleanBinding( var isEqual = Bindings.createBooleanBinding(
() -> Objects.equals(lastAppliedValue.getValue(), currentValue.getValue()), () -> Objects.equals(lastAppliedValue.getValue(), currentValue.getValue()),
@ -65,16 +85,14 @@ public class TextAreaComp extends SimpleComp {
var button = new IconButtonComp("mdi2c-checkbox-marked-outline") var button = new IconButtonComp("mdi2c-checkbox-marked-outline")
.hide(isEqual) .hide(isEqual)
.createRegion(); .createRegion();
var anchorPane = new AnchorPane(text, button); anchorPane.getChildren().add(button);
AnchorPane.setBottomAnchor(button, 10.0); AnchorPane.setBottomAnchor(button, 10.0);
AnchorPane.setRightAnchor(button, 10.0); AnchorPane.setRightAnchor(button, 10.0);
text.prefWidthProperty().bind(anchorPane.widthProperty()); text.prefWidthProperty().bind(anchorPane.widthProperty());
text.prefHeightProperty().bind(anchorPane.heightProperty()); text.prefHeightProperty().bind(anchorPane.heightProperty());
return anchorPane;
} }
return text; return new Structure(anchorPane, text);
} }
} }