Skip to content

Commit

Permalink
Use popup instead of overlay for market selection
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Oct 27, 2024
1 parent 6543ae0 commit 04f8b92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ void onMarketListItemClicked(TradeWizardDirectionAndMarketView.ListItem item) {
.ifPresent(bisqEasyOfferbookSelectionService::selectChannel);
}

void updateNavigationButtonsVisibility(boolean shouldShow) {
navigationButtonsVisibleHandler.accept(shouldShow);
}

private void setDirection(Direction direction) {
model.getDirection().set(direction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.desktop.common.Transitions;
import bisq.desktop.common.view.View;
import bisq.desktop.components.containers.Spacer;
import bisq.desktop.components.controls.BisqPopup;
import bisq.desktop.components.controls.BisqTooltip;
import bisq.desktop.components.controls.SearchBox;
import bisq.desktop.components.table.BisqTableColumn;
Expand All @@ -30,6 +31,7 @@
import bisq.desktop.main.content.components.MarketImageComposition;
import bisq.i18n.Res;
import bisq.offer.Direction;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
Expand All @@ -44,6 +46,7 @@
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextAlignment;
import javafx.stage.PopupWindow;
import javafx.util.Callback;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -62,7 +65,7 @@ public class TradeWizardDirectionAndMarketView extends View<StackPane, TradeWiza
private final VBox content;
private final BisqTableView<TradeWizardDirectionAndMarketView.ListItem> tableView;
private final SearchBox searchBox;
private final StackPane tableViewWithSearchBox;
private final BisqPopup marketSelectionPopup;
private Subscription directionSubscription, showReputationInfoPin, marketPin;
private Button withoutReputationButton, backToBuyButton;
private Button gainReputationButton;
Expand All @@ -88,20 +91,22 @@ public TradeWizardDirectionAndMarketView(TradeWizardDirectionAndMarketModel mode

tableView = new BisqTableView<>(model.getSortedList());
tableView.getStyleClass().add("bisq-easy-trade-wizard-market");
double tableHeight = 250;
double tableHeight = 325;
double tableWidth = 600;
tableView.setPrefSize(tableWidth, tableHeight);
tableView.setFixedCellSize(50);
tableView.setFixedCellSize(55);
configTableView();

StackPane.setMargin(searchBox, new Insets(5, 0, 0, 15));
tableViewWithSearchBox = new StackPane(tableView, searchBox);
StackPane tableViewWithSearchBox = new StackPane(tableView, searchBox);
tableViewWithSearchBox.setAlignment(Pos.TOP_LEFT);
tableViewWithSearchBox.setPrefSize(tableWidth, tableHeight);
tableViewWithSearchBox.setMaxWidth(tableWidth);
tableViewWithSearchBox.setMaxHeight(tableHeight);
tableViewWithSearchBox.getStyleClass().add("markets-table-container");
updateMarketSelectionTableVisibility(false);
marketSelectionPopup = new BisqPopup();
marketSelectionPopup.setContentNode(tableViewWithSearchBox);
marketSelectionPopup.setAnchorLocation(PopupWindow.AnchorLocation.WINDOW_TOP_RIGHT);

buyButton = createAndGetDirectionButton(Res.get("bisqEasy.tradeWizard.directionAndMarket.buy"));
sellButton = createAndGetDirectionButton(Res.get("bisqEasy.tradeWizard.directionAndMarket.sell"));
Expand All @@ -116,8 +121,7 @@ public TradeWizardDirectionAndMarketView(TradeWizardDirectionAndMarketModel mode
setupReputationInfo();

StackPane.setMargin(reputationInfo, new Insets(-TradeWizardView.TOP_PANE_HEIGHT, 0, 0, 0));
StackPane.setMargin(tableViewWithSearchBox, new Insets(130, 0, 0, 0));
root.getChildren().addAll(content, tableViewWithSearchBox, reputationInfo);
root.getChildren().addAll(content, reputationInfo);
root.setAlignment(Pos.CENTER);
}

Expand All @@ -130,18 +134,10 @@ protected void onViewAttached() {
// not when we set the selected item by code.
tableView.setOnMouseClicked(e -> controller.onMarketListItemClicked(tableView.getSelectionModel().getSelectedItem()));
quoteCurrencyLabel.setOnMouseClicked(e -> {
updateMarketSelectionTableVisibility(!tableViewWithSearchBox.isVisible());
if (tableViewWithSearchBox.isVisible()) {
e.consume();
}
});
// TODO: Add keyEvent handler in root for ESC
root.setOnMouseClicked(e -> {
if (tableViewWithSearchBox.isVisible()) {
updateMarketSelectionTableVisibility(false);
}
Bounds rootBounds = root.localToScreen(root.getBoundsInLocal());
Bounds labelBounds = quoteCurrencyLabel.localToScreen(quoteCurrencyLabel.getBoundsInLocal());
marketSelectionPopup.show(quoteCurrencyLabel, rootBounds.getMaxX() - 120, labelBounds.getMaxY() + 15);
});
updateMarketSelectionTableVisibility(false);

searchBox.textProperty().bindBidirectional(model.getSearchText());

Expand Down Expand Up @@ -190,7 +186,6 @@ protected void onViewDetached() {
searchBox.textProperty().unbindBidirectional(model.getSearchText());
tableView.setOnMouseClicked(null);
quoteCurrencyLabel.setOnMouseClicked(null);
root.setOnMouseClicked(null);

if (model.getShowReputationInfo().get()) {
Transitions.removeEffect(content);
Expand All @@ -208,12 +203,6 @@ protected void onViewDetached() {
marketPin.unsubscribe();
}

private void updateMarketSelectionTableVisibility(boolean shouldShow) {
tableViewWithSearchBox.setVisible(shouldShow);
tableViewWithSearchBox.setManaged(shouldShow);
controller.updateNavigationButtonsVisibility(!shouldShow);
}

private Button createAndGetDirectionButton(String title) {
Button button = new Button(title);
button.getStyleClass().add("card-button");
Expand Down

0 comments on commit 04f8b92

Please sign in to comment.