owo-lib
owo-lib copied to clipboard
Make `calculate(Horizontal/Vertical)ContentSize` in Component
Motivation
Complex parent components may need to know how much space their children need before arranging them. Currently this can be achieved by inflating each child, seeing how much space they take with no restrictions and reinflating them with properly calculated space.
However, this invokes inflate
on children twice, which may contain expensive calculations, such as rearranging nested child components or calling overridden applySizing
, which is useful for caching rendering parameters on custom components.
Solution
This can be solved by asking how much space each child needs beforehand, without modifying them.
BaseComponent
already has such functionality with determine(Horizontal/Vertical)ContentSize
methods,
but they are marked as protected
and not available in the base Component
type.
This PR moves said methods to the Component
interface and updates overridden implementations.