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

Make calculate(Horizontal/Vertical)ContentSize in Component #276

Draft
wants to merge 4 commits into
base: 1.21
Choose a base branch
from

Conversation

kikugie
Copy link
Contributor

@kikugie kikugie commented Jul 28, 2024

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.

…ibility

Mark them as deprecated with an addition of `calculate(Horizontal/Vertical)ContentSize` in `Component`
@kikugie kikugie changed the title Make determine(Horizontal/Vertical)ContentSize public in Component Make calculate(Horizontal/Vertical)ContentSize in Component Jul 28, 2024
…gate to `determine(Horizontal/Vertical)ContentSize` implementations by default.
@kikugie
Copy link
Contributor Author

kikugie commented Jul 28, 2024

Update

Putting determine(Horizontal/Vertical)ContentSize in Component creates a compiler error for all inheritors requiring it to be public.
I've made calculate(Horizontal/Vertical)ContentSize in Component for this purpose.
BaseComponent overrides those to return the result of the overriden determine(Horizontal/Vertical)ContentSize without breaking compatibility.
(This is some OOP shenanigans, if I may say so)

@kikugie kikugie marked this pull request as draft July 28, 2024 21:14
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

Successfully merging this pull request may close these issues.

1 participant