Skip to content

Commit 13bf8cc

Browse files
v0.2 & added background blur options
1 parent afaba28 commit 13bf8cc

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

.github/res/screenshot.png

231 KB
Loading
File renamed without changes.

UnityHubNative.Net/ControlsExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ namespace UnityHubNative.Net;
77

88
public static class ControlsExtensions
99
{
10-
public static T OnCheckChanged<T>(this T checkbox, Action value) where T : CheckBox
10+
public static T OnValueChanged<T>(this T slider, Action callback) where T : RangeBase
1111
{
12-
checkbox.IsCheckedChanged += (_, _) => value();
12+
slider.ValueChanged += (_, _) => callback();
13+
return slider;
14+
}
15+
16+
public static T OnCheckChanged<T>(this T checkbox, Action callback) where T : CheckBox
17+
{
18+
checkbox.IsCheckedChanged += (_, _) => callback();
1319
return checkbox;
1420
}
1521

UnityHubNative.Net/MainWindow.cs

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class MainWindow : Window
3333
private static CheckBox s_transparentCheckbox;
3434
private static CheckBox s_acrylicCheckbox;
3535
private static DockPanel s_transparentPanel;
36+
private static Slider s_backgroundBlurIntensitySlider;
3637

3738
public MainWindow(object data)
3839
{
@@ -97,7 +98,11 @@ void SetupBackground()
9798
];
9899
#if Windows
99100

100-
Background = Brushes.Transparent;
101+
Background = UnityHubNativeNetApp.Config.acrylic
102+
? new SolidColorBrush(
103+
ActualThemeVariant == Avalonia.Styling.ThemeVariant.Dark ? Colors.Black : Colors.White,
104+
1 - UnityHubNativeNetApp.Config.blurIntensity)
105+
: Brushes.Transparent;
101106
#endif
102107
}
103108
}
@@ -379,30 +384,72 @@ private static void ReloadEverything()
379384
]).SetTooltip("Makes the window transparent. Uses Mica on Windows and the desktop's blur on Linux.\nNeeds restart to take effect."),
380385
}.SetDock(Dock.Top).AddItems
381386
([
382-
s_transparentPanel = new DockPanel
387+
new SettingsExpanderItem
383388
{
384-
IsEnabled = UnityHubNativeNetApp.Config.transparent,
385-
LastChildFill = false,
386-
}.AddChildren
387-
([
388-
new TextBlock
389+
Content = s_transparentPanel = new DockPanel
389390
{
390-
Text = "Acrilyc",
391-
VerticalAlignment = VerticalAlignment.Center,
392-
}.SetTooltip("Use Acrylic blur. Only works on Windows.\nNeeds restart to take effect.").SetDock(Dock.Left),
393-
s_acrylicCheckbox = new CheckBox
391+
IsEnabled = UnityHubNativeNetApp.Config.transparent,
392+
LastChildFill = false,
393+
}.AddChildren
394+
([
395+
new DockPanel
396+
{
397+
LastChildFill = false
398+
}.AddChildren
399+
([
400+
new TextBlock
401+
{
402+
Text = "Acrilyc",
403+
VerticalAlignment = VerticalAlignment.Center,
404+
}.SetTooltip("Use Acrylic blur. Only works on Windows.\nNeeds restart to take effect.").SetDock(Dock.Left),
405+
s_acrylicCheckbox = new CheckBox
406+
{
407+
IsChecked = UnityHubNativeNetApp.Config.transparent,
408+
VerticalAlignment = VerticalAlignment.Center,
409+
}.OnCheckChanged(OnAcrylicCheckboxChanged).SetDock(Dock.Right),
410+
]).SetDock(Dock.Top),
411+
]),
412+
},
413+
new SettingsExpanderItem
414+
{
415+
Content = new DockPanel
394416
{
395-
IsChecked = UnityHubNativeNetApp.Config.transparent,
396-
VerticalAlignment = VerticalAlignment.Center,
397-
}.OnCheckChanged(OnAcrylicCheckboxChanged).SetDock(Dock.Right)
398-
])
417+
LastChildFill = false,
418+
IsEnabled = UnityHubNativeNetApp.Config.transparent && UnityHubNativeNetApp.Config.acrylic,
419+
}.AddChildren
420+
([
421+
new TextBlock
422+
{
423+
Text = "Background Blur Intensity",
424+
VerticalAlignment = VerticalAlignment.Center,
425+
}.SetTooltip("Changes the intensity of the background blur.").SetDock(Dock.Left),
426+
s_backgroundBlurIntensitySlider = new Slider
427+
{
428+
VerticalAlignment = VerticalAlignment.Center,
429+
Minimum = 0,
430+
Maximum = 1,
431+
Width = 100,
432+
TickFrequency = 0.1,
433+
TickPlacement = TickPlacement.BottomRight,
434+
IsSnapToTickEnabled = true,
435+
Value = UnityHubNativeNetApp.Config.blurIntensity
436+
}.OnValueChanged(OnAcrylicIntensitySliderValueChanged).SetDock(Dock.Right)
437+
]).SetDock(Dock.Top)
438+
}
399439
])
400440
])
401441
}
402442
])
403443
])
404444
]);
405445

446+
private static void OnAcrylicIntensitySliderValueChanged()
447+
{
448+
UnityHubNativeNetApp.Config.blurIntensity = (float)s_backgroundBlurIntensitySlider.Value;
449+
s_instance.SetupBackground();
450+
UnityHubNativeNetApp.SaveConfig(UnityHubNativeNetApp.Config);
451+
}
452+
406453
private static void OnAcrylicCheckboxChanged()
407454
{
408455
UnityHubNativeNetApp.Config.acrylic = !UnityHubNativeNetApp.Config.acrylic;

UnityHubNative.Net/Manifest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace UnityHubNative.Net;
22

33
static class Manifest
44
{
5-
public const string Version = "v0.1";
5+
public const string Version = "v0.2";
66
}

UnityHubNative.Net/UnityHubNativeNetApp.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ public static AppConfig LoadConfig()
4747
try
4848
{
4949
var txt = File.ReadAllLines(Paths.ConfigPath);
50-
return new()
50+
return new AppConfig()
5151
{
52-
transparent = txt[0] == "true",
53-
acrylic = txt[1] == "true",
52+
transparent = txt.Length >= 1 && txt[0] == "true",
53+
acrylic = txt.Length >= 2 && txt[1] == "true",
54+
blurIntensity = txt.Length >= 3 && float.TryParse(txt[2], out var acrylicAmount) ? acrylicAmount : 0.2f
5455
};
5556
}
5657
catch (Exception ex)
@@ -66,12 +67,14 @@ public static void SaveConfig(AppConfig config)
6667
[
6768
config.transparent ? "true" : "false",
6869
config.acrylic ? "true" : "false",
70+
config.blurIntensity.ToString(),
6971
]);
7072
}
7173

7274
public struct AppConfig
7375
{
7476
public bool transparent;
7577
public bool acrylic;
78+
public float blurIntensity;
7679
}
7780
}

0 commit comments

Comments
 (0)