-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a MaximumRowsOrColumns to Uniformgridlayout (#1068)
* 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
Showing
17 changed files
with
298 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.