From 720e5edfdcee7dceae61f5c222310325a00157e4 Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 9 Jan 2024 01:34:17 +0000 Subject: [PATCH] Rework text area --- .../xpipe/app/fxcomps/impl/TextAreaComp.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/TextAreaComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/TextAreaComp.java index 2786d26d0..40d3bf625 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/TextAreaComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/TextAreaComp.java @@ -1,6 +1,7 @@ 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.SimpleChangeListener; import javafx.beans.binding.Bindings; @@ -8,11 +9,24 @@ import javafx.beans.property.Property; import javafx.beans.property.SimpleStringProperty; import javafx.scene.control.TextArea; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Region; +import lombok.Builder; +import lombok.Value; import java.util.Objects; -public class TextAreaComp extends SimpleComp { +public class TextAreaComp extends Comp { + + @Value + @Builder + public static class Structure implements CompStructure { + AnchorPane pane; + TextArea textArea; + + @Override + public AnchorPane get() { + return pane; + } + } private final Property currentValue; private final Property lastAppliedValue; @@ -32,7 +46,7 @@ public class TextAreaComp extends SimpleComp { } @Override - protected Region createSimple() { + public Structure createBase() { var text = new TextArea(currentValue.getValue() != null ? currentValue.getValue() : null); text.setPrefRowCount(5); 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) { var isEqual = Bindings.createBooleanBinding( () -> Objects.equals(lastAppliedValue.getValue(), currentValue.getValue()), @@ -65,16 +85,14 @@ public class TextAreaComp extends SimpleComp { var button = new IconButtonComp("mdi2c-checkbox-marked-outline") .hide(isEqual) .createRegion(); - var anchorPane = new AnchorPane(text, button); + anchorPane.getChildren().add(button); AnchorPane.setBottomAnchor(button, 10.0); AnchorPane.setRightAnchor(button, 10.0); text.prefWidthProperty().bind(anchorPane.widthProperty()); text.prefHeightProperty().bind(anchorPane.heightProperty()); - - return anchorPane; } - return text; + return new Structure(anchorPane, text); } }