Skip to content

Commit

Permalink
fix: listen for changes in layout bounds in FXGLDefaultMenu.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart-del committed Mar 26, 2024
1 parent ace11d1 commit 8d5c543
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 8d5c543

Please sign in to comment.