Skip to content

Commit

Permalink
PR for #58 - Implemented Thickness API (#59)
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
jamesmcroft authored and tom-made committed Mar 13, 2019
1 parent e871f63 commit 0ff3e8a
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 0 deletions.
12 changes: 12 additions & 0 deletions XPlat.UI.Controls/Orientation.cs
@@ -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,
}
}
40 changes: 40 additions & 0 deletions XPlat.UI.Controls/XPlat.UI.Controls.csproj
@@ -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>
232 changes: 232 additions & 0 deletions XPlat.UI/Thickness.cs
@@ -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);
}
}
}
25 changes: 25 additions & 0 deletions XPlat.UI/ThicknessHelper.cs
@@ -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);
}
}
}
51 changes: 51 additions & 0 deletions XPlat.sln
Expand Up @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XPlat.Samples.iOS", "XPlat.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XPlat.ApplicationModel", "XPlat.ApplicationModel\XPlat.ApplicationModel.csproj", "{08E1FD7A-DB1F-416B-AFF8-1ACEC7525419}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XPlat.UI.Controls", "XPlat.UI.Controls\XPlat.UI.Controls.csproj", "{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -1146,6 +1148,54 @@ Global
{08E1FD7A-DB1F-416B-AFF8-1ACEC7525419}.Release|x64.Build.0 = Release|Any CPU
{08E1FD7A-DB1F-416B-AFF8-1ACEC7525419}.Release|x86.ActiveCfg = Release|Any CPU
{08E1FD7A-DB1F-416B-AFF8-1ACEC7525419}.Release|x86.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|ARM.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|iPhone.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|x64.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|x64.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|x86.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.AppStore|x86.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|ARM.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|iPhone.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|x64.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|x64.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|x86.ActiveCfg = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Debug|x86.Build.0 = Debug|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|Any CPU.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|ARM.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|ARM.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|iPhone.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|iPhone.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|x64.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|x64.Build.0 = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|x86.ActiveCfg = Release|Any CPU
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -1172,6 +1222,7 @@ Global
{FCF6A9E8-650A-4225-A8E6-BDFF4B4CEE5F} = {D1AEF003-632F-4A32-8281-32F22FD47EA6}
{101E3060-8799-4119-8A7A-4F86A01C0C84} = {DF048C6D-7657-46DC-A059-276547B6E926}
{08E1FD7A-DB1F-416B-AFF8-1ACEC7525419} = {D1AEF003-632F-4A32-8281-32F22FD47EA6}
{1D3C1D3A-4C5A-4D65-A453-4CFE4F3AA3B6} = {D1AEF003-632F-4A32-8281-32F22FD47EA6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D974AA36-9622-4207-B11A-D2648ADC3DC9}
Expand Down

0 comments on commit 0ff3e8a

Please sign in to comment.