After playing a bit with UI and more specifically with scrollable content using a Scroll Rect and Layout I felt the way it’s done it not logic.
When I add a Scroll Rect component to a Panel for instance, I want all my Panel content to be part of the scrolling - and I want that behavior even if I add content dynamically.
But there is not how it works - the scroll area is based on the height of the Scroll Rect Content property but this value is not computed dynamically and what I think it’s weird it’s that the height it’s not related to the height of the child that the Content contains.
It’s weird for me that a Panel I want scrollable has not it’s entire content scrollable if it’s content is added by code. It’s strange to have to add a Content Size Filter just in order to have it’s size computed dynamically.
For me UI is about 2D element, a 2D element size is its “bouding box” based on its children.
It’s not about criticize, it’s about giving a feedback. I came from 2D development and I’m used to have a 2D element sized being dynamic - like in Action Script and the very well thought Feather UI framework.
If you just update the bounds of the ScrollRect when children are added and removed, not every tick, that shouldn’t be too bad on performance should it?
Unfortunately that’s not enough. We can’t know that the children are not moving, and there’s no good way to know if a transform has moved without checking. And if even just one child was moving it would mean having to recalculate the bounds (based on all children in the sub-tree) every frame for as long as it was moving.
What about a method that allows to recalculate the bounds which could be called manually ? It’s won’t solve all cases but it will allow to add child dynamically (like adding buttons according to a local or remote save or whatever) and then call that method. It will be very usefull for developers, ok it won’t solves cases where the content (children) are moving, but it will allow to initialize/update the content whenever needed and then ask for update the content bounds.