-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
feat(layout)!: Change Flex::default()
#881
Conversation
Flex::default()
to Flex::Stretch
Flex::default()
to Flex::Stretch
Flex::default()
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #881 +/- ##
=======================================
- Coverage 92.2% 92.1% -0.1%
=======================================
Files 61 60 -1
Lines 15977 15819 -158
=======================================
- Hits 14731 14573 -158
Misses 1246 1246 ☔ View full report in Codecov by Sentry. |
I ran every I imagine there will be some users that depend on I also updated This was the only related diff to get my code to compile: ccs.push(match *constraint {
Constraint::Length(v) => ...,
Constraint::Percentage(v) => ...,
Constraint::Ratio(n, d) => ...,
Constraint::Min(v) => ...,
Constraint::Max(v) => ...,
+ Constraint::Fill(v) => ...,
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, had a small comment but I'm find merging as is.
We might want (in a later PR) to rework some doc examples to not use Legacy
.
For the merger: don't forget to rework the commit description. Btw great description @kdheepak
This PR makes a number of simplifications to the layout and constraint features that were added after v0.25.0.
For users upgrading from v0.25.0, the net effect of this PR (along with the other PRs) is the following:
Flex
modes have been added.Flex::Start
(new default)Flex::Center
Flex::End
Flex::SpaceAround
Flex::SpaceBetween
Flex::Legacy
(old default)Min(v)
grows to allocate excess space in allFlex
modes instead of shrinking (except inFlex::Legacy
where it retains old behavior).Fill(1)
grows to allocate excess space, growing equally withMin(v)
.The following contains a summary of the changes in this PR and the motivation behind them.
Flex
Flex::Stretch
Flex::StretchLast
toFlex::Legacy
Constraint
Fixed
Min(v)
grow as much as possible everywhere (exceptFlex::Legacy
where it retains the old behavior)Min(v)
grow equally asFill(1)
while respectingMin
lower bounds. WhenFill
andMin
are used together, they both fill excess space equally.Allowing
Min(v)
to grow still allows users to build the same layouts as before withFlex::Start
with no breaking changes to the behavior.This PR also removes the unstable feature
SegmentSize
.This is a breaking change to the behavior of constraints. If users want old behavior, they can use
Flex::Legacy
.Users that have constraint that exceed the available space will probably not see any difference or see an improvement in their layouts. Any layout with
Min
will be identical inFlex::Start
andFlex::Legacy
so any layout withMin
will not be breaking.Previously,
Table
usedEvenDistribution
internally by default, but with that gone the default is nowFlex::Start
. This changes the behavior ofTable
(for the better in most cases). The only way for users to get exactly the same as the old behavior is to change their constraints. I imagine most users will be happier out of the box with the new Table default.Resolves #843
Thanks to @joshka for the direction
Background
This is a follow up to the following PRs:
Fixed
andFill
: feat: AddConstraint::Fixed(x)
andConstraint::Proportional(x)
#783 feat(constraints): RenameConstraint::Proportional
toConstraint::Fill
#880Flex
: feat: Add flex to layout ✨ #804Refactor
: feat: Change priority of constraints and addsplit_with_spacers
✨ #788Flex::Stretch
was introduced as a stable alternative toFlex::StretchLast
, as well as a backward compatible way to makeSegmentSize::EvenDistribution
work.Constraint::Fixed
was introduced to fix column spacing.Motivation
Typically, there's two ways a layout's constraints are not met:
e.g. there's a 100px wide space but a user is only requesting for a total of 75:
e.g. there's a 50px wide space but a user is requesting for a total of 75:
In
Stretch
flex modes, constraints were usually violated in both cases.This caused instability, and needed constraints like
Fixed
to ensure that some lengths were prioritized over others (e.g. we typically want table column spacing should take precedence over column constraints provided by users).In
Flex::Start
,Flex::Center
,Flex::End
,Flex::SpaceBetween
,Flex::SpaceAround
, when there's excess space constraints are not violated:flex-too-much-space.mov
When there's no enough space constraints are still violated:
But the priority order of constraints allows users to control the layout as they see fit.
TLDR:
Flex::Stretch
broke more constraints more often than other layouts and withMin
growing, it has marginal utility over otherFlex
modes, and we can remove it.Another change in this PR is the behavior of
Min
. NowMin
grows in allFlex
layouts (exceptFlex::Legacy
).This allows
Flex::Stretch
like behavior withMin(0)
instead. e.g. the following two behave identically for any available space:Previously,
Min(v)
would always try to collapse to the valuev
in everyFlex
mode, but because ofStretch
semantics it would grow to fill remaining space. This behavior made people useMin(0)
as a space filler. e.g.This PR makes this "space filler" growing behavior the default in all
Flex
layouts (exceptFlex::Legacy
for backwards compatibility reasons), i.e.Min(v)
does not collapse to the valuev
but instead tries to grow to the area size with low priority.Current
main
branch:This PR:
Flex::Legacy
vsFlex::Start
Min(v)
has another behavior which is that is limits the lower bound on the segment size with the user provided value. Previously, breaking aMin(v)
constraint was more "costly" thanLength
,Percentage
,Ratio
etc, so people also used it like this:This PR retains that behavior too:
The mechanics by which this behavior is achieved is by ordering the weights for the constraints appropriately.
TLDR: This effectively means that in any layout with
Min
, there shouldn't be any breaking change that a user experiences betweenFlex::Legacy
(old default) andFlex::Start
(new default).Additionally, in this PR,
Min
growing is weighted equally toFill
growing, which means you can get desirable behavior like this:min-grow-fill-spacing.mov
Since we are removing
Flex::Stretch
, we are also removingSegmentSize::EvenDistribution
. SinceSegmentSize
is unstable, this PR removesSegmentSize
entirely.This PR also removes
Fixed
sinceFixed
was only necessary to have something higher priority inStretch
layouts. WithoutStretch
we don't need it anymore.With the refactor in #788 spacers are used instead of
Fixed
for column spacing, and these spacers have a high priority. This makesFixed
unnecessary.