-
-
Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy pathEtoLayoutExtensions.cs
More file actions
271 lines (196 loc) · 11.7 KB
/
Copy pathEtoLayoutExtensions.cs
File metadata and controls
271 lines (196 loc) · 11.7 KB
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
using Eto.Drawing;
using Eto.Forms;
namespace NAPS2.EtoForms.Layout;
public static class EtoLayoutExtensions
{
public static Icon ToEtoIcon(this byte[] bytes) => new(new MemoryStream(bytes));
public static Bitmap ToEtoImage(this byte[] bytes) => new(bytes);
public static Bitmap ToEtoImage(this IMemoryImage image) => EtoPlatform.Current.ToBitmap(image);
public static MessageBoxType ToEto(this MessageBoxIcon icon)
{
return icon switch
{
MessageBoxIcon.Information => MessageBoxType.Information,
MessageBoxIcon.Warning => MessageBoxType.Warning,
_ => MessageBoxType.Information // TODO: Default type with no icon?
};
}
public static DockPosition ToEto(this DockStyle dock)
{
return dock switch
{
DockStyle.Bottom => DockPosition.Bottom,
DockStyle.Left => DockPosition.Left,
DockStyle.Right => DockPosition.Right,
_ => DockPosition.Top
};
}
public static LayoutControl Width(this Control control, int? width) =>
new LayoutControl(control, width: width);
public static LayoutControl MinWidth(this Control control, int minWidth) =>
new LayoutControl(control, minWidth: minWidth);
public static LayoutControl MaxWidth(this Control control, int maxWidth) =>
new LayoutControl(control, maxWidth: maxWidth);
public static LayoutControl Height(this Control control, int? height) =>
new LayoutControl(control, height: height);
public static LayoutControl MinHeight(this Control control, int minHeight) =>
new LayoutControl(control, minHeight: minHeight);
public static LayoutControl MaxHeight(this Control control, int maxHeight) =>
new LayoutControl(control, maxHeight: maxHeight);
public static LayoutControl Size(this Control control, int width, int height) =>
new LayoutControl(control, width: width, height: height);
public static LayoutControl NaturalSize(this Control control, int width, int height) =>
new LayoutControl(control, naturalWidth: width, naturalHeight: height);
public static LayoutControl NaturalWidth(this Control control, int width) =>
new LayoutControl(control, naturalWidth: width);
public static LayoutControl NaturalHeight(this Control control, int height) =>
new LayoutControl(control, naturalHeight: height);
public static LayoutControl Scale(this Control control) =>
new LayoutControl(control, scale: true);
public static LayoutControl SpacingAfter(this Control control, int spacingAfter) =>
new LayoutControl(control, spacingAfter: spacingAfter);
public static LayoutControl AlignCenter(this Control control) =>
new LayoutControl(control, alignment: LayoutAlignment.Center);
public static LayoutControl AlignLeading(this Control control) =>
new LayoutControl(control, alignment: LayoutAlignment.Leading);
public static LayoutControl AlignTrailing(this Control control) =>
new LayoutControl(control, alignment: LayoutAlignment.Trailing);
public static LayoutControl Align(this Control control, LayoutAlignment alignment) =>
new LayoutControl(control, alignment: alignment);
public static LayoutColumn AlignCenter(this LayoutColumn column) =>
new LayoutColumn(column, alignment: LayoutAlignment.Center);
public static LayoutColumn AlignLeading(this LayoutColumn column) =>
new LayoutColumn(column, alignment: LayoutAlignment.Leading);
public static LayoutColumn AlignTrailing(this LayoutColumn column) =>
new LayoutColumn(column, alignment: LayoutAlignment.Trailing);
public static LayoutColumn Align(this LayoutColumn column, LayoutAlignment alignment) =>
new LayoutColumn(column, alignment: alignment);
public static LayoutRow AlignCenter(this LayoutRow row) =>
new LayoutRow(row, alignment: LayoutAlignment.Center);
public static LayoutRow AlignLeading(this LayoutRow row) =>
new LayoutRow(row, alignment: LayoutAlignment.Leading);
public static LayoutRow AlignTrailing(this LayoutRow row) =>
new LayoutRow(row, alignment: LayoutAlignment.Trailing);
public static LayoutRow Align(this LayoutRow row, LayoutAlignment alignment) =>
new LayoutRow(row, alignment: alignment);
public static LayoutControl Padding(this Control control, Padding padding) =>
new LayoutControl(control, padding: padding);
public static LayoutControl Padding(this Control control, int all) =>
new LayoutControl(control, padding: new Padding(all));
public static LayoutControl Padding(this Control control, int left = 0, int top = 0, int right = 0,
int bottom = 0) =>
new LayoutControl(control, padding: new Padding(left, top, right, bottom));
public static LayoutControl Visible(this Control control, LayoutVisibility? visibility) =>
new LayoutControl(control, visibility: visibility);
public static Label Ellipsize(this Label label)
{
EtoPlatform.Current.ConfigureEllipsis(label);
return label;
}
/// <summary>
/// Wraps the given label. The way this works is that is uses the specified width to calculate the allocated height,
/// which remains static (so e.g. if you're resizing a form, the form height isn't dependent on its width). If
/// wrapping happens at that width, it becomes the minimum width (as otherwise the label could exceed its vertical
/// bounds). If wrapping doesn't happen, the text width is the minimum width. Note that depending on how the control
/// is laid out in the form, you might need to set a Width or MaxWidth constraint for wrapping to actually happen.
/// </summary>
/// <param name="label"></param>
/// <param name="defaultWidth"></param>
/// <returns></returns>
public static LayoutControl DynamicWrap(this Label label, int defaultWidth)
{
if (defaultWidth == 0)
{
return label;
}
label.Wrap = WrapMode.Word;
return new LayoutControl(label, wrapDefaultWidth: defaultWidth);
}
public static LayoutControl Width(this LayoutControl control, int width) =>
new LayoutControl(control, width: width);
public static LayoutControl MinWidth(this LayoutControl control, int minWidth) =>
new LayoutControl(control, minWidth: minWidth);
public static LayoutControl MaxWidth(this LayoutControl control, int maxWidth) =>
new LayoutControl(control, maxWidth: maxWidth);
public static LayoutControl Height(this LayoutControl control, int height) =>
new LayoutControl(control, height: height);
public static LayoutControl MinHeight(this LayoutControl control, int minHeight) =>
new LayoutControl(control, minHeight: minHeight);
public static LayoutControl MaxHeight(this LayoutControl control, int maxHeight) =>
new LayoutControl(control, maxHeight: maxHeight);
public static LayoutControl NaturalSize(this LayoutControl control, int width, int height) =>
new LayoutControl(control, naturalWidth: width, naturalHeight: height);
public static LayoutControl NaturalWidth(this LayoutControl control, int width) =>
new LayoutControl(control, naturalWidth: width);
public static LayoutControl NaturalHeight(this LayoutControl control, int height) =>
new LayoutControl(control, naturalHeight: height);
public static LayoutControl Scale(this LayoutControl control) =>
new LayoutControl(control, scale: true);
public static LayoutElement Scale(this LayoutElement element)
{
element.Scale = true;
return element;
}
public static LayoutControl SpacingAfter(this LayoutControl control, int spacingAfter) =>
new LayoutControl(control, spacingAfter: spacingAfter);
public static LayoutControl AlignCenter(this LayoutControl control) =>
new LayoutControl(control, alignment: LayoutAlignment.Center);
public static LayoutControl AlignLeading(this LayoutControl control) =>
new LayoutControl(control, alignment: LayoutAlignment.Leading);
public static LayoutControl AlignTrailing(this LayoutControl control) =>
new LayoutControl(control, alignment: LayoutAlignment.Trailing);
public static LayoutControl Align(this LayoutControl control, LayoutAlignment alignment) =>
new LayoutControl(control, alignment: alignment);
public static LayoutControl Padding(this LayoutControl control, Padding padding) =>
new LayoutControl(control, padding: padding);
public static LayoutControl Padding(this LayoutControl control, int all) =>
new LayoutControl(control, padding: new Padding(all));
public static LayoutControl Padding(this LayoutControl control, int left = 0, int top = 0, int right = 0,
int bottom = 0) =>
new LayoutControl(control, padding: new Padding(left, top, right, bottom));
public static LayoutControl Visible(this LayoutControl control, LayoutVisibility? visibility) =>
new LayoutControl(control, visibility: visibility);
public static LayoutColumn Padding(this LayoutColumn column, Padding padding) =>
new LayoutColumn(column, padding: padding);
public static LayoutColumn Padding(this LayoutColumn column, int all) =>
new LayoutColumn(column, padding: new Padding(all));
public static LayoutColumn Padding(this LayoutColumn column, int left = 0, int top = 0, int right = 0,
int bottom = 0) =>
new LayoutColumn(column, padding: new Padding(left, top, right, bottom));
public static LayoutColumn Spacing(this LayoutColumn column, int spacing) =>
new LayoutColumn(column, spacing: spacing);
public static LayoutColumn SpacingAfter(this LayoutColumn column, int spacingAfter) =>
new LayoutColumn(column, spacingAfter: spacingAfter);
public static LayoutColumn Scale(this LayoutColumn column) =>
new LayoutColumn(column, scale: true);
public static LayoutColumn Aligned(this LayoutColumn column) =>
new LayoutColumn(column, aligned: true);
public static LayoutColumn Visible(this LayoutColumn column, LayoutVisibility visibility) =>
new LayoutColumn(column, visibility: visibility);
public static LayoutRow Padding(this LayoutRow row, Padding padding) =>
new LayoutRow(row, padding: padding);
public static LayoutRow Padding(this LayoutRow row, int all) =>
new LayoutRow(row, padding: new Padding(all));
public static LayoutRow Padding(this LayoutRow row, int left = 0, int top = 0, int right = 0, int bottom = 0) =>
new LayoutRow(row, padding: new Padding(left, top, right, bottom));
public static LayoutRow Spacing(this LayoutRow row, int spacing) =>
new LayoutRow(row, spacing: spacing);
public static LayoutRow SpacingAfter(this LayoutRow row, int spacingAfter) =>
new LayoutRow(row, spacingAfter: spacingAfter);
public static LayoutRow Scale(this LayoutRow row) =>
new LayoutRow(row, scale: true);
public static LayoutRow Aligned(this LayoutRow row) =>
new LayoutRow(row, aligned: true);
public static LayoutRow Visible(this LayoutRow row, LayoutVisibility visibility) =>
new LayoutRow(row, visibility: visibility);
public static LayoutOverlay Scale(this LayoutOverlay overlay) =>
new LayoutOverlay(overlay, scale: true);
public static LayoutElement Expand(this IEnumerable<LayoutElement> elements) =>
new ExpandLayoutElement(elements.ToArray());
public static LayoutElement Expand(this IEnumerable<Control> elements) =>
new ExpandLayoutElement(elements.Select(x => (LayoutElement) x).ToArray());
public static void AddItems(this ContextMenu contextMenu, params MenuItem[] menuItems)
{
contextMenu.Items.AddRange(menuItems);
}
}