https://kotlinlang.org logo
#korge
Title
# korge
t

tobsef

07/03/2020, 8:16 PM
A click Event is blocked by a overlaying Container. The hitTest of a Container only uses the bounds which contains all views. So it's not possible the click the green box with index 0. The Container above consumes the click events, because it spreads over the whole screen. Can we use the unused HitTestType of View to change from Bounding to Child? This default Container implementation seems to be not very intuitive and leads to strange behavior (
Container#getLocalBoundsInternal
). It was hard to get out, why my click event doesn't work. It seems to be a performance optimization.
Copy code
suspend fun main() = Korge(width = 512, height = 512) {

    solidRect(100, 100, color = GREEN) {
        centerOn(this@Korge)
        onClick {
            color = if(color == GREEN) BLUE else GREEN
        }
    }

    container {
        solidRect(100, 100, color = RED) {

        }
        solidRect(100, 100, color = RED) {
            alignRightToRightOf(this@Korge)
        }
        solidRect(100, 100, color = RED) {
            alignBottomToBottomOf(this@Korge)
        }
        solidRect(100, 100, color = RED) {
            alignBottomToBottomOf(this@Korge)
            alignRightToRightOf(this@Korge)
        }
    }

}
🤔 2
r

Rachid

07/04/2020, 4:19 PM
Can't you just add all the
solidRect
on the same container?
Or define the green box after the red boxes?
t

tobsef

07/04/2020, 8:41 PM
1. This is indeed the workaround I did to solve it. But breaking apart my UI-container isn't a nice solution. 2. Putting the green tile in front of the red ones, is not an option. In my case the green tile is a map and the red boxes are permanent UI elements, which should stay on top.