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

Introducing intrinsics #2172

Merged
merged 9 commits into from
Jun 3, 2022
Merged

Introducing intrinsics #2172

merged 9 commits into from
Jun 3, 2022

Conversation

sjoshid
Copy link
Contributor

@sjoshid sjoshid commented Apr 24, 2022

This PR adds compute_max_intrinsic function to Widget trait. Along with the usual layout params, this method also takes an Axis param that controls which intrinsic is expected.

Axis::Horizontal = Max width intrinsic is expected.
Axis::Vertical = Max height intrinsic is expected.

Each widget gets to decide what its intrinsic max width/height is.

For some non-container widgets like Label it is the width the label would take without any line breaks.

For container widget like AspectRatioBox it depends on its width/height irrespective of child's intrinsic width/height. Child's intrinsic is calculated only if AspectRatioBox width/height is infinite.

There are some todos Im planning to fix before I mark this ready for review. But I wanted to get other main points across with this draft PR.
Addressed all todos.

Copy link
Collaborator

@Zarenor Zarenor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a review of this PR; once we've talked through these suggestions, I'll be happy to review again and approve for merging. I'm excited to have this functionality.
I do wonder - is 'max' redundant in the function names? As we've defined it, the intrinsic width is width a widget wishes to be if it has no width constraint - max or min, given the height constraint it has, and vice-versa for height... I'm not sure it's a maximum or a minimum?

druid/src/box_constraints.rs Outdated Show resolved Hide resolved
druid/src/widget/container.rs Outdated Show resolved Hide resolved
druid/src/widget/flex.rs Outdated Show resolved Hide resolved
druid/src/widget/flex.rs Outdated Show resolved Hide resolved
druid/src/widget/intrinsic_width.rs Outdated Show resolved Hide resolved
@sjoshid
Copy link
Contributor Author

sjoshid commented May 20, 2022

@Zarenor I agree with your naming suggestions. Actually, anything than what I have makes sense. Im horrible at naming.
I'll clean it up today.

@sjoshid
Copy link
Contributor Author

sjoshid commented May 22, 2022

I forgot to address this point

I do wonder - is 'max' redundant in the function names? As we've defined it, the intrinsic width is width a widget wishes to be if it has no width constraint - max or min, given the height constraint it has, and vice-versa for height... I'm not sure it's a maximum or a minimum?

max is used just so we can, down the road, introduce a min. Also, Flutter (inspiration behind this PR) has both.

@sjoshid sjoshid marked this pull request as ready for review May 22, 2022 20:40
druid/src/widget/widget.rs Outdated Show resolved Hide resolved
druid/src/widget/flex.rs Outdated Show resolved Hide resolved
druid/src/box_constraints.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jneem jneem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I only have nitpicking things left. I think @Zarenor was also taking a look so I'm not marking as "Approved" just yet, but it looks fine to me.

druid/src/widget/widget.rs Outdated Show resolved Hide resolved
druid/src/widget/widget.rs Show resolved Hide resolved
druid/src/widget/flex.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@Zarenor Zarenor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Excited to have this feature implemented.

Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick review for some polish. I didn't really do deep analysis of the algorithms though.

Most of my comments are about use import ordering. Sorry about that. I would love to have this automated in the future. There has been a rustfmt proposal for this since 2018 but nobody has invested the time to get it fully done yet. There does seem to be some progress in that rustfmt now has a group_imports option, but it's still unstable. I'll see if we can have a better solution to this, or at least some sort of style guide document. But yeah, for now just remember that the general grouping/ordering of imports should be:

use std::foo;

use some_extrnal_crate::foo;

use crate::my_foo;

druid/src/box_constraints.rs Outdated Show resolved Hide resolved
druid/src/widget/padding.rs Outdated Show resolved Hide resolved
druid/src/widget/widget.rs Outdated Show resolved Hide resolved
druid/src/widget/intrinsic_width.rs Outdated Show resolved Hide resolved
druid/src/widget/flex.rs Outdated Show resolved Hide resolved
druid/src/widget/widget.rs Outdated Show resolved Hide resolved
@xStrom
Copy link
Member

xStrom commented Jun 2, 2022

Please also add a changelog entry.

CHANGELOG.md Outdated Show resolved Hide resolved
@xStrom
Copy link
Member

xStrom commented Jun 3, 2022

I'll also add for the record, that for me personally compute_max_intrinsic seems a bit verbose of a name, specifically the compute part. For example, we don't have compute_layout - we just have layout. However I recongize that this is based on the Flutter method computeMaxIntrinsicWidth and historically we've had the rule of thumb that when in doubt, do what Flutter does.

So I don't think this is a blocker to get this merged. We can bikeshed over the name later, perhaps as part of the Xilem API rework.

Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your continued effort to get this in!

@xStrom xStrom merged commit 0656497 into linebender:master Jun 3, 2022
@sjoshid
Copy link
Contributor Author

sjoshid commented Jun 4, 2022

Any time. Thank you, @Zarenor and @jneem for spending time and giving valuable feedback. :)

@sjoshid sjoshid deleted the Intrinsic_widget branch June 4, 2022 13:18
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
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.

4 participants