-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
LabelCoreGalleryPage.cs
323 lines (276 loc) · 12.8 KB
/
LabelCoreGalleryPage.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
using Xamarin.Forms.CustomAttributes;
namespace Xamarin.Forms.Controls
{
internal class LabelCoreGalleryPage : CoreGalleryPage<Label>
{
protected override bool SupportsFocus
{
get { return false; }
}
protected override void InitializeElement (Label element)
{
element.Text = "I am a label's text.";
}
protected override void Build (StackLayout stackLayout)
{
base.Build (stackLayout);
#pragma warning disable 618
var namedSizeMediumBoldContainer = new ViewContainer<Label> (Test.Label.FontAttibutesBold, new Label { Text = "Medium Bold Font", Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Bold) });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeMediumItalicContainer = new ViewContainer<Label> (Test.Label.FontAttributesItalic, new Label { Text = "Medium Italic Font", Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Italic) });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeMediumUnderlineContainer = new ViewContainer<Label>(Test.Label.TextDecorationUnderline, new Label { Text = "Medium Underlined Font", Font = Font.SystemFontOfSize(NamedSize.Medium), TextDecorations = TextDecorations.Underline });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeMediumStrikeContainer = new ViewContainer<Label>(Test.Label.TextDecorationStrike, new Label { Text = "Medium StrikeThrough Font", Font = Font.SystemFontOfSize(NamedSize.Medium), TextDecorations = TextDecorations.Strikethrough });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeLargeContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeLarge, new Label { Text = "Large Font", Font = Font.SystemFontOfSize (NamedSize.Large) });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeMediumContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeMedium, new Label { Text = "Medium Font", Font = Font.SystemFontOfSize (NamedSize.Medium) });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeMicroContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeMicro, new Label { Text = "Micro Font", Font = Font.SystemFontOfSize (NamedSize.Micro) });
#pragma warning restore 618
#pragma warning disable 618
var namedSizeSmallContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeSmall, new Label { Text = "Small Font", Font = Font.SystemFontOfSize (NamedSize.Small) });
#pragma warning restore 618
var formattedString = new FormattedString();
formattedString.Spans.Add(new Span { BackgroundColor = Color.Red, TextColor = Color.Olive, Text = "Span 1 " });
Span span = new Span { BackgroundColor = Color.Black, TextColor = Color.White, Text = "Span 2 (tap me) " };
span.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => DisplayAlert("Congratulations!", "This is a tapped span", "ok")) });
formattedString.Spans.Add(span);
formattedString.Spans.Add(new Span { BackgroundColor = Color.Pink, TextColor = Color.Purple, Text = "Span 3" });
var formattedTextContainer = new ViewContainer<Label>(Test.Label.FormattedText, new Label { FormattedText = formattedString });
const string longText = "Lorem ipsum dolor sit amet, cu mei malis petentium, dolor tempor delicata no qui, eos ex vitae utinam vituperata. Utroque habemus philosophia ut mei, doctus placerat eam cu. An inermis scaevola pro, quo legimus deleniti ei, equidem docendi urbanitas ea eum. Saepe doctus ut pri. Nec ex wisi dolorem. Duo dolor vituperatoribus ea. Id purto instructior per. Nec partem accusamus ne. Qui ad saepe accumsan appellantur, duis omnesque has et, vim nihil nemore scaevola ne. Ei populo appetere recteque xum, meliore splendide appellantur vix id.";
var lineBreakModeCharacterWrapContainer = new ViewContainer<Label> (Test.Label.LineBreakModeCharacterWrap, new Label { Text = longText, LineBreakMode = LineBreakMode.CharacterWrap });
var lineBreakModeHeadTruncationContainer = new ViewContainer<Label> (Test.Label.LineBreakModeHeadTruncation, new Label { Text = longText, LineBreakMode = LineBreakMode.HeadTruncation });
var lineBreakModeMiddleTruncationContainer = new ViewContainer<Label> (Test.Label.LineBreakModeMiddleTruncation, new Label { Text = longText, LineBreakMode = LineBreakMode.MiddleTruncation });
var lineBreakModeNoWrapContainer = new ViewContainer<Label> (Test.Label.LineBreakModeNoWrap, new Label { Text = longText, LineBreakMode = LineBreakMode.NoWrap });
var lineBreakModeTailTruncationContainer = new ViewContainer<Label> (Test.Label.LineBreakModeTailTruncation, new Label { Text = longText, LineBreakMode = LineBreakMode.TailTruncation });
var lineBreakModeWordWrapContainer = new ViewContainer<Label> (Test.Label.LineBreakModeWordWrap, new Label { Text = longText, LineBreakMode = LineBreakMode.WordWrap });
var textContainer = new ViewContainer<Label> (Test.Label.Text, new Label { Text = "I should have text" });
var textColorContainer = new ViewContainer<Label> (Test.Label.TextColor, new Label { Text = "I should have lime text", TextColor = Color.Lime });
const int alignmentTestsHeightRequest = 100;
const int alignmentTestsWidthRequest = 100;
var xAlignCenterContainer = new ViewContainer<Label> (Test.Label.HorizontalTextAlignmentCenter,
new Label {
Text = "HorizontalTextAlignment Center",
HorizontalTextAlignment = TextAlignment.Center,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest
}
);
var xAlignEndContainer = new ViewContainer<Label> (Test.Label.HorizontalTextAlignmentEnd,
new Label {
Text = "HorizontalTextAlignment End",
HorizontalTextAlignment = TextAlignment.End,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest
}
);
var xAlignStartContainer = new ViewContainer<Label> (Test.Label.HorizontalTextAlignmentStart,
new Label {
Text = "HorizontalTextAlignment Start",
HorizontalTextAlignment = TextAlignment.Start,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest
}
);
var yAlignCenterContainer = new ViewContainer<Label> (Test.Label.VerticalTextAlignmentCenter,
new Label {
Text = "VerticalTextAlignment Start",
VerticalTextAlignment = TextAlignment.Center,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest,
BackgroundColor = Color.Pink
}
);
var yAlignEndContainer = new ViewContainer<Label> (Test.Label.VerticalTextAlignmentEnd,
new Label {
Text = "VerticalTextAlignment End",
VerticalTextAlignment = TextAlignment.End,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest,
BackgroundColor = Color.Pink
}
);
var yAlignStartContainer = new ViewContainer<Label> (Test.Label.VerticalTextAlignmentStart,
new Label {
Text = "VerticalTextAlignment Start",
VerticalTextAlignment = TextAlignment.Start,
HeightRequest = alignmentTestsHeightRequest,
WidthRequest = alignmentTestsWidthRequest,
BackgroundColor = Color.Pink
}
);
var styleTitleContainer = new ViewContainer<Label> (Test.Device.Styles,
new Label {
Text = "Device.Styles.TitleStyle",
Style = Device.Styles.TitleStyle
}
);
var styleSubtitleContainer = new ViewContainer<Label> (Test.Device.Styles,
new Label {
Text = "Device.Styles.SubtitleStyle",
Style = Device.Styles.SubtitleStyle
}
);
var styleBodyContainer = new ViewContainer<Label> (Test.Device.Styles,
new Label {
Text = "Device.Styles.BodyStyle",
Style = Device.Styles.BodyStyle
}
);
var styleCaptionContainer = new ViewContainer<Label> (Test.Device.Styles,
new Label {
Text = "Device.Styles.CaptionStyle",
Style = Device.Styles.CaptionStyle,
}
);
var maxlinesContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label {
Text = longText,
MaxLines = 2
}
);
var maxlinesCharWrapContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.CharacterWrap
}
);
var maxlinesHeadTruncContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.HeadTruncation
}
);
var maxlinesMiddleTruncContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.MiddleTruncation
}
);
var maxlinesNoWrapContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.NoWrap
}
);
var maxlinesTailTruncContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.TailTruncation
}
);
var maxlinesWordWrapContainer = new ViewContainer<Label>(Test.Label.MaxLines,
new Label
{
Text = longText,
MaxLines = 2,
LineBreakMode = LineBreakMode.WordWrap
}
);
var formattedString2 = new FormattedString();
formattedString2.Spans.Add(new Span { BackgroundColor = Color.Red, TextColor = Color.Olive, Text = "Span 1 " });
var span2 = new Span { BackgroundColor = Color.Black, TextColor = Color.White, Text = "Span 2 (tap me) " };
span2.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => DisplayAlert("Congratulations!", "This is a tapped span", "ok")) });
formattedString2.Spans.Add(span2);
formattedString2.Spans.Add(new Span { BackgroundColor = Color.Pink, TextColor = Color.Purple, Text = "Span 3" });
var paddingContainer = new ViewContainer<Label>(Test.Label.Padding,
new Label
{
FormattedText = formattedString2,
BackgroundColor = Color.Yellow,
Padding = new Thickness(40, 20)
}
);
var htmlLabelContainer = new ViewContainer<Label>(Test.Label.HtmlTextType,
new Label
{
Text = "<h1>Hello world!</h1>",
TextType = TextType.Html
});
var htmlLabelMultipleLinesContainer = new ViewContainer<Label>(Test.Label.HtmlTextTypeMultipleLines,
new Label
{
Text = "<h1>Hello world!</h1><p>Lorem <strong>ipsum</strong> bla di bla <i>blabla</i> blablabl ablabla & blablablablabl ablabl ablablabl ablablabla blablablablablablab lablablabla blablab lablablabla blablabl ablablablab lablabla blab lablablabla blablab lablabla blablablablab lablabla blablab lablablabl ablablabla blablablablablabla blablabla</p>",
TextType = TextType.Html,
MaxLines = 3
});
var toggleLabel = new Label
{
TextType = TextType.Html,
Text = "<h1 style=\"color: red;\">Hello world!</h1><p>Lorem <strong>ipsum</strong></p>"
};
var htmlLabelProperties = new ViewContainer<Label>(Test.Label.HtmlTextLabelProperties, new Label
{
Text = "<h1>End aligned. Green. ä</h1>",
TextType = TextType.Html,
HorizontalTextAlignment = TextAlignment.Center,
TextColor = Color.Green,
});
var gestureRecognizer = new TapGestureRecognizer();
gestureRecognizer.Tapped += (s, a) =>
{
toggleLabel.TextType = toggleLabel.TextType == TextType.Html ? TextType.Text : TextType.Html;
};
toggleLabel.GestureRecognizers.Add(gestureRecognizer);
var toggleHtmlPlainTextLabelContainer = new ViewContainer<Label>(Test.Label.TextTypeToggle,
toggleLabel);
Add (namedSizeMediumBoldContainer);
Add (namedSizeMediumItalicContainer);
Add (namedSizeMediumUnderlineContainer);
Add (namedSizeMediumStrikeContainer);
Add (namedSizeLargeContainer);
Add (namedSizeMediumContainer);
Add (namedSizeMicroContainer);
Add (namedSizeSmallContainer);
Add (formattedTextContainer);
Add (lineBreakModeCharacterWrapContainer);
Add (lineBreakModeHeadTruncationContainer);
Add (lineBreakModeMiddleTruncationContainer);
Add (lineBreakModeNoWrapContainer);
Add (lineBreakModeTailTruncationContainer);
Add (lineBreakModeWordWrapContainer);
Add (textContainer);
Add (textColorContainer);
Add (xAlignCenterContainer);
Add (xAlignEndContainer);
Add (xAlignStartContainer);
Add (yAlignCenterContainer);
Add (yAlignEndContainer);
Add (yAlignStartContainer);
Add (styleTitleContainer);
Add (styleSubtitleContainer);
Add (styleBodyContainer);
Add (styleCaptionContainer);
Add (maxlinesContainer);
Add (maxlinesCharWrapContainer);
Add (maxlinesHeadTruncContainer);
Add (maxlinesMiddleTruncContainer);
Add (maxlinesNoWrapContainer);
Add (maxlinesTailTruncContainer);
Add (maxlinesWordWrapContainer);
Add(paddingContainer);
Add (htmlLabelContainer);
Add (htmlLabelMultipleLinesContainer);
Add (htmlLabelProperties);
Add (toggleHtmlPlainTextLabelContainer);
}
}
}