-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormattedTextSection.cs
132 lines (104 loc) · 4.92 KB
/
FormattedTextSection.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
namespace Eto.Test.Sections.Drawing
{
[Section("Drawing", typeof(FormattedText))]
public class FormattedTextSection : Scrollable
{
public FormattedTextSection()
{
Styles.Add<Label>(null, l => l.VerticalAlignment = VerticalAlignment.Center);
var font = SystemFonts.Default();
var color = Colors.White;
var formattedTextSingleLine = new FormattedText
{
Text = "Some text with no new lines that should have an ellipsis when not wrapped",
MaximumSize = new SizeF(500, float.MaxValue),
Wrap = FormattedTextWrapMode.Word,
Trimming = FormattedTextTrimming.CharacterEllipsis,
ForegroundBrush = Brushes.White,
//ForegroundBrush = new LinearGradientBrush(Colors.White, Colors.Blue, new PointF(0, 0), new PointF(200, 200)),
Font = font
};
var formattedText = new FormattedText
{
Text = LoremGenerator.GenerateLines(2, 10, 30),
MaximumSize = new SizeF(500, 80),
Wrap = FormattedTextWrapMode.Word,
Trimming = FormattedTextTrimming.CharacterEllipsis,
ForegroundBrush = Brushes.White,
//ForegroundBrush = new LinearGradientBrush(Colors.White, Colors.Blue, new PointF(0, 0), new PointF(200, 200)),
Font = font
};
var formattedTextWithNewLines = new FormattedText
{
Text = LoremGenerator.GenerateLines(6, 10, 20),
Wrap = FormattedTextWrapMode.Word,
Trimming = FormattedTextTrimming.CharacterEllipsis,
ForegroundBrush = Brushes.White,
//ForegroundBrush = new LinearGradientBrush(Colors.White, Colors.Blue, new PointF(0, 0), new PointF(200, 200)),
Font = font
};
var control = new Drawable { Size = new Size(400, 500), BackgroundColor = Colors.Black };
control.Paint += (sender, e) =>
{
var g = e.Graphics;
var location = new PointF(10, 10);
g.DrawText(font, color, location, "Single Line Text That Will Not Wrap 漢字");
location.Y += 40;
var rect = new RectangleF(location, new SizeF(300, 20));
g.DrawRectangle(Colors.Blue, rect);
g.DrawText(font, new SolidBrush(color), rect, "Should Be Right Aligned", FormattedTextWrapMode.None, FormattedTextAlignment.Right, FormattedTextTrimming.None);
location.Y += 40;
var sizeSingleLine = formattedTextSingleLine.Measure();
g.DrawText(formattedTextSingleLine, location);
g.DrawRectangle(Colors.Silver, new RectangleF(location, sizeSingleLine));
location.Y += sizeSingleLine.Height + 20;
g.DrawRectangle(Colors.Blue, new RectangleF(location, formattedText.MaximumSize));
var size = formattedText.Measure();
g.DrawText(formattedText, location);
g.DrawRectangle(Colors.Silver, new RectangleF(location, size));
location.Y += (int)formattedText.MaximumHeight + 20;
var sizeWithNewLines = formattedTextWithNewLines.Measure();
g.DrawText(formattedTextWithNewLines, location);
g.DrawRectangle(Colors.Silver, new RectangleF(location, sizeWithNewLines));
};
var wrapMode = new EnumDropDown<FormattedTextWrapMode>();
wrapMode.SelectedValueBinding.Bind(formattedText, f => f.Wrap);
wrapMode.SelectedValueBinding.Bind(formattedTextWithNewLines, f => f.Wrap);
wrapMode.SelectedValueBinding.Bind(formattedTextSingleLine, f => f.Wrap);
wrapMode.SelectedValueChanged += (sender, e) => control.Invalidate();
var trimming = new EnumDropDown<FormattedTextTrimming>();
trimming.SelectedValueBinding.Bind(formattedText, f => f.Trimming);
trimming.SelectedValueBinding.Bind(formattedTextWithNewLines, f => f.Trimming);
trimming.SelectedValueBinding.Bind(formattedTextSingleLine, f => f.Trimming);
trimming.SelectedValueChanged += (sender, e) => control.Invalidate();
var alignment = new EnumDropDown<FormattedTextAlignment>();
alignment.SelectedValueBinding.Bind(formattedText, f => f.Alignment);
alignment.SelectedValueBinding.Bind(formattedTextWithNewLines, f => f.Alignment);
alignment.SelectedValueBinding.Bind(formattedTextSingleLine, f => f.Alignment);
alignment.SelectedValueChanged += (sender, e) => control.Invalidate();
var fontSelection = new FontPicker();
fontSelection.ValueBinding.Bind(formattedText, f => f.Font);
fontSelection.ValueBinding.Bind(formattedTextWithNewLines, f => f.Font);
fontSelection.ValueBinding.Bind(formattedTextSingleLine, f => f.Font);
fontSelection.ValueChanged += (sender, e) => control.Invalidate();
var maxSizeEntry = new SizeFEntry();
maxSizeEntry.ValueBinding.Bind(formattedText, f => f.MaximumSize);
maxSizeEntry.ValueBinding.Child(r => r.Width).Bind(formattedTextSingleLine, f => (int)f.MaximumSize.Width);
maxSizeEntry.ValueChanged += (sender, e) => control.Invalidate();
var layout = new DynamicLayout();
layout.DefaultSpacing = new Size(4, 4);
layout.BeginCentered();
layout.AddSeparateRow(
"Wrap:", wrapMode,
"Trimming:", trimming,
"Alignment:", alignment,
"Font:", fontSelection,
null
);
layout.AddSeparateRow("MaximumSize:", maxSizeEntry, null);
layout.EndCentered();
layout.Add(control);
Content = layout;
}
}
}