summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/LabelGallery.cs
blob: c40d7ae4e2a0af4b035341832dedccf9a05bf971 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xamarin.Forms.Controls
{
	public class LabelGallery : ContentPage
	{
		public LabelGallery ()
		{
			var normal = new Label { Text = "Normal Label" };
			var center = new Label { Text = "Center Label" };
			var right = new Label { Text = "Right Label" };
			var moving = new Label { Text = "Move On Click" };
			var click = new Label { Text = "Click Label" };
			var rotate = new Label { Text = "Rotate Label" };
			var transparent = new Label { Text = "Transparent Label" };
			var color = new Label { Text = "Color Change" };
			var micro = new Label { Text = "Micro Label" };
			var small = new Label { Text = "Small Label" };
			var medium = new Label { Text = "Medium Label" };
			var large = new Label { Text = "Large Label", VerticalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center};
			var bold = new Label { Text = "Bold Label" };
			var italic = new Label { Text = "Italic Label" };
			var bolditalic = new Label { Text = "Bold Italic Label" };
			var customFont = new Label { Text = "Custom Font" };
			var italicfont = new Label { Text = "Custom Italic Font" };
			var boldfont = new Label { Text = "Custom Bold Font" };
			var bolditalicfont = new Label { Text = "Custom Bold Italic Font" };
			var huge = new Label {
				Text = "This is the label that never ends, yes it go on and on my friend. " +
				"Some people started catting it not knowing what it was, and they'll continue catting it forever just because...",
				LineBreakMode = LineBreakMode.WordWrap
			};
			var formatted = new Label { FormattedText = new FormattedString { 
					Spans = { 
#pragma warning disable 618
						new Span {Text="FormattedStrings ", ForegroundColor=Color.Blue, BackgroundColor = Color.Yellow, Font = Font.BoldSystemFontOfSize (NamedSize.Large)},
#pragma warning restore 618
						new Span {Text="are ", ForegroundColor=Color.Red, BackgroundColor = Color.Gray},
						new Span {Text="not pretty!", ForegroundColor = Color.Green,},
					}
				} };
			var missingfont = new Label { Text = "Missing font: use default" };

#pragma warning disable 618
			micro.Font = Font.SystemFontOfSize (NamedSize.Micro);
#pragma warning restore 618

#pragma warning disable 618
			small.Font = Font.SystemFontOfSize (NamedSize.Small);
#pragma warning restore 618

#pragma warning disable 618
			medium.Font = Font.SystemFontOfSize (NamedSize.Medium);
#pragma warning restore 618

#pragma warning disable 618
			large.Font = Font.SystemFontOfSize (NamedSize.Large);
#pragma warning restore 618

#pragma warning disable 618
			bold.Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Bold);
#pragma warning restore 618

#pragma warning disable 618
			italic.Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Italic);
#pragma warning restore 618

#pragma warning disable 618
			bolditalic.Font = Font.SystemFontOfSize (NamedSize.Medium, FontAttributes.Bold | FontAttributes.Italic);
#pragma warning restore 618

			var fontName = Device.OnPlatform ("Georgia", "sans-serif-light", "Comic Sans MS");
			var font = Font.OfSize (fontName, NamedSize.Medium);
#pragma warning disable 618
			customFont.Font = font;
#pragma warning restore 618

#pragma warning disable 618
			italicfont.Font = font.WithAttributes (FontAttributes.Italic);
#pragma warning restore 618

#pragma warning disable 618
			boldfont.Font = font.WithAttributes (FontAttributes.Bold);
#pragma warning restore 618

#pragma warning disable 618
			bolditalicfont.Font = font.WithAttributes (FontAttributes.Bold | FontAttributes.Italic);
#pragma warning restore 618

#pragma warning disable 618
			customFont.GestureRecognizers.Add (new TapGestureRecognizer{Command = new Command (o => customFont.Font = Font.Default)});
#pragma warning restore 618

#pragma warning disable 618
			missingfont.Font = Font.OfSize ("FooBar", 20);
#pragma warning restore 618
			center.HorizontalTextAlignment = TextAlignment.Center;
			right.HorizontalTextAlignment = TextAlignment.End;
			int i = 1;
			click.GestureRecognizers.Add (new TapGestureRecognizer{Command = new Command (o=>click.Text = "Clicked " + i++)});
			rotate.GestureRecognizers.Add (new TapGestureRecognizer{Command = new Command (o=>rotate.RelRotateTo (180))});
			transparent.Opacity = .5;
			moving.GestureRecognizers.Add (new TapGestureRecognizer{Command = new Command (o=>moving.HorizontalTextAlignment = TextAlignment.End)});

			color.GestureRecognizers.Add (new TapGestureRecognizer{Command = new Command (o=>{
				color.TextColor = new Color (1, 0, 0);
				color.BackgroundColor = new Color (0, 1, 0);
			})});

			Thickness padding = new Thickness (20);
			// Padding Adjust for iPad
			Device.OnPlatform (iOS: () => {
				if (Device.Idiom == TargetIdiom.Tablet)
					padding = new Thickness (20, 20, 20, 60);
			});

			Content = new ScrollView {
				Content = new StackLayout {
					Padding = padding,
					Children = {
						formatted,
						normal,
						center,
						right,
						huge,
						moving,
						click,
						rotate,
						transparent,
						color,
						micro,
						small,
						medium,
						large,
						bold,
						italic,
						bolditalic,
						customFont,
						italicfont,
						boldfont,
						bolditalicfont,
						missingfont,
					}
				}
			};
		}
	}
}