Skip to content

Commit ebf450b

Browse files
committed
Improve alignment in multiline alert dialogs
1 parent 41a7d61 commit ebf450b

3 files changed

Lines changed: 23 additions & 49 deletions

File tree

tabshell-demo/src/main/java/com/techsenger/tabshell/demo/dialogs/DialogsDialogPresenter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class DialogsDialogPresenter extends AbstractDialogPresenter<DialogsDialo
4747
.addAlertDialog(AlertDialogType.WARNING, "Attention! You shouldn't do it!");
4848
}),
4949
Map.entry(DialogType.ERROR, () -> {
50-
var dialog = getView().getComposer().addAlertDialog(AlertDialogType.ERROR, "Oops! That didn’t work.");
50+
var dialog = getView().getComposer().addAlertDialog(AlertDialogType.ERROR,
51+
"Oops! That didn’t work.\nTwo times!");
5152
}),
5253
Map.entry(DialogType.YES_NO, () -> {
5354
var dialog = getView().getComposer()

tabshell-dialogs/src/main/java/com/techsenger/tabshell/dialogs/alert/AlertDialogFxView.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
import atlantafx.base.theme.Styles;
2020
import com.techsenger.tabshell.core.dialog.AbstractDialogFxView;
2121
import static com.techsenger.tabshell.dialogs.alert.AlertDialogType.ERROR;
22-
import com.techsenger.tabshell.dialogs.utils.FxViewUtils;
2322
import com.techsenger.tabshell.material.button.ResultButton;
2423
import com.techsenger.tabshell.material.button.ResultButtonName;
2524
import com.techsenger.tabshell.material.icon.Icon;
2625
import com.techsenger.tabshell.material.icon.IconViewBox;
26+
import com.techsenger.tabshell.material.style.Spacing;
2727
import com.techsenger.toolkit.fx.utils.NodeUtils;
28+
import javafx.geometry.Pos;
2829
import javafx.scene.control.Label;
2930
import javafx.scene.layout.HBox;
31+
import javafx.scene.layout.Priority;
32+
import javafx.scene.layout.VBox;
3033

3134
/**
3235
*
@@ -39,7 +42,20 @@ public class AlertDialogFxView<P extends AlertDialogPresenter<?>> extends Abstra
3942

4043
private final Label messageLabel = new Label();
4144

42-
private final HBox messageBox = new HBox(messageIconViewBox, messageLabel);
45+
private final HBox messageBox = new HBox(messageIconViewBox, messageLabel) {
46+
47+
@Override
48+
protected void layoutChildren() {
49+
super.layoutChildren();
50+
double labelHeight = messageLabel.prefHeight(-1);
51+
double iconHeight = messageIconViewBox.prefHeight(-1);
52+
if (labelHeight >= iconHeight) {
53+
setAlignment(Pos.TOP_LEFT);
54+
} else {
55+
setAlignment(Pos.CENTER_LEFT);
56+
}
57+
}
58+
};
4359

4460
private final ResultButton okButton = new ResultButton(AlertDialogButtons.OK, "OK");
4561

@@ -100,7 +116,9 @@ protected void build() {
100116
throw new AssertionError();
101117
}
102118
messageLabel.getStyleClass().add("message-label");
103-
FxViewUtils.buildIconedMessageBox(messageIconViewBox, messageLabel, messageBox);
119+
VBox.setVgrow(messageBox, Priority.ALWAYS);
120+
messageBox.getStyleClass().add("message-box");
121+
messageBox.setSpacing(Spacing.HORIZONTAL_HALF);
104122
getContentBox().getChildren().add(messageBox);
105123
registerButtons(okButton, cancelButton, noButton, yesButton);
106124
}

tabshell-dialogs/src/main/java/com/techsenger/tabshell/dialogs/utils/FxViewUtils.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)