Skip to content

Commit

Permalink
Add a MaximumRowsOrColumns to Uniformgridlayout (#1068)
Browse files Browse the repository at this point in the history
* Fix to avoid C# compiler error without needing to upgrade the project.

* Add a MaximumRowsOrColumns property to UniformGridLayout

* Fix to avoid C# compiler error without needing to upgrade the project.

* Add a MaximumRowsOrColumns property to UniformGridLayout

* Fix nit

* Fix bugs and include test(s)
  • Loading branch information
micahl authored and ranjeshj committed Sep 13, 2019
1 parent 7df2ec0 commit 6bd03c9
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 71 deletions.
31 changes: 31 additions & 0 deletions dev/Generated/UniformGridLayout.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CppWinRTActivatableClassWithDPFactory(UniformGridLayout)

GlobalDependencyProperty UniformGridLayoutProperties::s_ItemsJustificationProperty{ nullptr };
GlobalDependencyProperty UniformGridLayoutProperties::s_ItemsStretchProperty{ nullptr };
GlobalDependencyProperty UniformGridLayoutProperties::s_MaximumRowsOrColumnsProperty{ nullptr };
GlobalDependencyProperty UniformGridLayoutProperties::s_MinColumnSpacingProperty{ nullptr };
GlobalDependencyProperty UniformGridLayoutProperties::s_MinItemHeightProperty{ nullptr };
GlobalDependencyProperty UniformGridLayoutProperties::s_MinItemWidthProperty{ nullptr };
Expand Down Expand Up @@ -45,6 +46,17 @@ void UniformGridLayoutProperties::EnsureProperties()
ValueHelper<winrt::UniformGridLayoutItemsStretch>::BoxValueIfNecessary(winrt::UniformGridLayoutItemsStretch::None),
winrt::PropertyChangedCallback(&OnItemsStretchPropertyChanged));
}
if (!s_MaximumRowsOrColumnsProperty)
{
s_MaximumRowsOrColumnsProperty =
InitializeDependencyProperty(
L"MaximumRowsOrColumns",
winrt::name_of<int>(),
winrt::name_of<winrt::UniformGridLayout>(),
false /* isAttached */,
ValueHelper<int>::BoxValueIfNecessary(-1),
winrt::PropertyChangedCallback(&OnMaximumRowsOrColumnsPropertyChanged));
}
if (!s_MinColumnSpacingProperty)
{
s_MinColumnSpacingProperty =
Expand Down Expand Up @@ -106,6 +118,7 @@ void UniformGridLayoutProperties::ClearProperties()
{
s_ItemsJustificationProperty = nullptr;
s_ItemsStretchProperty = nullptr;
s_MaximumRowsOrColumnsProperty = nullptr;
s_MinColumnSpacingProperty = nullptr;
s_MinItemHeightProperty = nullptr;
s_MinItemWidthProperty = nullptr;
Expand All @@ -129,6 +142,14 @@ void UniformGridLayoutProperties::OnItemsStretchPropertyChanged(
winrt::get_self<UniformGridLayout>(owner)->OnPropertyChanged(args);
}

void UniformGridLayoutProperties::OnMaximumRowsOrColumnsPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
{
auto owner = sender.as<winrt::UniformGridLayout>();
winrt::get_self<UniformGridLayout>(owner)->OnPropertyChanged(args);
}

void UniformGridLayoutProperties::OnMinColumnSpacingPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
Expand Down Expand Up @@ -189,6 +210,16 @@ winrt::UniformGridLayoutItemsStretch UniformGridLayoutProperties::ItemsStretch()
return ValueHelper<winrt::UniformGridLayoutItemsStretch>::CastOrUnbox(static_cast<UniformGridLayout*>(this)->GetValue(s_ItemsStretchProperty));
}

void UniformGridLayoutProperties::MaximumRowsOrColumns(int value)
{
static_cast<UniformGridLayout*>(this)->SetValue(s_MaximumRowsOrColumnsProperty, ValueHelper<int>::BoxValueIfNecessary(value));
}

int UniformGridLayoutProperties::MaximumRowsOrColumns()
{
return ValueHelper<int>::CastOrUnbox(static_cast<UniformGridLayout*>(this)->GetValue(s_MaximumRowsOrColumnsProperty));
}

void UniformGridLayoutProperties::MinColumnSpacing(double value)
{
static_cast<UniformGridLayout*>(this)->SetValue(s_MinColumnSpacingProperty, ValueHelper<double>::BoxValueIfNecessary(value));
Expand Down
9 changes: 9 additions & 0 deletions dev/Generated/UniformGridLayout.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class UniformGridLayoutProperties
void ItemsStretch(winrt::UniformGridLayoutItemsStretch const& value);
winrt::UniformGridLayoutItemsStretch ItemsStretch();

void MaximumRowsOrColumns(int value);
int MaximumRowsOrColumns();

void MinColumnSpacing(double value);
double MinColumnSpacing();

Expand All @@ -32,6 +35,7 @@ class UniformGridLayoutProperties

static winrt::DependencyProperty ItemsJustificationProperty() { return s_ItemsJustificationProperty; }
static winrt::DependencyProperty ItemsStretchProperty() { return s_ItemsStretchProperty; }
static winrt::DependencyProperty MaximumRowsOrColumnsProperty() { return s_MaximumRowsOrColumnsProperty; }
static winrt::DependencyProperty MinColumnSpacingProperty() { return s_MinColumnSpacingProperty; }
static winrt::DependencyProperty MinItemHeightProperty() { return s_MinItemHeightProperty; }
static winrt::DependencyProperty MinItemWidthProperty() { return s_MinItemWidthProperty; }
Expand All @@ -40,6 +44,7 @@ class UniformGridLayoutProperties

static GlobalDependencyProperty s_ItemsJustificationProperty;
static GlobalDependencyProperty s_ItemsStretchProperty;
static GlobalDependencyProperty s_MaximumRowsOrColumnsProperty;
static GlobalDependencyProperty s_MinColumnSpacingProperty;
static GlobalDependencyProperty s_MinItemHeightProperty;
static GlobalDependencyProperty s_MinItemWidthProperty;
Expand All @@ -57,6 +62,10 @@ class UniformGridLayoutProperties
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnMaximumRowsOrColumnsPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnMinColumnSpacingPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);
Expand Down
66 changes: 46 additions & 20 deletions dev/Repeater/APITests/Common/OrientationBasedMeasures.cs
Original file line number Diff line number Diff line change
@@ -1,118 +1,144 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.Graphics.Canvas.Effects;
using MUXControlsTestApp.Utilities;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using DisplayInformation = Windows.Graphics.Display.DisplayInformation;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests.RepeaterTests.Common
{
public class OrientationBasedMeasures
{
public ScrollOrientation ScrollOrientation { get; set; }
private double m_rawPixelsPerViewPixel = 1.0;
private bool m_useLayoutRounding;

public bool IsVerical
{
get { return ScrollOrientation == ScrollOrientation.Vertical; }
}

public OrientationBasedMeasures(ScrollOrientation o)
public OrientationBasedMeasures(ScrollOrientation o, bool useLayoutRounding = true)
{
ScrollOrientation = o;
m_useLayoutRounding = useLayoutRounding;

bool? hasThreadAccess = Window.Current?.Dispatcher?.HasThreadAccess;
if (useLayoutRounding && hasThreadAccess.HasValue && hasThreadAccess.Value)
m_rawPixelsPerViewPixel = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
}

public double Major(Size size)
{
return IsVerical ? size.Height : size.Width;
return RoundForLayout(IsVerical ? size.Height : size.Width);
}

public double Minor(Size size)
{
return IsVerical ? size.Width : size.Height;
return RoundForLayout(IsVerical ? size.Width : size.Height);
}

public double MajorSize(Rect rect)
{
return IsVerical ? rect.Height : rect.Width;
return RoundForLayout(IsVerical ? rect.Height : rect.Width);
}

public double MinorSize(Rect rect)
{
return IsVerical ? rect.Width : rect.Height;
return RoundForLayout(IsVerical ? rect.Width : rect.Height);
}

public double MajorStart(Rect rect)
{
return IsVerical ? rect.Top : rect.Left;
return RoundForLayout(IsVerical ? rect.Top : rect.Left);
}

public double MajorEnd(Rect rect)
{
return IsVerical ? rect.Bottom : rect.Right;
return RoundForLayout(IsVerical ? rect.Bottom : rect.Right);
}

public double MinorStart(Rect rect)
{
return IsVerical ? rect.Left : rect.Top;
return RoundForLayout(IsVerical ? rect.Left : rect.Top);
}

public void SetMajorSize(ref Rect rect, double value)
{
if (IsVerical)
{
rect.Height = value;
rect.Height = RoundForLayout(value);
}
else
{
rect.Width = value;
rect.Width = RoundForLayout(value);
}
}

public void SetMajorStart(ref Rect rect, double value)
{
if (IsVerical)
{
rect.Y = value;
rect.Y = RoundForLayout(value);
}
else
{
rect.X = value;
rect.X = RoundForLayout(value);
}
}

public void SetMinorStart(ref Rect rect, double value)
{
if (IsVerical)
{
rect.X = value;
rect.X = RoundForLayout(value);
}
else
{
rect.Y = value;
rect.Y = RoundForLayout(value);
}
}

public Rect MinorMajorRect(double minor, double major, double minorSize, double majorSize)
{
var min = RoundForLayout(minor);
var maj = RoundForLayout(major);
var minSize = RoundForLayout(minorSize);
var majSize = RoundForLayout(majorSize);
return
IsVerical ?
new Rect(minor, major, minorSize, majorSize) :
new Rect(major, minor, majorSize, minorSize);
new Rect(min, maj, minSize, majSize) :
new Rect(maj, min, majSize, minSize);
}

public Point MinorMajorPoint(double minor, double major)
{
var min = RoundForLayout(minor);
var maj = RoundForLayout(major);
return
IsVerical ?
new Point(minor, major) :
new Point(major, minor);
new Point(min, maj) :
new Point(maj, min);
}

public Size MinorMajorSize(double minor, double major)
{
var min = RoundForLayout(minor);
var maj = RoundForLayout(major);
return
IsVerical ?
new Size(minor, major) :
new Size(major, minor);
new Size(min, maj) :
new Size(maj, min);
}

private double RoundForLayout(double value)
{
if (m_useLayoutRounding)
return global::System.Math.Floor((m_rawPixelsPerViewPixel * value) + 0.5) / m_rawPixelsPerViewPixel;
else
return value;
}
}
}
Loading

0 comments on commit 6bd03c9

Please sign in to comment.