Skip to content

Commit

Permalink
Merge pull request #2699 from ripcurlx/improve-overlay-button-handling
Browse files Browse the repository at this point in the history
Improve space management in button bar of overlays
  • Loading branch information
ManfredKarrer authored Apr 11, 2019
2 parents e6f12da + b01e1c9 commit d7195c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
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());
}

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

0 comments on commit d7195c4

Please sign in to comment.