Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result when using uiVerticalStack and uiHorizontalStack #1735

Closed
Kietyo opened this issue Jun 30, 2023 · 2 comments · Fixed by #1739
Closed

Unexpected result when using uiVerticalStack and uiHorizontalStack #1735

Kietyo opened this issue Jun 30, 2023 · 2 comments · Fixed by #1739

Comments

@Kietyo
Copy link
Contributor

Kietyo commented Jun 30, 2023

class MyScene : Scene() {
    @OptIn(ExperimentalTime::class)
    override suspend fun SContainer.sceneMain() {
        val sceneWidth = width
        val sceneHeight = height

        uiVerticalStack(sceneWidth, adjustSize = false) {
            uiHorizontalStack(adjustHeight = false) {
                solidRect(100, 100, Colors.BLUE)
                solidRect(100, 100, Colors.RED)
                solidRect(100, 100, Colors.GREEN)
                solidRect(100, 100, Colors.YELLOW)
            }
            uiHorizontalStack(adjustHeight = false) {
                solidRect(100, 100, Colors.YELLOW)
                solidRect(100, 100, Colors.GREEN)
                solidRect(100, 100, Colors.RED)
                solidRect(100, 100, Colors.BLUE)
            }
        }
    }
}
image

For some reason the top row is shorter

@soywiz
Copy link
Member

soywiz commented Jun 30, 2023

You can either:

val sceneWidth = width
val sceneHeight = height

uiVerticalStack(sceneWidth, adjustSize = false) {
    uiHorizontalStack(100f, adjustHeight = false) {
        solidRect(100, 100, Colors.BLUE)
        solidRect(100, 100, Colors.RED)
        solidRect(100, 100, Colors.GREEN)
        solidRect(100, 100, Colors.YELLOW)
    }
    uiHorizontalStack(100f, adjustHeight = false) {
        solidRect(100, 100, Colors.YELLOW)
        solidRect(100, 100, Colors.GREEN)
        solidRect(100, 100, Colors.RED)
        solidRect(100, 100, Colors.BLUE)
    }
}

or:

val sceneWidth = width
val sceneHeight = height

uiVerticalStack(sceneWidth, adjustSize = false) {
    uiHorizontalStack(adjustHeight = true) {
        solidRect(100, 100, Colors.BLUE)
        solidRect(100, 100, Colors.RED)
        solidRect(100, 100, Colors.GREEN)
        solidRect(100, 100, Colors.YELLOW)
    }
    uiHorizontalStack(adjustHeight = true) {
        solidRect(100, 100, Colors.YELLOW)
        solidRect(100, 100, Colors.GREEN)
        solidRect(100, 100, Colors.RED)
        solidRect(100, 100, Colors.BLUE)
    }
}

depending on the effect you want to achieve.

The problem was not that the image was smaller, but that the size of the boxes was kept, but the height used for the rows was 32, so the second row was overlapping it. You can check that by pressing F7 and going to those nodes.

@soywiz
Copy link
Member

soywiz commented Jun 30, 2023

Maybe we could make the first argument (the size) nullable, and when the size is not provided, try to get the maxiumum size from their children

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
2 participants