Repository navigation
Expand file tree
/
Copy pathUiControls.cs
More file actions
454 lines (413 loc) · 16.4 KB
/
Copy pathUiControls.cs
File metadata and controls
454 lines (413 loc) · 16.4 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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
using System;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Shapes;
namespace DesktopNest
{
internal static class DesktopHeaderGlyphs
{
public const string Arrange = "\uF0E2";
public const string More = "\uE712";
public const string Settings = "\uE713";
public const string Expand = "\uE70D";
public const string Collapse = "\uE70E";
public const string Locked = "\uE72E";
public const string Unlocked = "\uE785";
}
internal static class Ui
{
public static readonly SolidColorBrush TextPrimary = Brush("#FFF7FAFC");
public static readonly SolidColorBrush TextSecondary = Brush("#FF9CAABD");
public static readonly SolidColorBrush TextMuted = Brush("#FF6F7D91");
public static readonly SolidColorBrush Accent = Brush("#FF62E3D0");
public static readonly SolidColorBrush AccentSoft = Brush("#3362E3D0");
public static readonly SolidColorBrush Purple = Brush("#FF9C8CFF");
public static readonly SolidColorBrush PurpleSoft = Brush("#309C8CFF");
public static readonly SolidColorBrush Card = Brush("#B8162132");
public static readonly SolidColorBrush CardHover = Brush("#D1223045");
public static readonly SolidColorBrush Stroke = Brush("#26FFFFFF");
public static readonly SolidColorBrush StrokeStrong = Brush("#42FFFFFF");
public static SolidColorBrush Brush(string hex)
{
SolidColorBrush brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex));
brush.Freeze();
return brush;
}
public static Thumb ResizeThumb(double size, string toolTip)
{
FrameworkElementFactory hitSurface =
new FrameworkElementFactory(typeof(Border));
hitSurface.SetValue(Border.BackgroundProperty, Brushes.Transparent);
ControlTemplate template = new ControlTemplate(typeof(Thumb));
template.VisualTree = hitSurface;
return new Thumb
{
Width = size,
Height = size,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Bottom,
Cursor = Cursors.SizeNWSE,
Background = Brushes.Transparent,
BorderThickness = new Thickness(0),
Focusable = false,
FocusVisualStyle = null,
Template = template,
ToolTip = toolTip
};
}
public static TextBlock Text(string text, double size, Brush color)
{
return new TextBlock
{
Text = text,
FontFamily = new FontFamily("Microsoft YaHei UI"),
FontSize = size,
Foreground = color,
TextTrimming = TextTrimming.CharacterEllipsis,
VerticalAlignment = VerticalAlignment.Center
};
}
public static Border CardBorder()
{
return new Border
{
Background = Card,
BorderBrush = Stroke,
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(16),
Padding = new Thickness(16)
};
}
public static Button IconButton(string glyph, string tooltip)
{
Button button = new Button
{
Content = glyph,
ToolTip = tooltip,
FontFamily = new FontFamily("Segoe MDL2 Assets"),
FontSize = 15,
Foreground = TextSecondary,
Background = System.Windows.Media.Brushes.Transparent,
BorderThickness = new Thickness(0),
Width = 36,
Height = 36,
Cursor = Cursors.Hand,
FocusVisualStyle = null
};
button.MouseEnter += delegate { button.Background = Ui.Brush("#18FFFFFF"); button.Foreground = TextPrimary; };
button.MouseLeave += delegate { button.Background = System.Windows.Media.Brushes.Transparent; button.Foreground = TextSecondary; };
return button;
}
public static void SetHeaderGlyph(Button button, string glyph, string toolTip)
{
if (button == null)
{
throw new ArgumentNullException("button");
}
button.Content = glyph;
button.FontFamily = new FontFamily("Segoe MDL2 Assets");
button.ToolTip = toolTip;
AutomationProperties.SetName(button, toolTip);
}
public static Button PillButton(string text, string glyph)
{
StackPanel content = new StackPanel { Orientation = Orientation.Horizontal };
content.Children.Add(new TextBlock
{
Text = glyph,
FontFamily = new FontFamily("Segoe MDL2 Assets"),
FontSize = 14,
Margin = new Thickness(0, 0, 8, 0),
VerticalAlignment = VerticalAlignment.Center
});
content.Children.Add(Ui.Text(text, 12, Ui.TextPrimary));
Button button = new Button
{
Content = content,
Foreground = TextPrimary,
Background = AccentSoft,
BorderBrush = Brush("#4562E3D0"),
BorderThickness = new Thickness(1),
Padding = new Thickness(12, 7, 12, 7),
Cursor = Cursors.Hand,
FocusVisualStyle = null
};
return button;
}
public static Style OverlayScrollBarStyle()
{
string xaml =
"<Style xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" TargetType=\"{x:Type ScrollBar}\">" +
"<Setter Property=\"Width\" Value=\"3\"/>" +
"<Setter Property=\"Background\" Value=\"Transparent\"/>" +
"<Setter Property=\"Template\"><Setter.Value>" +
"<ControlTemplate TargetType=\"{x:Type ScrollBar}\">" +
"<Grid Background=\"Transparent\" Margin=\"0,3\">" +
"<Track x:Name=\"PART_Track\" IsDirectionReversed=\"True\">" +
"<Track.DecreaseRepeatButton><RepeatButton Command=\"{x:Static ScrollBar.PageUpCommand}\" Opacity=\"0\"/></Track.DecreaseRepeatButton>" +
"<Track.Thumb><Thumb MinHeight=\"28\"><Thumb.Template><ControlTemplate TargetType=\"{x:Type Thumb}\">" +
"<Border Background=\"#3262E3D0\" CornerRadius=\"1.5\"/>" +
"</ControlTemplate></Thumb.Template></Thumb></Track.Thumb>" +
"<Track.IncreaseRepeatButton><RepeatButton Command=\"{x:Static ScrollBar.PageDownCommand}\" Opacity=\"0\"/></Track.IncreaseRepeatButton>" +
"</Track></Grid></ControlTemplate>" +
"</Setter.Value></Setter></Style>";
return (Style)XamlReader.Parse(xaml);
}
}
internal sealed class ModernSlider : Border
{
private readonly Border _track;
private readonly Border _fill;
private readonly Border _thumb;
private readonly TextBlock _valueText;
private bool _dragging;
private bool _silent;
private double _value;
public event EventHandler ValueChanged;
public ModernSlider(string title, string glyph, Brush accent)
{
CornerRadius = new CornerRadius(13);
Background = Ui.Brush("#5C0B1320");
BorderBrush = Ui.Stroke;
BorderThickness = new Thickness(1);
Padding = new Thickness(13, 11, 13, 12);
Margin = new Thickness(0, 0, 0, 10);
StackPanel root = new StackPanel();
Child = root;
Grid titleRow = new Grid();
titleRow.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
titleRow.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
titleRow.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
Border iconBubble = new Border
{
Background = Ui.Brush("#16FFFFFF"),
CornerRadius = new CornerRadius(8),
Width = 30,
Height = 30,
Margin = new Thickness(0, 0, 9, 0),
Child = new TextBlock
{
Text = glyph,
Foreground = accent,
FontFamily = new FontFamily("Segoe MDL2 Assets"),
FontSize = 15,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
};
Grid.SetColumn(iconBubble, 0);
titleRow.Children.Add(iconBubble);
TextBlock titleText = Ui.Text(title, 12.5, Ui.TextPrimary);
Grid.SetColumn(titleText, 1);
titleRow.Children.Add(titleText);
_valueText = Ui.Text("--", 11.5, Ui.TextSecondary);
_valueText.HorizontalAlignment = HorizontalAlignment.Right;
Grid.SetColumn(_valueText, 2);
titleRow.Children.Add(_valueText);
root.Children.Add(titleRow);
Grid trackHost = new Grid { Height = 18, Margin = new Thickness(2, 9, 2, 0), Cursor = Cursors.Hand };
_track = new Border
{
Background = Ui.Brush("#2BFFFFFF"),
CornerRadius = new CornerRadius(4),
Height = 6,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center
};
trackHost.Children.Add(_track);
_fill = new Border
{
Background = accent,
CornerRadius = new CornerRadius(4),
Height = 6,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
Width = 0
};
trackHost.Children.Add(_fill);
_thumb = new Border
{
Background = Ui.TextPrimary,
BorderBrush = accent,
BorderThickness = new Thickness(3),
CornerRadius = new CornerRadius(8),
Width = 16,
Height = 16,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center
};
trackHost.Children.Add(_thumb);
root.Children.Add(trackHost);
trackHost.SizeChanged += delegate { UpdateVisual(); };
trackHost.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
{
_dragging = true;
trackHost.CaptureMouse();
SetFromPoint(e.GetPosition(trackHost).X, trackHost.ActualWidth);
e.Handled = true;
};
trackHost.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (_dragging)
{
SetFromPoint(e.GetPosition(trackHost).X, trackHost.ActualWidth);
}
};
trackHost.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
{
if (_dragging)
{
_dragging = false;
trackHost.ReleaseMouseCapture();
SetFromPoint(e.GetPosition(trackHost).X, trackHost.ActualWidth);
}
};
}
public double Value
{
get { return _value; }
set
{
double next = Math.Max(0, Math.Min(100, value));
if (Math.Abs(next - _value) < 0.01)
{
return;
}
_value = next;
UpdateVisual();
if (!_silent && ValueChanged != null)
{
ValueChanged(this, EventArgs.Empty);
}
}
}
public void SetValueSilently(double value)
{
_silent = true;
Value = value;
_silent = false;
UpdateVisual();
}
public void SetAvailable(bool available, string unavailableText)
{
IsEnabled = available;
Opacity = available ? 1 : 0.52;
if (!available)
{
_valueText.Text = unavailableText;
}
else
{
UpdateVisual();
}
}
private void SetFromPoint(double x, double width)
{
if (!IsEnabled || width <= 0)
{
return;
}
Value = x / width * 100.0;
}
private void UpdateVisual()
{
if (_track == null || _thumb == null || _fill == null)
{
return;
}
double width = _track.ActualWidth;
double position = width * _value / 100.0;
_fill.Width = Math.Max(0, position);
_thumb.Margin = new Thickness(Math.Max(0, position - _thumb.Width / 2), 0, 0, 0);
if (IsEnabled)
{
_valueText.Text = Math.Round(_value).ToString("0") + "%";
}
}
}
internal sealed class ToggleRow : Border
{
private readonly Border _track;
private readonly Border _thumb;
private bool _checked;
public event EventHandler CheckedChanged;
public ToggleRow(string title, string subtitle)
{
Background = System.Windows.Media.Brushes.Transparent;
Padding = new Thickness(0, 9, 0, 9);
Cursor = Cursors.Hand;
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
Child = grid;
StackPanel labels = new StackPanel();
TextBlock titleText = Ui.Text(title, 12.5, Ui.TextPrimary);
labels.Children.Add(titleText);
if (!string.IsNullOrEmpty(subtitle))
{
TextBlock subtitleText = Ui.Text(subtitle, 10.5, Ui.TextMuted);
subtitleText.Margin = new Thickness(0, 3, 0, 0);
labels.Children.Add(subtitleText);
}
grid.Children.Add(labels);
_track = new Border
{
Width = 40,
Height = 23,
CornerRadius = new CornerRadius(12),
Background = Ui.Brush("#35FFFFFF"),
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(12, 0, 0, 0)
};
_thumb = new Border
{
Width = 17,
Height = 17,
CornerRadius = new CornerRadius(9),
Background = Ui.TextPrimary,
HorizontalAlignment = HorizontalAlignment.Left,
Margin = new Thickness(3, 0, 0, 0)
};
_track.Child = _thumb;
Grid.SetColumn(_track, 1);
grid.Children.Add(_track);
MouseLeftButtonUp += delegate
{
IsChecked = !IsChecked;
};
}
public bool IsChecked
{
get { return _checked; }
set
{
if (_checked == value)
{
return;
}
_checked = value;
UpdateVisual();
if (CheckedChanged != null)
{
CheckedChanged(this, EventArgs.Empty);
}
}
}
public void SetCheckedSilently(bool value)
{
_checked = value;
UpdateVisual();
}
private void UpdateVisual()
{
_track.Background = _checked ? Ui.Accent : Ui.Brush("#35FFFFFF");
_thumb.Margin = _checked ? new Thickness(20, 0, 0, 0) : new Thickness(3, 0, 0, 0);
}
}
}