Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added Controls library, and added Orientation enum * Added Thickness and ThicknessHelper to XPlat.UI
- Loading branch information
1 parent
e871f63
commit 0ff3e8a
Showing
5 changed files
with
360 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace XPlat.UI.Controls | ||
{ | ||
/// <summary>Defines constants that specify the different orientations that a control or layout can have.</summary> | ||
public enum Orientation | ||
{ | ||
/// <summary>The control or layout should be vertically oriented.</summary> | ||
Vertical, | ||
|
||
/// <summary>The control or layout should be horizontally oriented.</summary> | ||
Horizontal, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard1.4;xamarin.ios10;monoandroid81;uap10.0</TargetFrameworks> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<Version>1.0.0.0</Version> | ||
<Authors>James Croft</Authors> | ||
<Company>James Croft</Company> | ||
<Product>XPlat - Windows.UI.Xaml.Controls APIs</Product> | ||
<Description>Brings the functionality of the Windows.UI.Xaml.Controls APIs cross-platform with support for Windows, Android and iOS.</Description> | ||
<Copyright>Copyright (C) James Croft. All rights reserved.</Copyright> | ||
<PackageLicenseUrl>https://github.com/jamesmcroft/XPlat-Windows-APIs/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageProjectUrl>https://github.com/jamesmcroft/XPlat-Windows-APIs</PackageProjectUrl> | ||
<PackageIconUrl>https://i.imgur.com/tkagpGy.png</PackageIconUrl> | ||
<PackageTags>Xamarin UWP iOS Android Toolkit API Extensions Components Controls UI</PackageTags> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
<PackageId>XPlat.UI.Controls</PackageId> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DocumentationFile>bin\Release\netstandard1.4\XPlat.UI.Controls.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.5.4" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' "> | ||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.7" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" /> | ||
|
||
|
||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,232 @@ | ||
namespace XPlat.UI | ||
{ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
/// <summary>Describes the thickness of a frame around a rectangle. Four Double values describe the Left, Top, Right, and Bottom sides of the rectangle, respectively.</summary> | ||
public struct Thickness | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Thickness"/> struct. | ||
/// </summary> | ||
/// <param name="uniformLength"> | ||
/// A single length value to apply to all parts of the thickness in pixels. | ||
/// </param> | ||
public Thickness(double uniformLength) | ||
{ | ||
this.Left = this.Top = this.Right = this.Bottom = uniformLength; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Thickness"/> struct. | ||
/// </summary> | ||
/// <param name="left"> | ||
/// The left value. | ||
/// </param> | ||
/// <param name="top"> | ||
/// The top value. | ||
/// </param> | ||
/// <param name="right"> | ||
/// The right value. | ||
/// </param> | ||
/// <param name="bottom"> | ||
/// The bottom value. | ||
/// </param> | ||
public Thickness(double left, double top, double right, double bottom) | ||
{ | ||
this.Left = left; | ||
this.Top = top; | ||
this.Right = right; | ||
this.Bottom = bottom; | ||
} | ||
|
||
#if WINDOWS_UWP | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Thickness"/> class. | ||
/// </summary> | ||
/// <param name="thickness"> | ||
/// The thickness value. | ||
/// </param> | ||
public Thickness(Windows.UI.Xaml.Thickness thickness) | ||
{ | ||
this.Bottom = thickness.Bottom; | ||
this.Left = thickness.Left; | ||
this.Right = thickness.Right; | ||
this.Top = thickness.Top; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="Thickness"/> object based on the given <see cref="Windows.UI.Xaml.Thickness"/> value. | ||
/// </summary> | ||
/// <param name="thickness"> | ||
/// The thickness value. | ||
/// </param> | ||
public static implicit operator Thickness(Windows.UI.Xaml.Thickness thickness) | ||
{ | ||
return new Thickness(thickness); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="Windows.UI.Xaml.Thickness"/> object based on the given <see cref="Thickness"/> value. | ||
/// </summary> | ||
/// <param name="thickness"> | ||
/// The thickness value. | ||
/// </param> | ||
public static implicit operator Windows.UI.Xaml.Thickness(Thickness thickness) | ||
{ | ||
return new Windows.UI.Xaml.Thickness(thickness.Left, thickness.Top, thickness.Right, thickness.Bottom); | ||
} | ||
#endif | ||
|
||
/// <summary> | ||
/// Gets or sets the left value. | ||
/// </summary> | ||
public double Left { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the top value. | ||
/// </summary> | ||
public double Top { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the right value. | ||
/// </summary> | ||
public double Right { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the bottom value. | ||
/// </summary> | ||
public double Bottom { get; set; } | ||
|
||
/// <summary> | ||
/// Checks the equality of two thickness items. | ||
/// </summary> | ||
/// <param name="t1"> | ||
/// The thickness 1. | ||
/// </param> | ||
/// <param name="t2"> | ||
/// The thickness 2. | ||
/// </param> | ||
/// <returns> | ||
/// Returns true if the thickness values are equal. | ||
/// </returns> | ||
public static bool operator ==(Thickness t1, Thickness t2) | ||
{ | ||
return t1.Equals(t2); | ||
} | ||
|
||
/// <summary> | ||
/// Checks the inequality of two thickness items. | ||
/// </summary> | ||
/// <param name="t1"> | ||
/// The thickness 1. | ||
/// </param> | ||
/// <param name="t2"> | ||
/// The thickness 2. | ||
/// </param> | ||
/// <returns> | ||
/// Returns true if the thickness values are not equal. | ||
/// </returns> | ||
public static bool operator !=(Thickness t1, Thickness t2) | ||
{ | ||
return !t1.Equals(t2); | ||
} | ||
|
||
#if __ANDROID__ | ||
/// <summary> | ||
/// Converts the thickness value to the correct density pixels for the device. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns the thickness converted to density pixels. | ||
/// </returns> | ||
public Thickness InDensityPixels() | ||
{ | ||
float d = Android.App.Application.Context.Resources.DisplayMetrics.Density; | ||
return new Thickness(this.Left / d, this.Top / d, this.Right / d, this.Bottom / d); | ||
} | ||
#endif | ||
|
||
/// <summary>Returns the fully qualified type name of this instance.</summary> | ||
/// <returns>A <see cref="T:System.String" /> containing a fully qualified type name.</returns> | ||
/// <filterpriority>2</filterpriority> | ||
public override string ToString() | ||
{ | ||
return this.ToString(CultureInfo.InvariantCulture); | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the specified object is equal to the current object. | ||
/// </summary> | ||
/// <param name="obj"> | ||
/// The object to compare with the current object. | ||
/// </param> | ||
/// <returns> | ||
/// Returns true if the specified object is equal to the current object. | ||
/// </returns> | ||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
return obj.GetType() == this.GetType() && this.Equals((Thickness)obj); | ||
} | ||
|
||
/// <summary> | ||
/// Checks the equality of the current thickness and the given thickness. | ||
/// </summary> | ||
/// <param name="other"> | ||
/// The other thickness to compare. | ||
/// </param> | ||
/// <returns> | ||
/// Return true if the thickness values are equal. | ||
/// </returns> | ||
public bool Equals(Thickness other) | ||
{ | ||
return this.Bottom.Equals(other.Bottom) && this.Left.Equals(other.Left) && this.Right.Equals(other.Right) && this.Top.Equals(other.Top); | ||
} | ||
|
||
/// <summary> | ||
/// Serves as the default hash function. | ||
/// </summary> | ||
/// <returns> | ||
/// A hash code for the current object. | ||
/// </returns> | ||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
int hashCode = this.Bottom.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ this.Left.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ this.Right.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ this.Top.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
|
||
internal string ToString(CultureInfo cultureInfo) | ||
{ | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.Append(this.InternalToString(this.Left, cultureInfo)); | ||
stringBuilder.Append(","); | ||
stringBuilder.Append(this.InternalToString(this.Top, cultureInfo)); | ||
stringBuilder.Append(","); | ||
stringBuilder.Append(this.InternalToString(this.Right, cultureInfo)); | ||
stringBuilder.Append(","); | ||
stringBuilder.Append(this.InternalToString(this.Bottom, cultureInfo)); | ||
return stringBuilder.ToString(); | ||
} | ||
|
||
internal string InternalToString(double value, CultureInfo cultureInfo) | ||
{ | ||
return double.IsNaN(value) ? "Auto" : Convert.ToString(value, (IFormatProvider)cultureInfo); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace XPlat.UI | ||
{ | ||
/// <summary>Provides helper methods to evaluate or set Thickness values.</summary> | ||
public class ThicknessHelper | ||
{ | ||
/// <summary>Creates a Thickness value based on element values.</summary> | ||
/// <param name="left">The initial **Left**.</param> | ||
/// <param name="top">The initial **Top**.</param> | ||
/// <param name="right">The initial **Right**.</param> | ||
/// <param name="bottom">The initial **Bottom**.</param> | ||
/// <returns>The created Thickness.</returns> | ||
public static Thickness FromLengths(double left, double top, double right, double bottom) | ||
{ | ||
return new Thickness(left, top, right, bottom); | ||
} | ||
|
||
/// <summary>Creates a new Thickness value using a uniform value for all the element values.</summary> | ||
/// <param name="uniformLength">The uniform value to apply to all four of the Thickness element values.</param> | ||
/// <returns>The created Thickness.</returns> | ||
public static Thickness FromUniformLength(double uniformLength) | ||
{ | ||
return new Thickness(uniformLength); | ||
} | ||
} | ||
} |
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