Skip to content

Commit

Permalink
make appearance functional
Browse files Browse the repository at this point in the history
  • Loading branch information
NoobNotFound committed Dec 1, 2024
1 parent 1055403 commit f59453a
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 17 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!--Emerald.App-->
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
<PackageVersion Include="CommunityToolkit.WinUI.Converters" Version="8.1.240916" />
<PackageVersion Include="CommunityToolkit.WinUI.Helpers" Version="8.1.240916" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Animations" Version="7.1.2" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
Expand Down
3 changes: 0 additions & 3 deletions Emerald/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
// Place the frame in the current Window
MainWindow.Content = rootFrame;
}
#if WINDOWS
var mica = Emerald.Helpers.WindowManager.IntializeWindow(MainWindow);
#endif

if (rootFrame.Content == null)
{
Expand Down
3 changes: 2 additions & 1 deletion Emerald/Emerald.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Uno.Sdk">
<Project Sdk="Uno.Sdk">
<PropertyGroup>
<TargetFrameworks>
net8.0-maccatalyst;
Expand Down Expand Up @@ -55,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
<PackageReference Include="CommunityToolkit.WinUI.Helpers" />
<PackageReference Include="Microsoft.Windows.CsWin32">
<PrivateAssets>all</PrivateAssets>
Expand Down
3 changes: 3 additions & 0 deletions Emerald/Helpers/Settings/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public partial class Appearance : JSON
private (int A, int R, int G, int B)? _CustomMicaTintColor;


[ObservableProperty]
private int _TintOpacity = 10;

public Appearance()
{
this.PropertyChanged += (_, e) =>
Expand Down
11 changes: 7 additions & 4 deletions Emerald/Helpers/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

namespace Emerald.Helpers;

#if WINDOWS
public static class WindowManager
{
/// <summary>
/// Add mica and the icon to the <paramref name="window"/>
/// </summary>
public static MicaBackground IntializeWindow(Window window)
public static MicaBackground? IntializeWindow(Window window)
{
var s = new MicaBackground(window);
#if WINDOWS
var s = new MicaBackground(window);
s.TrySetMicaBackdrop();
return s;
#endif
return null;
}

/// <summary>
Expand Down Expand Up @@ -105,6 +107,7 @@ public void EnsureWindowsSystemDispatcherQueueController()

public class MicaBackground
{
#if WINDOWS
private readonly Window _window;
public readonly MicaController MicaController = new();
private SystemBackdropConfiguration _backdropConfiguration = new();
Expand Down Expand Up @@ -171,5 +174,5 @@ private void WindowOnActivated(object sender, WindowActivatedEventArgs args)
{
_backdropConfiguration.IsInputActive = args.WindowActivationState is not WindowActivationState.Deactivated;
}
}
#endif
}
9 changes: 5 additions & 4 deletions Emerald/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:models="using:Emerald.Models"
xmlns:uc="using:Emerald.UserControls"
xmlns:SS="using:Emerald.Helpers.Settings"
xmlns:conv="using:Emerald.Helpers.Converters"
xmlns:helpers="using:Emerald.Helpers">
<Page.Resources>
<conv:BoolToVisibility x:Key="BoolToVisibilty"/>
</Page.Resources>
<Grid x:Name="MainGrid">
<uc:TitleBar
<uc:TitleBar
x:Name="AppTitleBar"
Height="48"
Margin="12,0,0,0"
Expand Down Expand Up @@ -89,20 +90,20 @@
VerticalAlignment="Top"
Content="{x:Bind InfoBadge}" />
<Image
x:Load="{x:Bind SS:SettingsSystem.Settings.App.Appearance.NavIconType.Equals(1), Mode=OneWay}"
x:Name="Image"
Width="28"
Height="28"
x:Load="{x:Bind ShowThumbnail}"
Source="{x:Bind Thumbnail}" />
<FontIcon
x:Name="fontIcon"
x:Load="{x:Bind ShowFontIcons}"
x:Load="{x:Bind SS:SettingsSystem.Settings.App.Appearance.NavIconType.Equals(0), Mode=OneWay}"
Visibility="{x:Bind FontIconVisibility}"
FontSize="22"
Glyph="{x:Bind FontIconGlyph}" />
<FontIcon
x:Name="fontIconSolid"
x:Load="{x:Bind ShowFontIcons}"
x:Load="{x:Bind SS:SettingsSystem.Settings.App.Appearance.NavIconType.Equals(0), Mode=OneWay}"
Visibility="{x:Bind SolidFontIconVisibility}"
FontSize="22"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Expand Down
62 changes: 60 additions & 2 deletions Emerald/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Emerald.Helpers;
using Emerald.Models;
using Emerald.Views.Settings;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using Windows.UI;
using SS = Emerald.Helpers.Settings.SettingsSystem;

namespace Emerald;

Expand All @@ -21,11 +24,56 @@ private void MainNavigationView_ItemInvoked(NavigationView sender, NavigationVie
itm.InvokePropertyChanged();
}
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)

void InitializeAppearance()
{
SS.Settings.App.Appearance.PropertyChanged += (s, e) =>
{
if (e.PropertyName != null)
{
TintColor();
this.GetThemeService().SetThemeAsync((AppTheme)SS.Settings.App.Appearance.Theme);
}
};
void TintColor()
{
switch ((Helpers.Settings.Enums.MicaTintColor)SS.Settings.App.Appearance.MicaTintColor)
{
case Helpers.Settings.Enums.MicaTintColor.NoColor:
MainGrid.Background = null;
break;
case Helpers.Settings.Enums.MicaTintColor.AccentColor:
MainGrid.Background = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColor"])
{
Opacity = (double)SS.Settings.App.Appearance.TintOpacity / 100
};
break;
case Helpers.Settings.Enums.MicaTintColor.CustomColor:
var c = SS.Settings.App.Appearance.CustomMicaTintColor;
MainGrid.Background = new SolidColorBrush()
{
Color = c == null ? Color.FromArgb(255, 234, 0, 94) : Color.FromArgb((byte)c.Value.A, (byte)c.Value.R, (byte)c.Value.G, (byte)c.Value.B),
Opacity = (double)SS.Settings.App.Appearance.TintOpacity / 100
};
break;
}
}
TintColor();

//Mica (Windows 11)
var mica = WindowManager.IntializeWindow(App.Current.MainWindow);
#if WINDOWS
Emerald.Helpers.WindowManager.SetTitleBar(App.Current.MainWindow, AppTitleBar);
if (mica != null)
{
mica.MicaController.Kind = (MicaKind)SS.Settings.App.Appearance.MicaType;
SS.Settings.App.Appearance.PropertyChanged += (s, e)
=> mica.MicaController.Kind = (MicaKind)SS.Settings.App.Appearance.MicaType;
}
#endif
}
void InitializeNavView()
{

NavView.MenuItems.Add(new SquareNavigationViewItem("Home".Localize())
{
FontIconGlyph = "\xE80F",
Expand Down Expand Up @@ -81,6 +129,16 @@ private void MainPage_Loaded(object sender, RoutedEventArgs e)
NavView.Header = new NavViewHeader() { HeaderText = "Home".Localize(), HeaderMargin = GetNavViewHeaderMargin() };
NavView.DisplayModeChanged += (_, _) => (NavView.Header as NavViewHeader).HeaderMargin = GetNavViewHeaderMargin();
Navigate(NavView.SelectedItem as SquareNavigationViewItem);


}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
#if WINDOWS
Emerald.Helpers.WindowManager.SetTitleBar(App.Current.MainWindow, AppTitleBar);
#endif
InitializeNavView();
InitializeAppearance();
}

private Thickness GetNavViewHeaderMargin()
Expand Down
3 changes: 3 additions & 0 deletions Emerald/Strings/en/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -757,4 +757,7 @@
<value>Invalid RAM</value>
<comment>Rarely Used</comment>
</data>
<data name="TintOpacity" xml:space="preserve">
<value>Tint opacity</value>
</data>
</root>
14 changes: 12 additions & 2 deletions Emerald/Views/Settings/AppearancePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,22 @@
</Grid>
</cn:SettingsExpander.ItemsHeader>
<cn:SettingsExpander.Items>
<cn:SettingsCard
Header="{helpers:Localize Name=CustomColors}">
<cn:SettingsCard Header="{helpers:Localize Name=CustomColors}">
<Button
Click="CustomTintColor_Click"
Content="{helpers:Localize Name=Add}" />
</cn:SettingsCard>
<cn:SettingsCard Header="{helpers:Localize Name=TintOpacity}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="6">
<Slider
Minimum="0"
Maximum="100"
SmallChange="1"
LargeChange="10"
Value="{Binding App.Appearance.TintOpacity, Mode=TwoWay}"/>
<TextBlock Text="{Binding App.Appearance.TintOpacity, Mode=OneWay}"/>
</StackPanel>
</cn:SettingsCard>
</cn:SettingsExpander.Items>
</cn:SettingsExpander>
</StackPanel>
Expand Down
2 changes: 1 addition & 1 deletion Emerald/Views/Settings/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public SettingsPage()
{
InitializeComponent();

//Loaded += (_, _) => Navigate(navView.SelectedItem as NavigationViewItem);
Loaded += (_, _) => Navigate(navView.SelectedItem as NavigationViewItem);
}

private void navView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
Expand Down

0 comments on commit f59453a

Please sign in to comment.