-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ShellAppearance.cs
202 lines (163 loc) · 7.12 KB
/
ShellAppearance.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="Type[@FullName='Microsoft.Maui.Controls.ShellAppearance']/Docs/*" />
[EditorBrowsable(EditorBrowsableState.Never)]
public class ShellAppearance : IShellAppearanceElement
{
static readonly BindableProperty[] s_ingestArray = new[]
{
Shell.BackgroundColorProperty,
Shell.DisabledColorProperty,
Shell.ForegroundColorProperty,
Shell.TabBarBackgroundColorProperty,
Shell.TabBarDisabledColorProperty,
Shell.TabBarForegroundColorProperty,
Shell.TabBarTitleColorProperty,
Shell.TabBarUnselectedColorProperty,
Shell.TitleColorProperty,
Shell.UnselectedColorProperty
};
static readonly BindableProperty[] s_ingestBrushArray = new[]
{
Shell.FlyoutBackdropProperty
};
static readonly BindableProperty[] s_ingestDoubleArray = new[]
{
Shell.FlyoutWidthProperty,
Shell.FlyoutHeightProperty
};
Color[] _colorArray = new Color[s_ingestArray.Length];
Brush[] _brushArray = new Brush[s_ingestBrushArray.Length];
double[] _doubleArray = new double[s_ingestDoubleArray.Length];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='BackgroundColor']/Docs/*" />
public Color BackgroundColor => _colorArray[0];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='DisabledColor']/Docs/*" />
public Color DisabledColor => _colorArray[1];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='ForegroundColor']/Docs/*" />
public Color ForegroundColor => _colorArray[2];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TabBarBackgroundColor']/Docs/*" />
public Color TabBarBackgroundColor => _colorArray[3];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TabBarDisabledColor']/Docs/*" />
public Color TabBarDisabledColor => _colorArray[4];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TabBarForegroundColor']/Docs/*" />
public Color TabBarForegroundColor => _colorArray[5];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TabBarTitleColor']/Docs/*" />
public Color TabBarTitleColor => _colorArray[6];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TabBarUnselectedColor']/Docs/*" />
public Color TabBarUnselectedColor => _colorArray[7];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='TitleColor']/Docs/*" />
public Color TitleColor => _colorArray[8];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='UnselectedColor']/Docs/*" />
public Color UnselectedColor => _colorArray[9];
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='FlyoutBackdrop']/Docs/*" />
public Brush FlyoutBackdrop => _brushArray[0];
public double FlyoutWidth => _doubleArray[0];
public double FlyoutHeight => _doubleArray[1];
Color IShellAppearanceElement.EffectiveTabBarBackgroundColor =>
TabBarBackgroundColor ?? BackgroundColor;
Color IShellAppearanceElement.EffectiveTabBarDisabledColor =>
TabBarDisabledColor ?? DisabledColor;
Color IShellAppearanceElement.EffectiveTabBarForegroundColor =>
TabBarForegroundColor ?? ForegroundColor;
Color IShellAppearanceElement.EffectiveTabBarTitleColor =>
TabBarTitleColor ?? TitleColor;
Color IShellAppearanceElement.EffectiveTabBarUnselectedColor =>
TabBarUnselectedColor ?? UnselectedColor;
internal ShellAppearance()
{
for (int i = 0; i < _brushArray.Length; i++)
_brushArray[i] = Brush.Default;
for (int i = 0; i < _doubleArray.Length; i++)
_doubleArray[i] = -1;
}
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='Equals']/Docs/*" />
public override bool Equals(object obj)
{
if (!(obj is ShellAppearance appearance))
return false;
for (int i = 0; i < _colorArray.Length; i++)
{
if (!EqualityComparer<Color>.Default.Equals(_colorArray[i], appearance._colorArray[i]))
return false;
}
for (int i = 0; i < _brushArray.Length; i++)
{
if (!EqualityComparer<Brush>.Default.Equals(_brushArray[i], appearance._brushArray[i]))
return false;
}
for (int i = 0; i < _doubleArray.Length; i++)
{
if (!EqualityComparer<double>.Default.Equals(_doubleArray[i], appearance._doubleArray[i]))
return false;
}
return true;
}
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='GetHashCode']/Docs/*" />
public override int GetHashCode()
{
var hashCode = -1988429770;
for (int i = 0; i < _colorArray.Length; i++)
hashCode = hashCode * -1521134295 + EqualityComparer<Color>.Default.GetHashCode(_colorArray[i]);
for (int i = 0; i < _brushArray.Length; i++)
hashCode = hashCode * -1521134295 + EqualityComparer<Brush>.Default.GetHashCode(_brushArray[i]);
for (int i = 0; i < _doubleArray.Length; i++)
hashCode = hashCode * -1521134295 + EqualityComparer<double>.Default.GetHashCode(_doubleArray[i]);
return hashCode;
}
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='Ingest']/Docs/*" />
public bool Ingest(Element pivot)
{
bool anySet = false;
var dataSet = pivot.GetValues<Color>(s_ingestArray);
for (int i = 0; i < s_ingestArray.Length; i++)
{
if (_colorArray[i] == null && dataSet[i].IsSet)
{
anySet = true;
_colorArray[i] = dataSet[i].Value;
}
}
var brushDataSet = pivot.GetValues<Brush>(s_ingestBrushArray);
for (int i = 0; i < s_ingestBrushArray.Length; i++)
{
if (Brush.IsNullOrEmpty(_brushArray[i]) && brushDataSet[i].IsSet)
{
anySet = true;
_brushArray[i] = brushDataSet[i].Value;
}
}
var doubleDataSet = pivot.GetValues<double>(s_ingestDoubleArray);
for (int i = 0; i < s_ingestDoubleArray.Length; i++)
{
if (_doubleArray[i] == -1 && doubleDataSet[i].IsSet)
{
anySet = true;
_doubleArray[i] = doubleDataSet[i].Value;
}
}
return anySet;
}
/// <include file="../../../docs/Microsoft.Maui.Controls/ShellAppearance.xml" path="//Member[@MemberName='MakeComplete']/Docs/*" />
public void MakeComplete()
{
for (int i = 0; i < s_ingestArray.Length; i++)
{
if (_colorArray[i] == null)
_colorArray[i] = null;
}
}
public static bool operator ==(ShellAppearance appearance1, ShellAppearance appearance2)
{
return EqualityComparer<ShellAppearance>.Default.Equals(appearance1, appearance2);
}
public static bool operator !=(ShellAppearance appearance1, ShellAppearance appearance2)
{
return !(appearance1 == appearance2);
}
}
}