Skip to content

Commit 8d5c543

Browse files
committed
fix: listen for changes in layout bounds in FXGLDefaultMenu.kt
1 parent ace11d1 commit 8d5c543

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt

+18-12
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,25 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
188188
}
189189

190190
private fun createTitleView(title: String): Node {
191-
val text = getUIFactoryService().newText(title.substring(0, 1), 50.0)
192-
text.fill = null
193-
text.strokeProperty().bind(titleColor)
194-
text.strokeWidth = 1.5
191+
val firstLetter = getUIFactoryService().newText(title.substring(0, 1), 50.0)
192+
firstLetter.fill = null
193+
firstLetter.strokeProperty().bind(titleColor)
194+
firstLetter.strokeWidth = 1.5
195195

196-
val text2 = getUIFactoryService().newText(title.substring(1, title.length), 50.0)
197-
text2.fill = null
198-
text2.stroke = titleColor.value
199-
text2.strokeWidth = 1.5
196+
val restOfTheTittle = getUIFactoryService().newText(title.substring(1, title.length), 50.0)
197+
restOfTheTittle.fill = null
198+
restOfTheTittle.stroke = titleColor.value
199+
restOfTheTittle.strokeWidth = 1.5
200200

201-
val textWidth = text.layoutBounds.width + text2.layoutBounds.width
201+
var firstLetterWidth = firstLetter.layoutBounds.width
202+
var restOfTheTittleWidth = restOfTheTittle.layoutBounds.width
202203

203-
val border = Rectangle(textWidth + 30, 65.0, null)
204+
firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> firstLetterWidth = newBounds.width}
205+
restOfTheTittle.layoutBoundsProperty().addListener { _, _, newBounds -> restOfTheTittleWidth = newBounds.width}
206+
207+
val tittleWidth = firstLetterWidth + restOfTheTittleWidth
208+
209+
val border = Rectangle(tittleWidth + 30, 65.0, null)
204210
border.stroke = Color.WHITE
205211
border.strokeWidth = 4.0
206212
border.arcWidth = 25.0
@@ -224,11 +230,11 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
224230
emitter.setSpawnPointFunction { Point2D.ZERO }
225231
emitter.setAccelerationFunction { Point2D(random(-1.0, 1.0), random(0.0, 0.0)) }
226232

227-
val box = HBox(text, text2)
233+
val box = HBox(firstLetter, restOfTheTittle)
228234
box.alignment = Pos.CENTER
229235

230236
val titleRoot = StackPane(border, box)
231-
titleRoot.translateX = appWidth / 2.0 - (textWidth + 30) / 2
237+
titleRoot.translateX = appWidth / 2.0 - (tittleWidth + 30) / 2
232238
titleRoot.translateY = 50.0
233239

234240
if (!FXGL.getSettings().isNative)

0 commit comments

Comments
 (0)