-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Min/Max Width/Height support on Grid Column/Row Definitions #29582
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
base: main
Are you sure you want to change the base?
Changes from all commits
ef10b39
be65384
4ac822c
2638abb
2ef0dc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Microsoft.Maui.Controls; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.Controls.Core.UnitTests | ||
{ | ||
public class ColumnDefinitionTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make src/Controls/tests/Core.UnitTests/Layouts/GridLayoutTests.cs partial and this file shoulkd be called GridLayoutTests.ColumnDefinition.cs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created |
||
{ | ||
[Fact] | ||
public void DefaultMinWidthIsNegativeOne() | ||
{ | ||
var column = new ColumnDefinition(); | ||
Assert.Equal(-1d, column.MinWidth); | ||
} | ||
|
||
[Fact] | ||
public void DefaultMaxWidthIsNegativeOne() | ||
{ | ||
var column = new ColumnDefinition(); | ||
Assert.Equal(-1d, column.MaxWidth); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(50)] | ||
[InlineData(100)] | ||
[InlineData(double.PositiveInfinity)] | ||
public void CanSetMinWidth(double value) | ||
{ | ||
var column = new ColumnDefinition(); | ||
column.MinWidth = value; | ||
Assert.Equal(value, column.MinWidth); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(50)] | ||
[InlineData(100)] | ||
[InlineData(double.PositiveInfinity)] | ||
public void CanSetMaxWidth(double value) | ||
{ | ||
var column = new ColumnDefinition(); | ||
column.MaxWidth = value; | ||
Assert.Equal(value, column.MaxWidth); | ||
} | ||
|
||
[Fact] | ||
public void MinWidthChangeInvalidatesLayout() | ||
{ | ||
bool invalidated = false; | ||
var column = new ColumnDefinition(); | ||
column.SizeChanged += (sender, args) => invalidated = true; | ||
|
||
column.MinWidth = 100; | ||
Assert.True(invalidated); | ||
} | ||
|
||
[Fact] | ||
public void MaxWidthChangeInvalidatesLayout() | ||
{ | ||
bool invalidated = false; | ||
var column = new ColumnDefinition(); | ||
column.SizeChanged += (sender, args) => invalidated = true; | ||
|
||
column.MaxWidth = 200; | ||
Assert.True(invalidated); | ||
} | ||
|
||
[Fact] | ||
public void WidthChangeInvalidatesLayoutWithMinMaxConstraints() | ||
{ | ||
bool invalidated = false; | ||
var column = new ColumnDefinition(); | ||
column.MinWidth = 50; | ||
column.MaxWidth = 150; | ||
column.SizeChanged += (sender, args) => invalidated = true; | ||
|
||
column.Width = new GridLength(100); | ||
Assert.True(invalidated); | ||
} | ||
|
||
[Fact] | ||
public void MinMaxWidthAreBindableProperties() | ||
{ | ||
var column = new ColumnDefinition(); | ||
|
||
bool minWidthChanged = false; | ||
bool maxWidthChanged = false; | ||
|
||
column.PropertyChanged += (sender, args) => | ||
{ | ||
if (args.PropertyName == nameof(ColumnDefinition.MinWidth)) | ||
minWidthChanged = true; | ||
if (args.PropertyName == nameof(ColumnDefinition.MaxWidth)) | ||
maxWidthChanged = true; | ||
}; | ||
|
||
column.MinWidth = 100; | ||
column.MaxWidth = 200; | ||
|
||
Assert.True(minWidthChanged); | ||
Assert.True(maxWidthChanged); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-10)] // Negative values other than -1 should be coerced to -1 | ||
[InlineData(-2)] | ||
public void NegativeMinWidthIsCoerced(double value) | ||
{ | ||
var column = new ColumnDefinition(); | ||
column.MinWidth = value; | ||
Assert.Equal(-1d, column.MinWidth); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-10)] // Negative values other than -1 should be coerced to -1 | ||
[InlineData(-2)] | ||
public void NegativeMaxWidthIsCoerced(double value) | ||
{ | ||
var column = new ColumnDefinition(); | ||
column.MaxWidth = value; | ||
Assert.Equal(-1d, column.MaxWidth); | ||
} | ||
} | ||
} |
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.
Why not default to zero and PositiveInfinity?