From 8cdf7255e23470d53386780cd5592b7dc2e214e2 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 14 Dec 2024 10:51:25 -0500 Subject: [PATCH] replace checkbox with toggle slider to reserve required funds --- .../desktop/main/offer/MutableOfferView.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java index 9115c64491..2305818743 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java @@ -137,7 +137,7 @@ public abstract class MutableOfferView> exten private TextField currencyTextField; private AddressTextField addressTextField; private BalanceTextField balanceTextField; - private CheckBox reserveExactAmountCheckbox; + private ToggleButton reserveExactAmountSlider; private ToggleButton buyerAsTakerWithoutDepositSlider; private FundsTextField totalToPayTextField; private Label amountDescriptionLabel, priceCurrencyLabel, priceDescriptionLabel, volumeDescriptionLabel, @@ -176,6 +176,8 @@ public abstract class MutableOfferView> exten @Setter private OfferView.OfferActionHandler offerActionHandler; + private int heightAdjustment = -5; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -436,7 +438,7 @@ private void onShowPayFundsScreen() { qrCodeImageView.setVisible(true); balanceTextField.setVisible(true); cancelButton2.setVisible(true); - reserveExactAmountCheckbox.setVisible(true); + reserveExactAmountSlider.setVisible(true); } private void updateOfferElementsStyle() { @@ -958,7 +960,7 @@ private void addGridPane() { } private void addPaymentGroup() { - paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer")); + paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer"), heightAdjustment); GridPane.setColumnSpan(paymentTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -976,7 +978,7 @@ private void addPaymentGroup() { GridPane.setRowIndex(paymentGroupBox, gridRow); GridPane.setColumnSpan(paymentGroupBox, 2); - GridPane.setMargin(paymentGroupBox, new Insets(Layout.FIRST_ROW_DISTANCE, 0, 0, 0)); + GridPane.setMargin(paymentGroupBox, new Insets(Layout.FIRST_ROW_DISTANCE + heightAdjustment, 0, 0, 0)); gridPane.getChildren().add(paymentGroupBox); tradingAccountBoxTuple.first.setMinWidth(800); @@ -1012,7 +1014,7 @@ public TradeCurrency fromString(String s) { private void addAmountPriceGroup() { amountTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 2, - Res.get("createOffer.setAmountPrice"), 25); + Res.get("createOffer.setAmountPrice"), 25 + heightAdjustment); GridPane.setColumnSpan(amountTitledGroupBg, 2); addAmountPriceFields(); @@ -1021,7 +1023,7 @@ private void addAmountPriceGroup() { private void addOptionsGroup() { setDepositTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 2, - Res.get("shared.advancedOptions"), Layout.COMPACT_GROUP_DISTANCE); + Res.get("shared.advancedOptions"), 25 + heightAdjustment); securityDepositAndFeeBox = new HBox(); securityDepositAndFeeBox.setSpacing(40); @@ -1136,7 +1138,7 @@ private VBox getSecurityDepositBox() { private void addFundingGroup() { // don't increase gridRow as we removed button when this gets visible payFundsTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 3, - Res.get("createOffer.fundsBox.title"), 25); + Res.get("createOffer.fundsBox.title"), 20 + heightAdjustment); payFundsTitledGroupBg.getStyleClass().add("last"); GridPane.setColumnSpan(payFundsTitledGroupBg, 2); payFundsTitledGroupBg.setVisible(false); @@ -1144,7 +1146,7 @@ private void addFundingGroup() { totalToPayTextField = addFundsTextfield(gridPane, gridRow, Res.get("shared.totalsNeeded"), Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE); totalToPayTextField.setVisible(false); - GridPane.setMargin(totalToPayTextField, new Insets(65, 10, 0, 0)); + GridPane.setMargin(totalToPayTextField, new Insets(60 + heightAdjustment, 10, 0, 0)); qrCodeImageView = new ImageView(); qrCodeImageView.setVisible(false); @@ -1170,15 +1172,15 @@ private void addFundingGroup() { Res.get("shared.tradeWalletBalance")); balanceTextField.setVisible(false); - reserveExactAmountCheckbox = FormBuilder.addLabelCheckBox(gridPane, ++gridRow, - Res.get("shared.reserveExactAmount")); - - GridPane.setHalignment(reserveExactAmountCheckbox, HPos.LEFT); - - reserveExactAmountCheckbox.setVisible(false); - reserveExactAmountCheckbox.setSelected(preferences.getSplitOfferOutput()); - reserveExactAmountCheckbox.setOnAction(event -> { - boolean selected = reserveExactAmountCheckbox.isSelected(); + + reserveExactAmountSlider = FormBuilder.addSlideToggleButton(gridPane, ++gridRow, Res.get("shared.reserveExactAmount"), heightAdjustment); + GridPane.setHalignment(reserveExactAmountSlider, HPos.LEFT); + GridPane.setMargin(reserveExactAmountSlider, new Insets(-5, 0, -5, 0)); + reserveExactAmountSlider.setPadding(new Insets(0, 0, 0, 0)); + reserveExactAmountSlider.setVisible(false); + reserveExactAmountSlider.setSelected(preferences.getSplitOfferOutput()); + reserveExactAmountSlider.setOnAction(event -> { + boolean selected = reserveExactAmountSlider.isSelected(); if (selected != preferences.getSplitOfferOutput()) { preferences.setSplitOfferOutput(selected); model.dataModel.setReserveExactAmount(selected); @@ -1338,7 +1340,7 @@ private void addAmountPriceFields() { firstRowHBox.getChildren().addAll(amountBox, xLabel, percentagePriceBox, resultLabel, volumeBox); GridPane.setColumnSpan(firstRowHBox, 2); GridPane.setRowIndex(firstRowHBox, gridRow); - GridPane.setMargin(firstRowHBox, new Insets(40, 10, 0, 0)); + GridPane.setMargin(firstRowHBox, new Insets(40 + heightAdjustment, 10, 0, 0)); gridPane.getChildren().add(firstRowHBox); }