Browse Source

make window resizable (fixes #932)

[ci skip]
Sebastian Stenzel 6 years ago
parent
commit
14de8ffd59

+ 9 - 6
main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java

@@ -2,9 +2,9 @@ package org.cryptomator.ui.mainwindow;
 
 import javafx.fxml.FXML;
 import javafx.scene.layout.HBox;
+import javafx.scene.layout.Region;
 import javafx.stage.Stage;
 import org.cryptomator.ui.FxApplication;
-import org.cryptomator.ui.FxApplicationScoped;
 import org.cryptomator.ui.common.FxController;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,10 +21,8 @@ public class MainWindowController implements FxController {
 	private final CountDownLatch shutdownLatch;
 	private final Stage window;
 	private final FxApplication application;
-
-	@FXML
 	public HBox titleBar;
-
+	public Region resizer;
 	private double xOffset;
 	private double yOffset;
 
@@ -43,8 +41,13 @@ public class MainWindowController implements FxController {
 			yOffset = event.getSceneY();
 		});
 		titleBar.setOnMouseDragged(event -> {
-			titleBar.getScene().getWindow().setX(event.getScreenX() - xOffset);
-			titleBar.getScene().getWindow().setY(event.getScreenY() - yOffset);
+			window.setX(event.getScreenX() - xOffset);
+			window.setY(event.getScreenY() - yOffset);
+		});
+		resizer.setOnMouseDragged(event -> {
+			// we know for a fact that window is borderless. i.e. the scene starts at 0/0 of the window.
+			window.setWidth(event.getSceneX());
+			window.setHeight(event.getSceneY());
 		});
 	}
 

+ 5 - 2
main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java

@@ -29,8 +29,11 @@ public abstract class MainWindowModule {
 	@MainWindowScoped
 	static Stage provideStage() {
 		Stage stage = new Stage();
-		stage.setMinWidth(652.0);
-		stage.setMinHeight(440.0);
+		// TODO: min/max values chosen arbitrarily. We might wanna take a look at the user's resolution...
+		stage.setMinWidth(650);
+		stage.setMinHeight(440);
+		stage.setMaxWidth(1000);
+		stage.setMaxHeight(700);
 		stage.initStyle(StageStyle.UNDECORATED);
 		return stage;
 	}

+ 9 - 4
main/ui/src/main/resources/fxml/main_window.fxml

@@ -8,6 +8,7 @@
 <?import javafx.scene.control.Tooltip?>
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.Region?>
+<?import javafx.scene.layout.StackPane?>
 <?import javafx.scene.layout.VBox?>
 <VBox xmlns="http://javafx.com/javafx"
 	  xmlns:fx="http://javafx.com/fxml"
@@ -38,8 +39,12 @@
 			</Button>
 		</children>
 	</HBox>
-	<SplitPane VBox.vgrow="ALWAYS" dividerPositions="0.33" orientation="HORIZONTAL">
-		<fx:include source="/fxml/vault_list.fxml" SplitPane.resizableWithParent="false"/>
-		<fx:include source="/fxml/vault_detail.fxml" SplitPane.resizableWithParent="true"/>
-	</SplitPane>
+	<StackPane VBox.vgrow="ALWAYS">
+		<SplitPane dividerPositions="0.33" orientation="HORIZONTAL">
+			<fx:include source="/fxml/vault_list.fxml" SplitPane.resizableWithParent="false"/>
+			<fx:include source="/fxml/vault_detail.fxml" SplitPane.resizableWithParent="true"/>
+		</SplitPane>
+		<!-- TODO: move style to css file and make this pretty: -->
+		<Region StackPane.alignment="BOTTOM_RIGHT" fx:id="resizer" prefWidth="10" prefHeight="10" maxWidth="-Infinity" maxHeight="-Infinity"  style="-fx-background-color: red; -fx-cursor: nw_resize;"/>
+	</StackPane>
 </VBox>

+ 0 - 1
main/ui/src/main/resources/fxml/vault_list.fxml

@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
-<?import javafx.geometry.Insets?>
 <?import javafx.scene.control.Button?>
 <?import javafx.scene.control.Label?>
 <?import javafx.scene.control.ListView?>