1+ // --------------------------------------------------------------------------------------------------------------------
2+ // <copyright file="Thickness.cs" company="MADE Apps">
3+ // Copyright (c) MADE Apps.
4+ // </copyright>
5+ // <summary>
6+ // Defines a model for a UI thickness for padding or margins.
7+ // </summary>
8+ // --------------------------------------------------------------------------------------------------------------------
9+
10+ namespace MADE . App . Views . Layout
11+ {
12+ /// <summary>
13+ /// Defines a model for a UI thickness for padding or margins.
14+ /// </summary>
15+ public class Thickness
16+ {
17+ /// <summary>
18+ /// Initializes a new instance of the <see cref="Thickness"/> class.
19+ /// </summary>
20+ /// <param name="uniformLengthPixels">
21+ /// A single length value to apply to all parts of the thickness in pixels.
22+ /// </param>
23+ public Thickness ( double uniformLengthPixels )
24+ {
25+ this . Bottom = uniformLengthPixels ;
26+ this . Left = uniformLengthPixels ;
27+ this . Right = uniformLengthPixels ;
28+ this . Top = uniformLengthPixels ;
29+ }
30+
31+ /// <summary>
32+ /// Initializes a new instance of the <see cref="Thickness"/> class.
33+ /// </summary>
34+ /// <param name="leftPx">
35+ /// The left value.
36+ /// </param>
37+ /// <param name="topPx">
38+ /// The top value.
39+ /// </param>
40+ /// <param name="rightPx">
41+ /// The right value.
42+ /// </param>
43+ /// <param name="bottomPx">
44+ /// The bottom value.
45+ /// </param>
46+ public Thickness ( double leftPx , double topPx , double rightPx , double bottomPx )
47+ {
48+ this . Bottom = bottomPx ;
49+ this . Left = leftPx ;
50+ this . Right = rightPx ;
51+ this . Top = topPx ;
52+ }
53+
54+ #if WINDOWS_UWP
55+ public Thickness ( Windows . UI . Xaml . Thickness thickness )
56+ {
57+ this . Bottom = thickness . Bottom ;
58+ this . Left = thickness . Left ;
59+ this . Right = thickness . Right ;
60+ this . Top = thickness . Top ;
61+ }
62+
63+ public static implicit operator Thickness ( Windows . UI . Xaml . Thickness thickness )
64+ {
65+ return new Thickness ( thickness ) ;
66+ }
67+
68+ public static implicit operator Windows . UI . Xaml . Thickness ( Thickness thickness )
69+ {
70+ return new Windows . UI . Xaml . Thickness ( thickness . Left , thickness . Top , thickness . Right , thickness . Bottom ) ;
71+ }
72+ #endif
73+
74+ /// <summary>
75+ /// Gets or sets the bottom value.
76+ /// </summary>
77+ public double Bottom { get ; set ; }
78+
79+ /// <summary>
80+ /// Gets or sets the left value.
81+ /// </summary>
82+ public double Left { get ; set ; }
83+
84+ /// <summary>
85+ /// Gets or sets the right value.
86+ /// </summary>
87+ public double Right { get ; set ; }
88+
89+ /// <summary>
90+ /// Gets or sets the top value.
91+ /// </summary>
92+ public double Top { get ; set ; }
93+
94+ /// <summary>
95+ /// Checks the equality of two thickness items.
96+ /// </summary>
97+ /// <param name="t1">
98+ /// The thickness 1.
99+ /// </param>
100+ /// <param name="t2">
101+ /// The thickness 2.
102+ /// </param>
103+ /// <returns>
104+ /// Returns true if the thickness values are equal.
105+ /// </returns>
106+ public static bool operator == ( Thickness t1 , Thickness t2 )
107+ {
108+ return t1 . Equals ( t2 ) ;
109+ }
110+
111+ /// <summary>
112+ /// Checks the inequality of two thickness items.
113+ /// </summary>
114+ /// <param name="t1">
115+ /// The thickness 1.
116+ /// </param>
117+ /// <param name="t2">
118+ /// The thickness 2.
119+ /// </param>
120+ /// <returns>
121+ /// Returns true if the thickness values are not equal.
122+ /// </returns>
123+ public static bool operator != ( Thickness t1 , Thickness t2 )
124+ {
125+ return ! t1 . Equals ( t2 ) ;
126+ }
127+
128+ #if __ANDROID__
129+ /// <summary>
130+ /// Converts the thickness value to the correct density pixels for the device.
131+ /// </summary>
132+ /// <returns>
133+ /// Returns the thickness converted to density pixels.
134+ /// </returns>
135+ public Thickness InDensityPixels ( )
136+ {
137+ float d = Android . App . Application . Context . Resources . DisplayMetrics . Density ;
138+ return new Thickness ( this . Left / d , this . Top / d , this . Right / d , this . Bottom / d ) ;
139+ }
140+ #endif
141+
142+ /// <summary>
143+ /// Determines whether the specified object is equal to the current object.
144+ /// </summary>
145+ /// <param name="obj">
146+ /// The object to compare with the current object.
147+ /// </param>
148+ /// <returns>
149+ /// Returns true if the specified object is equal to the current object.
150+ /// </returns>
151+ public override bool Equals ( object obj )
152+ {
153+ if ( ReferenceEquals ( null , obj ) )
154+ {
155+ return false ;
156+ }
157+
158+ if ( ReferenceEquals ( this , obj ) )
159+ {
160+ return true ;
161+ }
162+
163+ return obj . GetType ( ) == this . GetType ( ) && this . Equals ( ( Thickness ) obj ) ;
164+ }
165+
166+ /// <summary>
167+ /// Serves as the default hash function.
168+ /// </summary>
169+ /// <returns>
170+ /// A hash code for the current object.
171+ /// </returns>
172+ public override int GetHashCode ( )
173+ {
174+ unchecked
175+ {
176+ int hashCode = this . Bottom . GetHashCode ( ) ;
177+ hashCode = ( hashCode * 397 ) ^ this . Left . GetHashCode ( ) ;
178+ hashCode = ( hashCode * 397 ) ^ this . Right . GetHashCode ( ) ;
179+ hashCode = ( hashCode * 397 ) ^ this . Top . GetHashCode ( ) ;
180+ return hashCode ;
181+ }
182+ }
183+
184+ /// <summary>
185+ /// Checks the equality of the current thickness and the given thickness.
186+ /// </summary>
187+ /// <param name="other">
188+ /// The other thickness to compare.
189+ /// </param>
190+ /// <returns>
191+ /// Return true if the thickness values are equal.
192+ /// </returns>
193+ protected bool Equals ( Thickness other )
194+ {
195+ return this . Bottom . Equals ( other . Bottom ) && this . Left . Equals ( other . Left ) && this . Right . Equals ( other . Right ) && this . Top . Equals ( other . Top ) ;
196+ }
197+ }
198+ }
0 commit comments