Initialize scene with stage size in SceneContext

This apparently fixes the rendering issues when switching scenes, while
keeping the stage size constant (unless the user resizes the stage).
This commit is contained in:
Kai S. K. Engelbart 2020-11-20 14:01:00 +01:00
parent e3052a2133
commit 67ebc6be83
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
3 changed files with 16 additions and 12 deletions

View File

@ -66,12 +66,11 @@ public final class SceneContext implements EventListener {
if (scene == null) { if (scene == null) {
// One-time scene initialization // One-time scene initialization
scene = new Scene(root); scene = new Scene(root, stage.getWidth(), stage.getHeight());
applyCSS(); applyCSS();
stage.setScene(scene); stage.setScene(scene);
} else { } else {
scene.setRoot(root); scene.setRoot(root);
stage.sizeToScene();
} }
stage.setResizable(info.resizable); stage.setResizable(info.resizable);

View File

@ -24,8 +24,8 @@
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" <GridPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="400.0" minWidth="500.0" minHeight="400.0" minWidth="500.0"
prefHeight="${screen.visualBounds.height}"
prefWidth="${screen.visualBounds.width}" prefWidth="${screen.visualBounds.width}"
prefHeight="${screen.visualBounds.height}"
xmlns="http://javafx.com/javafx/11.0.1" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.ChatScene"> fx:controller="envoy.client.ui.controller.ChatScene">
@ -57,8 +57,7 @@
<content> <content>
<AnchorPane minHeight="0.0" minWidth="0.0"> <AnchorPane minHeight="0.0" minWidth="0.0">
<children> <children>
<VBox prefHeight="3000.0" <VBox prefHeight="3000.0" prefWidth="316.0">
prefWidth="316.0">
<children> <children>
<VBox id="search-panel" maxHeight="-Infinity" <VBox id="search-panel" maxHeight="-Infinity"
minHeight="-Infinity" prefHeight="80.0" prefWidth="316.0"> minHeight="-Infinity" prefHeight="80.0" prefWidth="316.0">
@ -156,8 +155,7 @@
<Insets left="15.0" top="5.0" right="10.0" /> <Insets left="15.0" top="5.0" right="10.0" />
</HBox.margin> </HBox.margin>
</ImageView> </ImageView>
<Region id="transparent-background" <Region id="transparent-background" HBox.hgrow="ALWAYS" />
HBox.hgrow="ALWAYS" />
<Button fx:id="settingsButton" mnemonicParsing="false" <Button fx:id="settingsButton" mnemonicParsing="false"
onAction="#settingsButtonClicked" prefHeight="30.0" onAction="#settingsButtonClicked" prefHeight="30.0"
prefWidth="30.0" alignment="CENTER_RIGHT"> prefWidth="30.0" alignment="CENTER_RIGHT">
@ -165,7 +163,7 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
<HBox.margin> <HBox.margin>
<Insets bottom="35.0" left="5.0" top="35.0" right="10.0"/> <Insets bottom="35.0" left="5.0" top="35.0" right="10.0" />
</HBox.margin> </HBox.margin>
</Button> </Button>
</children> </children>

View File

@ -7,11 +7,16 @@
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox alignment="TOP_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.SettingsScene"> <VBox alignment="TOP_RIGHT" maxHeight="-Infinity" minHeight="400.0"
minWidth="500.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.SettingsScene">
<children> <children>
<HBox prefHeight="389.0" prefWidth="600.0"> <HBox prefHeight="389.0" prefWidth="600.0">
<children> <children>
<ListView id="message-list" fx:id="settingsList" onMouseClicked="#settingsListClicked" prefHeight="200.0" prefWidth="200.0"> <ListView id="message-list" fx:id="settingsList"
onMouseClicked="#settingsListClicked" prefHeight="200.0"
prefWidth="200.0">
<opaqueInsets> <opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets> </opaqueInsets>
@ -22,7 +27,8 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
</ListView> </ListView>
<TitledPane fx:id="titledPane" collapsible="false" prefHeight="400.0" prefWidth="400.0"> <TitledPane fx:id="titledPane" collapsible="false"
prefHeight="400.0" prefWidth="400.0">
<HBox.margin> <HBox.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0" /> <Insets bottom="10.0" left="5.0" right="10.0" top="10.0" />
</HBox.margin> </HBox.margin>
@ -32,7 +38,8 @@
</TitledPane> </TitledPane>
</children> </children>
</HBox> </HBox>
<Button defaultButton="true" mnemonicParsing="true" onMouseClicked="#backButtonClicked" text="_Back"> <Button defaultButton="true" mnemonicParsing="true"
onMouseClicked="#backButtonClicked" text="_Back">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>