extra info box adjusts dynamically

This commit is contained in:
woodser 2025-05-16 14:30:33 -04:00
parent 8d33a5f737
commit 12af277164
No known key found for this signature in database
GPG key ID: 55A10DD48ADEE5EF
3 changed files with 27 additions and 23 deletions

View file

@ -365,10 +365,9 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
extraInfoTextArea.setText(offer.getCombinedExtraInfo());
extraInfoTextArea.getStyleClass().add("text-area");
extraInfoTextArea.setWrapText(true);
extraInfoTextArea.setPrefHeight(75);
extraInfoTextArea.setMinHeight(75);
extraInfoTextArea.setMaxHeight(150);
extraInfoTextArea.setMaxHeight(300);
extraInfoTextArea.setEditable(false);
GUIUtil.adjustHeightAutomatically(extraInfoTextArea);
GridPane.setRowIndex(extraInfoTextArea, lastGridRowNoFundingRequired);
GridPane.setColumnSpan(extraInfoTextArea, GridPane.REMAINING);
GridPane.setColumnIndex(extraInfoTextArea, 0);

View file

@ -45,7 +45,6 @@ import haveno.desktop.components.BusyAnimation;
import haveno.desktop.main.overlays.Overlay;
import haveno.desktop.main.overlays.editor.PasswordPopup;
import haveno.desktop.main.overlays.popups.Popup;
import haveno.desktop.util.CssTheme;
import haveno.desktop.util.DisplayUtils;
import static haveno.desktop.util.FormBuilder.addButtonAfterGroup;
import static haveno.desktop.util.FormBuilder.addButtonBusyAnimationLabelAfterGroup;
@ -58,8 +57,6 @@ import haveno.desktop.util.Layout;
import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
@ -319,23 +316,7 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
TextArea textArea = addConfirmationLabelTextArea(gridPane, ++rowIndex, Res.get("payment.shared.extraInfo"), "", 0).second;
textArea.setText(offer.getCombinedExtraInfo());
textArea.setMaxHeight(200);
textArea.sceneProperty().addListener((o, oldScene, newScene) -> {
if (newScene != null) {
// avoid javafx css warning
CssTheme.loadSceneStyles(newScene, CssTheme.CSS_THEME_LIGHT, false);
textArea.applyCss();
var text = textArea.lookup(".text");
textArea.prefHeightProperty().bind(Bindings.createDoubleBinding(() -> {
return textArea.getFont().getSize() + text.getBoundsInLocal().getHeight();
}, text.boundsInLocalProperty()));
text.boundsInLocalProperty().addListener((observableBoundsAfter, boundsBefore, boundsAfter) -> {
Platform.runLater(() -> textArea.requestLayout());
});
}
});
textArea.setEditable(false);
GUIUtil.adjustHeightAutomatically(textArea);
}
// get amount reserved for the offer

View file

@ -65,10 +65,12 @@ import haveno.desktop.main.account.content.traditionalaccounts.TraditionalAccoun
import haveno.desktop.main.overlays.popups.Popup;
import haveno.network.p2p.P2PService;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.Scene;
@ -1177,4 +1179,26 @@ public class GUIUtil {
if (currencyCode == null) return null;
return "image-" + currencyCode.toLowerCase() + "-logo";
}
public static void adjustHeightAutomatically(TextArea textArea) {
textArea.sceneProperty().addListener((o, oldScene, newScene) -> {
if (newScene != null) {
// avoid javafx css warning
boolean isLightTheme = newScene.getStylesheets().stream().anyMatch(url -> url.contains("theme-light.css"));
CssTheme.loadSceneStyles(newScene, isLightTheme ? CssTheme.CSS_THEME_LIGHT : CssTheme.CSS_THEME_DARK, false);
textArea.applyCss();
var text = textArea.lookup(".text");
textArea.prefHeightProperty().bind(Bindings.createDoubleBinding(() -> {
Insets padding = textArea.getInsets();
double topBottomPadding = padding.getTop() + padding.getBottom();
return textArea.getFont().getSize() + text.getBoundsInLocal().getHeight() + topBottomPadding;
}, text.boundsInLocalProperty()));
text.boundsInLocalProperty().addListener((observableBoundsAfter, boundsBefore, boundsAfter) -> {
Platform.runLater(() -> textArea.requestLayout());
});
}
});
}
}