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

Grid - support Min/Max-Width/Height on Column/Row-Definitions #1048

Merged
merged 7 commits into from
Jun 11, 2019

Conversation

davidjohnoliver
Copy link
Contributor

GitHub Issue (If applicable): #1032

PR Type

What kind of change does this PR introduce?

Feature

Adds support for supports ColumnDefinition.MinWidth and MaxWidth and RowDefinition.MinHeight and MaxHeight.

This is not a complete implementation, for example we don't currently attempt to match UWP in the case that the sum of MinWidths exceeds the available width.

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

Copy link
Member

@jeromelaban jeromelaban left a comment

Choose a reason for hiding this comment

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

Nice work !

public class Given_Grid_And_Min_Max
{
[TestMethod]
public void When_Max_Width_Star()
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah true

src/Uno.UI/Extensions/MathEx.cs Show resolved Hide resolved
src/Uno.UI/UI/Xaml/Controls/Grid/ColumnDefinition.cs Outdated Show resolved Hide resolved
src/Uno.UI/UI/Xaml/Controls/Grid/Grid.cs Show resolved Hide resolved
var totalStarSizedWidth = initialTotalStarSizedWidth;
var unitStarWidth = remainingWidth / totalStarSizedWidth;

var maxTries = starSizeChildren.Span.Length * 2 + 1;
Copy link
Member

Choose a reason for hiding this comment

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

What's the idea behind maxTries being star children count * 2 + 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 to always run at least once, star children count because it shouldn't iterate more times than there are star children, *2 for margin of error.

Note that in the case there are no MinWidths or MaxWidths set it will only run once and will behave as before.

/// In either case, we exclude the constrained rows and recalculate for the remaining 'true' star-sized rows. The new unitStarHeight may cause
/// more Min/MaxHeights to kick in, so we repeat until the values stabilize.
Memory<double> starCalculatedPixelRows = null;
for (int i = 0; i <= maxTries; i++)
Copy link
Member

Choose a reason for hiding this comment

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

If you understand what changes between iterations, you might be able to come up with an algorithm that doesn't need iterations. An example could be to order the columns by their MaxWidth value (ascending) and apply the constraints on that sorted list once.

@davidjohnoliver davidjohnoliver merged commit e2486be into master Jun 11, 2019
@davidjohnoliver davidjohnoliver deleted the dev/djo/grid-minmaxwidth branch June 11, 2019 16:21
@agneszitte
Copy link
Contributor

Nice work !

I updated the related internal issue ;) Thanks @davidjohnoliver, nice work!

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.

5 participants