Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 restOfTheTitle = getUIFactoryService().newText(title.substring(1, title.length), 50.0)
restOfTheTitle.fill = null
restOfTheTitle.stroke = titleColor.value
restOfTheTitle.strokeWidth = 1.5

val textWidth = text.layoutBounds.width + text2.layoutBounds.width
var firstLetterWidth = firstLetter.layoutBounds.width
var restOfTheTitleWidth = restOfTheTitle.layoutBounds.width

val border = Rectangle(textWidth + 30, 65.0, null)
firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> firstLetterWidth = newBounds.width}
restOfTheTitle.layoutBoundsProperty().addListener { _, _, newBounds -> restOfTheTitleWidth = newBounds.width}

val titleWidth = firstLetterWidth + restOfTheTitleWidth

val border = Rectangle(titleWidth + 30, 65.0, null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The width of this rectangle is still fixed, it should be updated based on changes to layout bounds of the text objects. Something like:

firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> update border width }

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, restOfTheTitle)
box.alignment = Pos.CENTER

val titleRoot = StackPane(border, box)
titleRoot.translateX = appWidth / 2.0 - (textWidth + 30) / 2
titleRoot.translateX = appWidth / 2.0 - (titleWidth + 30) / 2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translateX property should also be bound to the new value of restOfTheTitle layout bounds. Something like:

firstLetter.layoutBoundsProperty().addListener { _, _, newBounds -> update titleRoot translateX }

titleRoot.translateY = 50.0

if (!FXGL.getSettings().isNative)
Expand Down