Skip to content

Commit

Permalink
Make sure dropdown content always has the same width
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Aug 25, 2024
1 parent fcd9b8f commit 6d4f668
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class DropdownMenu extends HBox {
private boolean openUpwards = false;
@Setter
private boolean openToTheRight = false;
private Double prefWidth = null;

public DropdownMenu(String defaultIconId, String activeIconId, boolean useIconOnly) {
defaultIcon = ImageUtil.getImageViewById(defaultIconId);
Expand Down Expand Up @@ -151,6 +152,9 @@ private void attachListeners() {
getStyleClass().add("dropdown-menu-active");
updateIcon(activeIcon);
isMenuShowing.setValue(true);
if (prefWidth != null && contextMenu.getItems().getFirst() instanceof DropdownMenuItem) {
updateMenuItemWidth();
}
});
contextMenu.setOnHidden(e -> {
getStyleClass().remove("dropdown-menu-active");
Expand All @@ -163,19 +167,24 @@ private void attachListeners() {
isFirstRun = true;
// Once the contextMenu has calculated the width on the first render time we update the items
// so that they all have the same size.
for (MenuItem item : contextMenu.getItems()) {
if (item instanceof DropdownBisqMenuItem dropdownBisqMenuItem) {
dropdownBisqMenuItem.updateWidth(contextMenu.getWidth() - 18); // Remove margins
}
if (item instanceof DropdownMenuItem dropdownMenuItem) {
dropdownMenuItem.updateWidth(contextMenu.getWidth() - 18); // Remove margins
}
}
prefWidth = contextMenu.getWidth() - 18; // Remove margins
updateMenuItemWidth();
}
};
contextMenu.widthProperty().addListener(new WeakChangeListener<>(widthPropertyChangeListener));
}

private void updateMenuItemWidth() {
for (MenuItem item : contextMenu.getItems()) {
if (item instanceof DropdownBisqMenuItem dropdownBisqMenuItem) {
dropdownBisqMenuItem.updateWidth(prefWidth);
}
if (item instanceof DropdownMenuItem dropdownMenuItem) {
dropdownMenuItem.updateWidth(prefWidth);
}
}
}

private void updateIcon(ImageView newIcon) {
if (buttonIcon != newIcon) {
getChildren().remove(buttonIcon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -245,18 +246,21 @@ private void updateMarketPaymentFilters() {
cleanUpPaymentsFilterMenu();

model.getAvailableMarketPayments().forEach(payment -> {
ImageView icon = ImageUtil.getImageViewById(payment.getName());
Label label = new Label(payment.getDisplayString(), icon);
label.setGraphicTextGap(5);
PaymentMenuItem item = new PaymentMenuItem(label);
ImageView paymentIcon = ImageUtil.getImageViewById(payment.getName());
Label paymentLabel = new Label(payment.getDisplayString(), paymentIcon);
paymentLabel.setGraphicTextGap(10);
PaymentMenuItem item = new PaymentMenuItem(paymentLabel);
item.setOnAction(e -> {
item.updateSelection(!item.isSelected());
controller.toggleMethodFilter(payment, item.isSelected());
});
paymentsFilterMenu.addMenuItems(item);
});

Label customPaymentLabel = new Label(Res.get("bisqEasy.offerbook.offerList.table.filters.paymentMethods.customMethod"));
StackPane customPaymentIcon = BisqEasyViewUtils.getCustomPaymentMethodIcon("C");
Label customPaymentLabel = new Label(
Res.get("bisqEasy.offerbook.offerList.table.filters.paymentMethods.customPayments"), customPaymentIcon);
customPaymentLabel.setGraphicTextGap(10);
PaymentMenuItem customItem = new PaymentMenuItem(customPaymentLabel);
customItem.setOnAction(e -> {
customItem.updateSelection(!customItem.isSelected());
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/bisq_easy.properties
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ bisqEasy.offerbook.offerList.table.filters.offerDirection.buyFrom=Buy from
bisqEasy.offerbook.offerList.table.filters.offerDirection.sellTo=Sell to
bisqEasy.offerbook.offerList.table.filters.paymentMethods.title=Payments ({0})
bisqEasy.offerbook.offerList.table.filters.paymentMethods.title.all=All
bisqEasy.offerbook.offerList.table.filters.paymentMethods.customMethod=Custom methods
bisqEasy.offerbook.offerList.table.filters.paymentMethods.customPayments=Custom payments

bisqEasy.offerbook.offerList.table.columns.price.tooltip.fixPrice=Fixed price: {0}\nPercentage from current market price: {1}
bisqEasy.offerbook.offerList.table.columns.price.tooltip.marketPrice=Market price: {0}
Expand Down

0 comments on commit 6d4f668

Please sign in to comment.