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

Support width/height: 'auto' #27

Open
felixmariotto opened this issue Jun 6, 2020 · 4 comments
Open

Support width/height: 'auto' #27

felixmariotto opened this issue Jun 6, 2020 · 4 comments
Labels
roadmap Feature planned, must be addressed

Comments

@felixmariotto
Copy link
Owner

Currently, either a Block has a width, either its width can be computed from its children width (same for height).

It would be a great addition to support width/height: 'auto', so that a component takes all the width (or height) it can in its parent component.

It should be done by BoxComponent.

@felixmariotto felixmariotto added the roadmap Feature planned, must be addressed label Jun 6, 2020
@enijar
Copy link
Contributor

enijar commented Dec 21, 2021

I've been investigating how to implement this feature. In my experiments, I game across this library, which uses this library to do most of the layout work.

I don't think adding that as a dependency would be the best route though as its lots of bloat. My thoughts are to do the following:

Store all geometry bounding boxes (in an in-memory cache) in a tree structure, e.g.

       A
    __||__
    ||  ||
    B    C
 __||__
 ||  ||
 D    E

And calculate the children's width/height based on this tree structure each frame.

What do you think about this approach? I don't think it will involve a large amount of changes to the existing code to implement.

@felixmariotto
Copy link
Owner Author

felixmariotto commented Dec 21, 2021

Hi @enijar, thanks for investigating this issue.
I'm not sure I understand well your proposal.

In three-mesh-ui that's the parents that compute the children position because the children dimension is supposed to be known in advance. It's happening here. With the proposed new feature, I suppose the parent would have to decide of the children (with auto) dimension at the same time, and store these dimension values so that when the layout update cascades the children can resize themselves.

You may have noticed that when a layoutUpdate is triggered it is fired from the highest UI component of a component tree and cascade through the children. So when .getWidth and .getHeight are called here you could assume that if the component has a parent, the parent was able to pre-compute the children dimension.

Is it something similar that you have in mind ?

@enijar
Copy link
Contributor

enijar commented Dec 22, 2021

@felixmariotto let me pull together a WIP demo of what I'm proposing, and I can share it on a CSB link before making a PR.

@felixmariotto
Copy link
Owner Author

Or you can just file a PR as draft no worries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
roadmap Feature planned, must be addressed
Projects
None yet
Development

No branches or pull requests

2 participants