-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Layout consistency #2192
Merged
Merged
Layout consistency #2192
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hecrj
force-pushed
the
fix/layout-inconsistencies
branch
from
January 10, 2024 09:02
bf66d80
to
a6cbc36
Compare
quintenpalmer
added a commit
to quintenpalmer/protomusiq
that referenced
this pull request
Feb 15, 2024
This fixes an issue where Fill-width elements in the column would disappear, maybe because of these issues: iced-rs/iced#715 iced-rs/iced#2186 iced-rs/iced#2192
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the intuitiveness of our layout engine by solving a bunch of inconsistencies related to our sizing strategies.
Shrunken fills
Until now, it was considered an invalid layout to have a container with
Length::Shrink
containing some widget withLength::Fill
in a specific dimension. Specifically, this use case would cause theFill
item to steal all the available space independently of the position of the parent in the widget tree (see #2186). In practice, this could cause widgets to fully disappear unexpectedly in completely unrelated places of the application unlessFill
was explicitly set everywhere.The changes here modify our
flex
layout logic so thatShrink
actually takes priority overFill
. As a result, a container with aShrink
strategy containing some widget with aFill
strategy will simply collapse its contents. Effectively, this makes invalid layouts local and avoids them from leaking through multiple levels of the widget tree.Furthermore, a
Shrink
parent with aFill
children in its cross axis will only collapse if the parent does not have anyShrink
children. If some children areShrink
, then theFill
children will fill as much space as the widest child. This behavior can be leveraged to satisfy a bunch of use cases that previously were impossible to model without using custom widgets.For instance, this layout
can now be achieved with
row
andvertical_rule
:While a
vertical_rule
uses aFill
strategy for itsheight
and the parentrow
is set toShrink
, the layout works as expected because thetext
has aShrink
height.Adaptive containers
But wait! What happens with containers that by default
Shrink
but only haveFill
children? Do we have to manually setFill
everywhere now for its contents to not disappear? No! Containers now adapt their sizing strategy based on their children.The
width
andheight
methods of theWidget
trait are now consolidated into a singlesize
method that returns aSize<Length>
. A newsize_hint
method also exists, which by default returnssize
, and it is leveraged by containers to guess the proper sizing strategy during construction.In practice, this means that if we want a container to
Shrink
when some of its children areFill
, we need to opt in on this behavior explicitly. It also means that we do not need to explicitly setFill
everywhere in order for layouts to work as expected.A
layout
exampleI have also created a new example:
layout
, which is meant to showcase a bunch of common, useful layouts that can be easily achieved with the built-in widgets:Other (useful) minor changes
fill
field inlayout::Limits
has been removed, simplifying its meaning considerably.column
androw
functions now take anIntoIterator
instead of aVec
.layout
module now has a bunch of new helpers with common layout strategies; useful for custom widgets.container::Appearance
can be directly used as thestyle
of aContainer
.Fixes #2186.