Cherrio LLC
03/18/2023, 6:04 AMNick
03/18/2023, 10:09 AMLayout
installed and that Layout
indicates it needs updating from that child’s size change. The parent’s layout
is then free to recalculate the parent’s size. Otherwise, the parent won’t automatically update its size on such a change.Cherrio LLC
03/18/2023, 11:22 AMdisplay
-> container(Size: display size)
-> container(Size: max with of buttons, sum of 3button's height
-> 3 buttons
if i change one of the button's height or width (making it bigger than parent) parent doesn't recalculate because the parent's layout is:
view.bounds = Rectangle(0.0, y, view.width, view.height)
instead of:
view.bounds = Rectangle(0.0,y, postionable.width, postionable.height)
1. Is this intended?
2. We have to manually recalculate size in this scenario right?Nick
03/19/2023, 1:45 AMsimpleLayout { container ->
var y = …
container.children.forEach { child ->
child.bounds = Rectangle(0.0, y, child.width, child.height)
y += …
}
}
If so, how do you enforce that the container is sized based on the buttons?
Are you also setting the container size in that same layout? That is how you could force the container to resize as the buttons do. The thing is that Layouts don’t get a direct reference to a View. So they can’t change the container’s bounds unless you keep a reference to the actual container around for the layout to use.
This is by design since Layouts work for the Display as well as Containers; and they don’t have a common interface.
So you could do this as follows:
val containerWithButtons: Container
…
containerWithButtons.layout = simpleLayout { container ->
var y = …
var maxWidth = 0.0
container.children.forEach { child ->
child.bounds = Rectangle(0.0, y, child.width, child.height)
y += …
maxWidth = …
}
containerWithButtons.size = Size(maxWidth, y) // or container.children.last().bounds.bottom, if y isn’t equal to the last child’s bottom
}
Cherrio LLC
03/19/2023, 10:23 AMCherrio LLC
03/19/2023, 10:26 AMNick
03/19/2023, 1:45 PM