summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs
blob: 9043c7011368e2b8b78fee9bbdde1f4cf163ca4f (plain)
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
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);

			var namedSizeMediumBoldContainer = new ViewContainer<Label> (Test.Label.FontAttibutesBold, new Label { Text = "Medium Bold Font", Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Bold) });
			var namedSizeMediumItalicContainer = new ViewContainer<Label> (Test.Label.FontAttributesItalic, new Label { Text = "Medium Italic Font", Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Italic) });
			var namedSizeLargeContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeLarge, new Label { Text = "Large Font", Font = Font.SystemFontOfSize (NamedSize.Large) });
			var namedSizeMediumContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeMedium, new Label { Text = "Medium Font", Font = Font.SystemFontOfSize (NamedSize.Medium) });
			var namedSizeMicroContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeMicro, new Label { Text = "Micro Font", Font = Font.SystemFontOfSize (NamedSize.Micro) });
			var namedSizeSmallContainer = new ViewContainer<Label> (Test.Label.FontNamedSizeSmall, new Label { Text = "Small Font", Font = Font.SystemFontOfSize (NamedSize.Small) });

			var formattedString = new FormattedString ();
			formattedString.Spans.Add (new Span { BackgroundColor = Color.Red, ForegroundColor = Color.Olive, Text = "Span 1 " });
			formattedString.Spans.Add (new Span { BackgroundColor = Color.Black, ForegroundColor = Color.White, Text = "Span 2 " });
			formattedString.Spans.Add (new Span { BackgroundColor = Color.Pink, ForegroundColor = 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 cum, 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
				}
			);

			var yAlignEndContainer = new ViewContainer<Label> (Test.Label.VerticalTextAlignmentEnd, 
				new Label {
					Text = "VerticalTextAlignment End",
 					VerticalTextAlignment = TextAlignment.End,
					HeightRequest = alignmentTestsHeightRequest, 
					WidthRequest = alignmentTestsWidthRequest
				}
			);

			var yAlignStartContainer = new ViewContainer<Label> (Test.Label.VerticalTextAlignmentStart, 
				new Label {
					Text = "VerticalTextAlignment Start",
 					VerticalTextAlignment = TextAlignment.Start,
					HeightRequest = alignmentTestsHeightRequest, 
					WidthRequest = alignmentTestsWidthRequest
				}
			);

			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,
				}
			);

			Add (namedSizeMediumBoldContainer);
			Add (namedSizeMediumItalicContainer);
			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);
		}
	}
}