Skip to content

Commit a52fe67

Browse files
committed
Gamer-Style Keys and Red background with opacity
1 parent 631960e commit a52fe67

5 files changed

Lines changed: 85 additions & 26 deletions

File tree

ContextSwitch/ContextSwitch.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<EnableMsixTooling>true</EnableMsixTooling>
1414
<WindowsSDKPackageVersion>10.0.26100.38</WindowsSDKPackageVersion>
1515
</PropertyGroup>
16+
<PropertyGroup>
17+
<!--<WindowsPackageType>None</WindowsPackageType>-->
18+
</PropertyGroup>
1619
<ItemGroup>
1720
<None Remove="Assets\ContextSwitchIcon.png" />
1821
</ItemGroup>

ContextSwitch/Controls.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Microsoft.UI;
2+
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Controls;
4+
using Microsoft.UI.Xaml.Media;
5+
using System;
6+
7+
namespace ContextSwitch;
8+
9+
static class Controls
10+
{
11+
public static Border Key(string key, Thickness? margin = null)
12+
=> new()
13+
{
14+
Margin = margin ?? new(4),
15+
Padding = new(4),
16+
CornerRadius = new(4),
17+
BorderThickness = new(1),
18+
BorderBrush = new SolidColorBrush(Colors.White),
19+
Child = new TextBlock { Text = key, FontSize = 10, TextLineBounds = TextLineBounds.Tight }
20+
};
21+
public static TextBlock Text(string txt, TextLineBounds lineBounds = TextLineBounds.Full)
22+
=> new()
23+
{
24+
Text = txt,
25+
TextLineBounds = lineBounds
26+
};
27+
public static StackPanel HStack(bool center = false, params UIElement[] uIElements)
28+
{
29+
var sp = new StackPanel { Orientation = Orientation.Horizontal };
30+
foreach (var element in uIElements)
31+
{
32+
if (center && element is FrameworkElement fe)
33+
fe.VerticalAlignment = VerticalAlignment.Center;
34+
sp.Children.Add(element);
35+
}
36+
return sp;
37+
}
38+
public static StackPanel VStack(bool center = false, params UIElement[] uIElements)
39+
{
40+
var sp = new StackPanel { Orientation = Orientation.Vertical };
41+
foreach (var element in uIElements)
42+
{
43+
if (center && element is FrameworkElement fe)
44+
fe.HorizontalAlignment = HorizontalAlignment.Center;
45+
sp.Children.Add(element);
46+
}
47+
return sp;
48+
}
49+
public static T WithCustomCode<T>(this T input, Action<T> act)
50+
{
51+
act(input);
52+
return input;
53+
}
54+
}

ContextSwitch/FloatingTimer.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using Microsoft.UI.Xaml.Hosting;
1515
using System.Numerics;
1616
using Microsoft.UI.Composition;
17-
17+
using static ContextSwitch.Controls;
1818

1919
namespace ContextSwitch;
2020

@@ -180,12 +180,8 @@ void TimerCallback()
180180
lockHide = true;
181181
Content.Opacity = 1;
182182
keyReset = true;
183-
((StackPanel)Content).Children.Add(new TextBlock {
184-
FontSize = 11,
185-
Text = "Press R-CTRL to reset",
186-
TextLineBounds = TextLineBounds.Tight,
187-
VerticalAlignment = VerticalAlignment.Center
188-
});
183+
((StackPanel)Content).Children.Add(
184+
HStack(center: true, Key("R-CTRL", new(0, 0, right: 5, 0)), Text("Reset Timer", TextLineBounds.Tight)));
189185
UpdateSize();
190186
}
191187
}
@@ -198,7 +194,9 @@ void ToggleRingState()
198194
ElementSoundPlayer.State = ElementSoundPlayerState.Off;
199195
} else
200196
{
201-
background.Color = Colors.Red;
197+
Color c = Colors.Red;
198+
c.A = 255 / 2;
199+
background.Color = c;
202200
ElementSoundPlayer.Play(ElementSoundKind.Invoke);
203201
}
204202
ringTimerAbnormalState = !ringTimerAbnormalState;

ContextSwitch/MainWindow.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Windows.Globalization;
1111
using WinUIEx;
1212
using WindowApi = WinWrapper.Windowing.Window;
13+
using static ContextSwitch.Controls;
1314
namespace ContextSwitch;
1415

1516
class MainWindow : Window
@@ -44,24 +45,24 @@ void InitMain()
4445
Children =
4546
{
4647
(titlebar = new()),
47-
(main = new StackPanel
48+
(main = VStack(
49+
center: true,
50+
ContextSwitchLogo(new(0, 0, 0, 50)),
51+
Text("How long should we do work before switching tasks?"),
52+
tp = new TimePicker {
53+
MinuteIncrement = 5,
54+
ClockIdentifier = ClockIdentifiers.TwentyFourHour,
55+
SelectedTime = TimeSpan.FromMinutes(25),
56+
},
57+
btn = new Button() { Content = "Start Timer" },
58+
HStack(center: true, Text("Tip: Hold"), Key("R-CTRL"), Text("to show timer"))
59+
)
60+
.WithCustomCode(x =>
4861
{
49-
VerticalAlignment = VerticalAlignment.Center,
50-
HorizontalAlignment = HorizontalAlignment.Center,
51-
Spacing = 16,
52-
Children = {
53-
ContextSwitchLogo(new(0, 0, 0, 50)),
54-
new TextBlock { Text = "How long should we do work before switching tasks?", HorizontalAlignment = HorizontalAlignment.Center },
55-
(tp = new TimePicker {
56-
MinuteIncrement = 5,
57-
ClockIdentifier = ClockIdentifiers.TwentyFourHour,
58-
SelectedTime = TimeSpan.FromMinutes(25),
59-
HorizontalAlignment = HorizontalAlignment.Center,
60-
}),
61-
(btn = new Button() { Content = "Start Timer" , HorizontalAlignment = HorizontalAlignment.Center }),
62-
new TextBlock { Text = "Tip: Hold R-CTRL to show timer", HorizontalAlignment = HorizontalAlignment.Center }
63-
}
64-
})
62+
x.VerticalAlignment = VerticalAlignment.Center;
63+
x.HorizontalAlignment = HorizontalAlignment.Center;
64+
x.Spacing = 16;
65+
}))
6566
}
6667
};
6768
Grid.SetRow(main, 1);

ContextSwitch/Properties/launchSettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"commandName": "MsixPackage"
55
},
66
"ContextSwitch (Unpackaged)": {
7-
"commandName": "Project"
7+
"commandName": "Project",
8+
"environmentVariables": {
9+
"UNPKG": "true"
10+
}
811
}
912
}
1013
}

0 commit comments

Comments
 (0)