Skip to content

Commit

Permalink
test(grid): Added a new sample that is dynamically updating Grid posi…
Browse files Browse the repository at this point in the history
…tioning of an element.
  • Loading branch information
carldebilly committed Apr 26, 2021
1 parent 96b8086 commit 18aa879
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridTestsControl\Grid_DynamicRowColumn.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridTestsControl\Grid_Margin_And_Padding.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -4869,6 +4873,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Flyout\Flyout_Unloaded.xaml.cs">
<DependentUpon>Flyout_Unloaded.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridTestsControl\Grid_DynamicRowColumn.xaml.cs">
<DependentUpon>Grid_DynamicRowColumn.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridTestsControl\Grid_Margin_And_Padding.xaml.cs">
<DependentUpon>Grid_Margin_And_Padding.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -7273,11 +7280,7 @@
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ChatBox\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\DatePicker\Models\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\NewFolder\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\PasswordBoxTests\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\PersonPictureTests\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Repeater\WinUI\Images\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Repeater\WinUI\Samples\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TimePicker\Model\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\Background\" />
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\BackButtonTitle\" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.GridTestsControl.Grid_DynamicRowColumn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel Spacing="4">
<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Column Widths</TextBlock>
<Slider Minimum="0" Maximum="100" Value="20" x:Name="width" Width="200" />
<TextBlock Text="{Binding Value, ElementName=width}" x:Name="widths" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Column Heights</TextBlock>
<Slider Minimum="0" Maximum="100" Value="20" x:Name="height" Width="200" />
<TextBlock Text="{Binding Value, ElementName=height}" x:Name="heights" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Column</TextBlock>
<Slider Minimum="0" Maximum="4" Value="2" x:Name="col" Width="200" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Row</TextBlock>
<Slider Minimum="0" Maximum="4" Value="2" x:Name="row" Width="200" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Column Span</TextBlock>
<Slider Minimum="1" Maximum="4" Value="2" x:Name="colspan" Width="200" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Width="120">Row Span</TextBlock>
<Slider Minimum="1" Maximum="4" Value="2" x:Name="rowspan" Width="200" />
</StackPanel>

<Grid Margin="20" RowSpacing="5" ColumnSpacing="5" Background="Blue" HorizontalAlignment="Left" x:Name="sut">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding Text, ElementName=widths}" />
<ColumnDefinition Width="{Binding Text, ElementName=widths}" />
<ColumnDefinition Width="{Binding Text, ElementName=widths}" />
<ColumnDefinition Width="{Binding Text, ElementName=widths}" />
<ColumnDefinition Width="{Binding Text, ElementName=widths}" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Text, ElementName=heights}" />
<RowDefinition Height="{Binding Text, ElementName=heights}" />
<RowDefinition Height="{Binding Text, ElementName=heights}" />
<RowDefinition Height="{Binding Text, ElementName=heights}" />
<RowDefinition Height="{Binding Text, ElementName=heights}" />
</Grid.RowDefinitions>

<Rectangle Fill="Red"
Grid.Column="{Binding Value, ElementName=col}"
Grid.Row="{Binding Value, ElementName=row}"
Grid.ColumnSpan="{Binding Value, ElementName=colspan}"
Grid.RowSpan="{Binding Value, ElementName=rowspan}" />
</Grid>
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Windows.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Windows_UI_Xaml_Controls.GridTestsControl
{
[Sample]
public sealed partial class Grid_DynamicRowColumn : Page
{
public Grid_DynamicRowColumn()
{
this.InitializeComponent();
}
}
}
17 changes: 8 additions & 9 deletions src/Uno.Foundation/Collections/StackVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ internal class StackVector<T> : IEnumerable<T> where T : struct
internal delegate bool RefPredicateDelegate(ref T item);

private Memory<T> _inner;
private int _length;

public StackVector(int capacity, int initialLength = 0)
{
_inner = new Memory<T>(new T[capacity]);
_length = initialLength;
Count = initialLength;
}

public IEnumerator<T> GetEnumerator() => new StackVectorEnumerator(this);

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => _length;
public int Count { get; private set; }

public Memory<T> Memory => _inner.Slice(0, _length);
public Memory<T> Memory => _inner.Slice(0, Count);

public void Resize(int newCount)
{
Expand All @@ -41,7 +40,7 @@ public void Resize(int newCount)
IncrementResizeCount();
}

_length = newCount;
Count = newCount;
}

#if DEBUG
Expand All @@ -58,7 +57,7 @@ private void IncrementResizeCount()

public ref T PushBack()
{
var newLength = _length + 1;
var newLength = Count + 1;
Resize(newLength);
return ref _inner.Span[newLength - 1];

Expand All @@ -81,7 +80,7 @@ public bool FirstOrDefault(RefPredicateDelegate predicate, ref T item)

public bool LastOrDefault(ref T last)
{
var length = _length;
var length = Count;

if(length == 0)
{
Expand All @@ -96,7 +95,7 @@ public ref T this[int index]
{
get
{
if(index < 0 || index >= _length)
if(index < 0 || index >= Count)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
Expand All @@ -117,7 +116,7 @@ public StackVectorEnumerator(StackVector<T> owner)
bool IEnumerator.MoveNext()
{
_index++;
return _index < _owner._length;
return _index < _owner.Count;
}

void IEnumerator.Reset() => _index = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Grid/ColumnDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public double ActualWidth
//var parent = this.GetParent();
//var result = (parent as Grid)?.GetActualWidth(this) ?? 0d;
//return result;
throw new NotImplementedException("TODO - Grid");
return _measureArrangeSize;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Grid/RowDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public double ActualHeight
//var parent = this.GetParent();
//var result = (parent as Grid)?.GetActualHeight(this) ?? 0d;
//return result;
throw new NotImplementedException("TODO - Grid");
return _measureArrangeSize;
}
}

Expand Down

0 comments on commit 18aa879

Please sign in to comment.