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

Layout sizes not updating after changes #3

Open
chrispytoes opened this issue Mar 30, 2023 · 3 comments
Open

Layout sizes not updating after changes #3

chrispytoes opened this issue Mar 30, 2023 · 3 comments

Comments

@chrispytoes
Copy link

I think this is a bug. When I try using node.setWidthPercent and recalculating the layout, it doesn't actually calculate the new layout position. It seems to only calculate on the first calculateLayout call, then all subsequent calls do nothing.

The following test fails on the last assertion after changing the width for a second time.

class YogaTest {
    @Test
    fun testNodeUpdate() {
        val root = YogaNodeFactory.create()
        val child = YogaNodeFactory.create()

        root.setWidth(100f)
        child.setWidthPercent(50f)

        root.addChildAt(child, 0)

        root.calculateLayout(100f, 100f)

        assertEquals(50f, child.layoutWidth)

        child.setWidthPercent(25f)

        root.calculateLayout(100f, 100f)

        assertEquals(25f, child.layoutWidth) // Test fails here, value is still 50 when it should be 25.
    }
}
@chrispytoes
Copy link
Author

Okay, from some more research I'm deducing this might be the way it's supposed to work? Do I actually have to remove a node from the tree, remove its children, reset it, then add it back, and add its children back, just to do an update?

@chrispytoes
Copy link
Author

chrispytoes commented Mar 30, 2023

Okay, now I'm really confused. Removing and resetting the node doesn't seem to make it update either.

class YogaTest {
    @Test
    fun testNodeUpdate() {
        val root = YogaNodeFactory.create()
        val child = YogaNodeFactory.create()

        root.setWidth(100f)
        child.setWidthPercent(50f)

        root.addChildAt(child, 0)

        root.calculateLayout(100f, 100f)

        assertEquals(50f, child.layoutWidth)

        root.removeChildAt(0)

        child.reset()

        child.setWidthPercent(25f)

        root.addChildAt(child, 0)

        root.calculateLayout(100f, 100f)

        assertEquals(25f, child.layoutWidth) // Still fails here with 50
    }
}

@chrispytoes
Copy link
Author

@NickAcPT Sorry to bother you about this again. I'm sure you probably don't care much about this project much anymore but it's currently the only version of Yoga I can find that works on Java desktop. You are a lifesaver for making this. Do you know if I'm doing something wrong here, or is this just not working?

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

No branches or pull requests

1 participant