diff --git a/XPlat.UI.Controls/Orientation.cs b/XPlat.UI.Controls/Orientation.cs new file mode 100644 index 0000000..7e019fa --- /dev/null +++ b/XPlat.UI.Controls/Orientation.cs @@ -0,0 +1,12 @@ +namespace XPlat.UI.Controls +{ + /// Defines constants that specify the different orientations that a control or layout can have. + public enum Orientation + { + /// The control or layout should be vertically oriented. + Vertical, + + /// The control or layout should be horizontally oriented. + Horizontal, + } +} \ No newline at end of file diff --git a/XPlat.UI.Controls/XPlat.UI.Controls.csproj b/XPlat.UI.Controls/XPlat.UI.Controls.csproj new file mode 100644 index 0000000..6ba4540 --- /dev/null +++ b/XPlat.UI.Controls/XPlat.UI.Controls.csproj @@ -0,0 +1,40 @@ + + + + netstandard1.4;xamarin.ios10;monoandroid81;uap10.0 + true + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + 1.0.0.0 + James Croft + James Croft + XPlat - Windows.UI.Xaml.Controls APIs + Brings the functionality of the Windows.UI.Xaml.Controls APIs cross-platform with support for Windows, Android and iOS. + Copyright (C) James Croft. All rights reserved. + https://github.com/jamesmcroft/XPlat-Windows-APIs/blob/master/LICENSE + https://github.com/jamesmcroft/XPlat-Windows-APIs + https://i.imgur.com/tkagpGy.png + Xamarin UWP iOS Android Toolkit API Extensions Components Controls UI + en + XPlat.UI.Controls + + + + bin\Release\netstandard1.4\XPlat.UI.Controls.xml + + + + + + + + + + + + + + + diff --git a/XPlat.UI/Thickness.cs b/XPlat.UI/Thickness.cs new file mode 100644 index 0000000..44a603f --- /dev/null +++ b/XPlat.UI/Thickness.cs @@ -0,0 +1,232 @@ +namespace XPlat.UI +{ + using System; + using System.Globalization; + using System.Text; + + /// Describes the thickness of a frame around a rectangle. Four Double values describe the Left, Top, Right, and Bottom sides of the rectangle, respectively. + public struct Thickness + { + /// + /// Initializes a new instance of the struct. + /// + /// + /// A single length value to apply to all parts of the thickness in pixels. + /// + public Thickness(double uniformLength) + { + this.Left = this.Top = this.Right = this.Bottom = uniformLength; + } + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The left value. + /// + /// + /// The top value. + /// + /// + /// The right value. + /// + /// + /// The bottom value. + /// + 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 + /// + /// Initializes a new instance of the class. + /// + /// + /// The thickness value. + /// + public Thickness(Windows.UI.Xaml.Thickness thickness) + { + this.Bottom = thickness.Bottom; + this.Left = thickness.Left; + this.Right = thickness.Right; + this.Top = thickness.Top; + } + + /// + /// Creates a new object based on the given value. + /// + /// + /// The thickness value. + /// + public static implicit operator Thickness(Windows.UI.Xaml.Thickness thickness) + { + return new Thickness(thickness); + } + + /// + /// Creates a new object based on the given value. + /// + /// + /// The thickness value. + /// + 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 + + /// + /// Gets or sets the left value. + /// + public double Left { get; set; } + + /// + /// Gets or sets the top value. + /// + public double Top { get; set; } + + /// + /// Gets or sets the right value. + /// + public double Right { get; set; } + + /// + /// Gets or sets the bottom value. + /// + public double Bottom { get; set; } + + /// + /// Checks the equality of two thickness items. + /// + /// + /// The thickness 1. + /// + /// + /// The thickness 2. + /// + /// + /// Returns true if the thickness values are equal. + /// + public static bool operator ==(Thickness t1, Thickness t2) + { + return t1.Equals(t2); + } + + /// + /// Checks the inequality of two thickness items. + /// + /// + /// The thickness 1. + /// + /// + /// The thickness 2. + /// + /// + /// Returns true if the thickness values are not equal. + /// + public static bool operator !=(Thickness t1, Thickness t2) + { + return !t1.Equals(t2); + } + +#if __ANDROID__ + /// + /// Converts the thickness value to the correct density pixels for the device. + /// + /// + /// Returns the thickness converted to density pixels. + /// + 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 + + /// Returns the fully qualified type name of this instance. + /// A containing a fully qualified type name. + /// 2 + public override string ToString() + { + return this.ToString(CultureInfo.InvariantCulture); + } + + /// + /// Determines whether the specified object is equal to the current object. + /// + /// + /// The object to compare with the current object. + /// + /// + /// Returns true if the specified object is equal to the current object. + /// + 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); + } + + /// + /// Checks the equality of the current thickness and the given thickness. + /// + /// + /// The other thickness to compare. + /// + /// + /// Return true if the thickness values are equal. + /// + 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); + } + + /// + /// Serves as the default hash function. + /// + /// + /// A hash code for the current object. + /// + 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); + } + } +} \ No newline at end of file diff --git a/XPlat.UI/ThicknessHelper.cs b/XPlat.UI/ThicknessHelper.cs new file mode 100644 index 0000000..0008576 --- /dev/null +++ b/XPlat.UI/ThicknessHelper.cs @@ -0,0 +1,25 @@ +namespace XPlat.UI +{ + /// Provides helper methods to evaluate or set Thickness values. + public class ThicknessHelper + { + /// Creates a Thickness value based on element values. + /// The initial **Left**. + /// The initial **Top**. + /// The initial **Right**. + /// The initial **Bottom**. + /// The created Thickness. + public static Thickness FromLengths(double left, double top, double right, double bottom) + { + return new Thickness(left, top, right, bottom); + } + + /// Creates a new Thickness value using a uniform value for all the element values. + /// The uniform value to apply to all four of the Thickness element values. + /// The created Thickness. + public static Thickness FromUniformLength(double uniformLength) + { + return new Thickness(uniformLength); + } + } +} \ No newline at end of file diff --git a/XPlat.sln b/XPlat.sln index 8749287..4421f41 100644 --- a/XPlat.sln +++ b/XPlat.sln @@ -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 @@ -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 @@ -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}