Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve space management in button bar of overlays #2699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.desktop.app.BisqApp;
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.AutoTooltipCheckBox;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.BusyAnimation;
import bisq.desktop.main.MainView;
Expand Down Expand Up @@ -85,8 +86,6 @@

import lombok.extern.slf4j.Slf4j;

import static bisq.desktop.util.FormBuilder.addCheckBox;

@Slf4j
public abstract class Overlay<T extends Overlay> {

Expand Down Expand Up @@ -156,6 +155,7 @@ protected enum Type {
truncatedMessage;
private String headlineStyle;
protected Button actionButton, secondaryActionButton;
private HBox buttonBox;
protected AutoTooltipButton closeButton;

private HPos buttonAlignment = HPos.RIGHT;
Expand Down Expand Up @@ -867,11 +867,12 @@ protected void addDontShowAgainCheckBox(boolean isChecked) {
if (dontShowAgainText == null)
dontShowAgainText = Res.get("popup.doNotShowAgain");

CheckBox dontShowAgainCheckBox = addCheckBox(gridPane, rowIndex, dontShowAgainText, buttonDistance - 1);
CheckBox dontShowAgainCheckBox = new AutoTooltipCheckBox(dontShowAgainText);
HBox.setHgrow(dontShowAgainCheckBox, Priority.NEVER);
buttonBox.getChildren().add(0, dontShowAgainCheckBox);

dontShowAgainCheckBox.setSelected(isChecked);
DontShowAgainLookup.dontShowAgain(dontShowAgainId, isChecked);
GridPane.setColumnIndex(dontShowAgainCheckBox, 0);
GridPane.setHalignment(dontShowAgainCheckBox, HPos.LEFT);
dontShowAgainCheckBox.setOnAction(e -> DontShowAgainLookup.dontShowAgain(dontShowAgainId, dontShowAgainCheckBox.isSelected()));
}
}
Expand All @@ -885,10 +886,30 @@ protected void addButtons() {
closeButton = new AutoTooltipButton(closeButtonText == null ? Res.get("shared.close") : closeButtonText);
closeButton.getStyleClass().add("compact-button");
closeButton.setOnAction(event -> doClose());
closeButton.setMinWidth(120);
HBox.setHgrow(closeButton, Priority.SOMETIMES);
}

Pane spacer = new Pane();

if (buttonAlignment == HPos.RIGHT) {
HBox.setHgrow(spacer, Priority.ALWAYS);
spacer.setMaxWidth(Double.MAX_VALUE);
}

buttonBox = new HBox();

GridPane.setHalignment(buttonBox, buttonAlignment);
GridPane.setRowIndex(buttonBox, ++rowIndex);
GridPane.setColumnSpan(buttonBox, 2);
GridPane.setMargin(buttonBox, new Insets(buttonDistance, 0, 0, 0));
gridPane.getChildren().add(buttonBox);

if (actionHandlerOptional.isPresent() || actionButtonText != null) {
actionButton = new AutoTooltipButton(actionButtonText == null ? Res.get("shared.ok") : actionButtonText);
actionButton.setDefaultButton(true);
HBox.setHgrow(actionButton, Priority.SOMETIMES);

actionButton.getStyleClass().add("action-button");
//TODO app wide focus
//actionButton.requestFocus();
Expand All @@ -897,17 +918,14 @@ protected void addButtons() {
actionHandlerOptional.ifPresent(Runnable::run);
});

Pane spacer = new Pane();

HBox hBox = new HBox();
hBox.setSpacing(10);
buttonBox.setSpacing(10);

hBox.setAlignment(Pos.CENTER);
buttonBox.setAlignment(Pos.CENTER);

if (buttonAlignment == HPos.RIGHT)
hBox.getChildren().add(spacer);
buttonBox.getChildren().add(spacer);

hBox.getChildren().addAll(actionButton);
buttonBox.getChildren().addAll(actionButton);

if (secondaryActionButtonText != null && secondaryActionHandlerOptional.isPresent()) {
secondaryActionButton = new AutoTooltipButton(secondaryActionButtonText);
Expand All @@ -916,31 +934,14 @@ protected void addButtons() {
secondaryActionHandlerOptional.ifPresent(Runnable::run);
});

hBox.getChildren().add(secondaryActionButton);
buttonBox.getChildren().add(secondaryActionButton);
}

if (!hideCloseButton)
hBox.getChildren().add(closeButton);


if (buttonAlignment == HPos.RIGHT) {
HBox.setHgrow(spacer, Priority.ALWAYS);
spacer.setMaxWidth(Double.MAX_VALUE);
}

GridPane.setHalignment(hBox, buttonAlignment);
GridPane.setRowIndex(hBox, ++rowIndex);
GridPane.setColumnSpan(hBox, 2);
GridPane.setMargin(hBox, new Insets(buttonDistance, 0, 0, 0));
gridPane.getChildren().add(hBox);
buttonBox.getChildren().add(closeButton);
} else if (!hideCloseButton) {
closeButton.setDefaultButton(true);
GridPane.setHalignment(closeButton, buttonAlignment);
GridPane.setColumnSpan(closeButton, 2);
if (!showReportErrorButtons)
GridPane.setMargin(closeButton, new Insets(buttonDistance, 0, 0, 0));
GridPane.setRowIndex(closeButton, ++rowIndex);
gridPane.getChildren().add(closeButton);
buttonBox.getChildren().addAll(spacer, closeButton);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ protected void onShow() {
protected void addButtons() {
super.addButtons();

closeButton.setPrefWidth(162);
actionButton.setPrefWidth(162);
closeButton.prefWidthProperty().bind(actionButton.widthProperty());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the setters are never called in any other popup? It would cause an error if binding is set and we call setWidth somewhere else....

Ah its not in the super class, so should be isolated then to that window.

utACK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was just to have the same button width based on Pedro's design for this popup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But still to support bigger button sizes for different languages

}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down