Skip to content

Commit fe9d66f

Browse files
IVS-189 Improve autoresizing
1 parent eff753f commit fe9d66f

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

testar/src/nl/ou/testar/jfx/MainController.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javafx.scene.Parent;
44
import javafx.scene.layout.AnchorPane;
5+
import javafx.stage.Stage;
56
import nl.ou.testar.jfx.core.NavigationController;
67
import nl.ou.testar.jfx.core.NavigationDelegate;
78
import nl.ou.testar.jfx.core.ViewController;
@@ -25,6 +26,8 @@ enum Mode {
2526
private SettingsController settingsController;
2627
private MiscController miscController;
2728

29+
private Stage stage = null;
30+
2831
public DashboardController getDashboardController() {
2932
return dashboardController;
3033
}
@@ -38,6 +41,7 @@ public MainController(Settings settings, String settingsPath) {
3841
}
3942

4043
private void setupMode(Parent view, Mode mode) {
44+
4145
if (mode != this.mode) {
4246
// final Label titleLabel = (Label) view.lookup("#titleLabel");
4347
// final Button btnBack = (Button) view.lookup("#btnBack");
@@ -67,9 +71,17 @@ public void onViewControllerActivated(ViewController viewController, Parent view
6771
AnchorPane.setTopAnchor(view, 0.0);
6872
AnchorPane.setRightAnchor(view, 0.0);
6973
AnchorPane.setBottomAnchor(view, 0.0);
70-
// btnBack.setVisible(navigationController.isBackAvailable());
71-
// contentPane.getChildren().removeAll();
72-
// contentPane.getChildren().add(view);
74+
75+
if (stage != null) {
76+
double width = stage.getWidth();
77+
double height = stage.getHeight();
78+
79+
view.setVisible(false);
80+
stage.sizeToScene();
81+
stage.setWidth(Math.max(width, stage.getWidth()));
82+
stage.setHeight(Math.max(height, stage.getHeight()));
83+
view.setVisible(true);
84+
}
7385
}
7486
});
7587

@@ -89,6 +101,7 @@ public void viewDidLoad(Parent view) {
89101

90102
btnHome.setOnAction(event -> {
91103
setupMode(view, Mode.HOME);
104+
92105
});
93106

94107
btnSettings.setOnAction(event -> {
@@ -101,4 +114,9 @@ public void viewDidLoad(Parent view) {
101114

102115
setupMode(view, Mode.HOME);
103116
}
117+
118+
@Override
119+
public void viewDidAppear(Parent view) {
120+
stage = (Stage) view.getScene().getWindow();
121+
}
104122
}

testar/src/org/testar/monkey/Main.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,6 @@ public void onViewControllerActivated(ViewController viewController, Parent view
393393
stage.setScene(new Scene(view));
394394
stage.sizeToScene();
395395
stage.show();
396-
// stage.setMinWidth(stage.getWidth());
397-
// stage.setMinHeight(stage.getHeight());
398396
}
399397
});
400398
}

0 commit comments

Comments
 (0)