From 8d5c543645e502abb675b90087ae34764b196d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Wysocki?= Date: Tue, 26 Mar 2024 18:36:18 +0100 Subject: [PATCH 1/2] fix: listen for changes in layout bounds in FXGLDefaultMenu.kt --- .../almasb/fxgl/app/scene/FXGLDefaultMenu.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt index 52363b8cd..e8fc0e54c 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt @@ -188,19 +188,25 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) { } private fun createTitleView(title: String): Node { - val text = getUIFactoryService().newText(title.substring(0, 1), 50.0) - text.fill = null - text.strokeProperty().bind(titleColor) - text.strokeWidth = 1.5 + val firstLetter = getUIFactoryService().newText(title.substring(0, 1), 50.0) + firstLetter.fill = null + firstLetter.strokeProperty().bind(titleColor) + firstLetter.strokeWidth = 1.5 - val text2 = getUIFactoryService().newText(title.substring(1, title.length), 50.0) - text2.fill = null - text2.stroke = titleColor.value - text2.strokeWidth = 1.5 + val restOfTheTittle = getUIFactoryService().newText(title.substring(1, title.length), 50.0) + restOfTheTittle.fill = null + restOfTheTittle.stroke = titleColor.value + restOfTheTittle.strokeWidth = 1.5 - val textWidth = text.layoutBounds.width + text2.layoutBounds.width + var firstLetterWidth = firstLetter.layoutBounds.width + var restOfTheTittleWidth = restOfTheTittle.layoutBounds.width - val border = Rectangle(textWidth + 30, 65.0, null) + firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> firstLetterWidth = newBounds.width} + restOfTheTittle.layoutBoundsProperty().addListener { _, _, newBounds -> restOfTheTittleWidth = newBounds.width} + + val tittleWidth = firstLetterWidth + restOfTheTittleWidth + + val border = Rectangle(tittleWidth + 30, 65.0, null) border.stroke = Color.WHITE border.strokeWidth = 4.0 border.arcWidth = 25.0 @@ -224,11 +230,11 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) { emitter.setSpawnPointFunction { Point2D.ZERO } emitter.setAccelerationFunction { Point2D(random(-1.0, 1.0), random(0.0, 0.0)) } - val box = HBox(text, text2) + val box = HBox(firstLetter, restOfTheTittle) box.alignment = Pos.CENTER val titleRoot = StackPane(border, box) - titleRoot.translateX = appWidth / 2.0 - (textWidth + 30) / 2 + titleRoot.translateX = appWidth / 2.0 - (tittleWidth + 30) / 2 titleRoot.translateY = 50.0 if (!FXGL.getSettings().isNative) From de3fc7493e5bc3f7c36c303140fe8b54c80640bb Mon Sep 17 00:00:00 2001 From: Almas Baim Date: Wed, 18 Dec 2024 21:48:53 +0000 Subject: [PATCH 2/2] fixed typo --- .../almasb/fxgl/app/scene/FXGLDefaultMenu.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt index e8fc0e54c..aed2a068b 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt @@ -193,20 +193,20 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) { firstLetter.strokeProperty().bind(titleColor) firstLetter.strokeWidth = 1.5 - val restOfTheTittle = getUIFactoryService().newText(title.substring(1, title.length), 50.0) - restOfTheTittle.fill = null - restOfTheTittle.stroke = titleColor.value - restOfTheTittle.strokeWidth = 1.5 + val restOfTheTitle = getUIFactoryService().newText(title.substring(1, title.length), 50.0) + restOfTheTitle.fill = null + restOfTheTitle.stroke = titleColor.value + restOfTheTitle.strokeWidth = 1.5 var firstLetterWidth = firstLetter.layoutBounds.width - var restOfTheTittleWidth = restOfTheTittle.layoutBounds.width + var restOfTheTitleWidth = restOfTheTitle.layoutBounds.width firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> firstLetterWidth = newBounds.width} - restOfTheTittle.layoutBoundsProperty().addListener { _, _, newBounds -> restOfTheTittleWidth = newBounds.width} + restOfTheTitle.layoutBoundsProperty().addListener { _, _, newBounds -> restOfTheTitleWidth = newBounds.width} - val tittleWidth = firstLetterWidth + restOfTheTittleWidth + val titleWidth = firstLetterWidth + restOfTheTitleWidth - val border = Rectangle(tittleWidth + 30, 65.0, null) + val border = Rectangle(titleWidth + 30, 65.0, null) border.stroke = Color.WHITE border.strokeWidth = 4.0 border.arcWidth = 25.0 @@ -230,11 +230,11 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) { emitter.setSpawnPointFunction { Point2D.ZERO } emitter.setAccelerationFunction { Point2D(random(-1.0, 1.0), random(0.0, 0.0)) } - val box = HBox(firstLetter, restOfTheTittle) + val box = HBox(firstLetter, restOfTheTitle) box.alignment = Pos.CENTER val titleRoot = StackPane(border, box) - titleRoot.translateX = appWidth / 2.0 - (tittleWidth + 30) / 2 + titleRoot.translateX = appWidth / 2.0 - (titleWidth + 30) / 2 titleRoot.translateY = 50.0 if (!FXGL.getSettings().isNative)