Are click handlers on text supported? I've tried ...
# korge
k
Are click handlers on text supported? I've tried
Copy code
class MenuScene : Scene() {
    override suspend fun Container.sceneInit() {
        text("Play") {
            onClick {
                println("Changing to Game scene")
                sceneContainer.changeTo<GameScene>()
            }
        }
    }
}
but the event never triggers.
đź‘€ 1
d
If it doesn’t work, that’s definitely a bug. In the meantime you can create a
solidRect(width, height, Colors.TRANSPARENT_BLACK)
and put the event there Are you rendering the text using a BitmapFont?
k
for now I'm using whatever is the default
d
If you press F7 or F12 it should display a debug overlay displaying clickable areas
does it show anything?
k
message has been deleted
d
that red rectangle is the text clickable area (misplaced) or do you have another view there?
k
let me clean up the scene
d
still, going to check, maybe the bounds are not computed correctly for text. Since we are using buttonText that already included an image in the background maybe we missed the bounds for text. Going to check and to create a regression test
k
Copy code
class MenuScene : Scene() {
    override suspend fun Container.sceneInit() {

            text("Play", color = Colors.WHITE) {
                x = 200.0
                y= 200.0

                onClick {
                    println("Changing to Game scene")
                    sceneContainer.changeTo<GameScene>()
                }
            }
    }
}
that's the whole scene
it seems
Text
doesn't override
hitTest
when I do the solidRect, the text becomes invisible
d
Okay. I’ll fill a bug and will fix it
k
@Deactivated User any tips on the invisible solidRect?
d
uhm how do you place the solidRect?
so I can reproduce it?
I’m checking this right now so I hope to have a fix for the issue in an hour or so
k
OK, no hurry
Just
solidRect { text() }
With the color set to transparent black
d
Oh I see. That’s confusing. SolidRect shouldn’t be a container (legacy stuff that should be removed on KorGE 2.0). What you can do is:
Copy code
container {
   solidRect(100, 20, Colors.TRANSPARENT_BLACK)
   text("hello")
   onClick { ... }
}
https://github.com/korlibs/korge/pull/184 <-- will be available in the next version
đź‘Ť 1