Skip to content

Commit

Permalink
Add DesktopAcrylic Kind (Base, Thin)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Sep 9, 2023
1 parent 46137e8 commit 97afe68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void createCustomMicaWindow_Click(object sender, RoutedEventArgs e)
private void createBuiltInAcrylicWindow_Click(object sender, RoutedEventArgs e)
{
var newWindow = new AppUIBasics.SamplePages.SampleSystemBackdropsWindow();
newWindow.SetBackdrop(AppUIBasics.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylic);
newWindow.SetBackdrop(AppUIBasics.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylicBase);
newWindow.Activate();
}
}
Expand Down
38 changes: 28 additions & 10 deletions WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public enum BackdropType
{
Mica,
MicaAlt,
DesktopAcrylic,
DesktopAcrylicBase,
DesktopAcrylicThin,
DefaultColor,
}

Expand Down Expand Up @@ -112,7 +113,7 @@ public void SetBackdrop(BackdropType type)
else
{
// Mica isn't supported. Try Acrylic.
type = BackdropType.DesktopAcrylic;
type = BackdropType.DesktopAcrylicBase;
tbChangeStatus.Text += " Mica isn't supported. Trying Acrylic.";
}
}
Expand All @@ -126,23 +127,37 @@ public void SetBackdrop(BackdropType type)
else
{
// MicaAlt isn't supported. Try Acrylic.
type = BackdropType.DesktopAcrylic;
type = BackdropType.DesktopAcrylicBase;
tbChangeStatus.Text += " MicaAlt isn't supported. Trying Acrylic.";
}
}
if (type == BackdropType.DesktopAcrylic)
if (type == BackdropType.DesktopAcrylicBase)
{
if (TrySetAcrylicBackdrop())
if (TrySetAcrylicBackdrop(false))
{
tbCurrentBackdrop.Text = "Custom Acrylic";
tbCurrentBackdrop.Text = "Custom Acrylic (Base)";
m_currentBackdrop = type;
}
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic isn't supported. Switching to default color.";
tbChangeStatus.Text += " Acrylic Base isn't supported. Switching to default color.";
}
}
if (type == BackdropType.DesktopAcrylicThin)
{
if (TrySetAcrylicBackdrop(true))
{
tbCurrentBackdrop.Text = "Custom Acrylic (Thin)";
m_currentBackdrop = type;
}
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic Thin isn't supported. Switching to default color.";
}
}

// announce visual change to automation
UIHelper.AnnounceActionForAccessibility(btnChangeBackdrop, $"Background changed to {tbCurrentBackdrop.Text}", "BackgroundChangedNotificationActivityId");
}
Expand Down Expand Up @@ -175,7 +190,7 @@ bool TrySetMicaBackdrop(bool useMicaAlt)
return false; // Mica is not supported on this system.
}

bool TrySetAcrylicBackdrop()
bool TrySetAcrylicBackdrop(bool useAcrylicThin)
{
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
{
Expand All @@ -191,6 +206,8 @@ bool TrySetAcrylicBackdrop()

m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();

m_acrylicController.Kind = useAcrylicThin ? Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin : Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
Expand Down Expand Up @@ -248,8 +265,9 @@ void ChangeBackdropButton_Click(object sender, RoutedEventArgs e)
switch (m_currentBackdrop)
{
case BackdropType.Mica: newType = BackdropType.MicaAlt; break;
case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylic; break;
case BackdropType.DesktopAcrylic: newType = BackdropType.DefaultColor; break;
case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylicBase; break;
case BackdropType.DesktopAcrylicBase: newType = BackdropType.DesktopAcrylicThin; break;
case BackdropType.DesktopAcrylicThin: newType = BackdropType.DefaultColor; break;
default:
case BackdropType.DefaultColor: newType = BackdropType.Mica; break;
}
Expand Down

0 comments on commit 97afe68

Please sign in to comment.