Skip to content

Commit

Permalink
convert appearance page.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoobNotFound committed Dec 1, 2024
1 parent 382774c commit 1055403
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Emerald/DirectResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Emerald;
public static class DirectResoucres
{
public static int MaxRAM
=> Extensions.GetMemoryGB() * 1024;
=> (Extensions.GetMemoryGB() ?? 192) * 1024; //switches maximum ram if failed, I couldn't find the max ram for MC.

public static int MinRAM
=> 512;
Expand Down
7 changes: 6 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 @@ -49,6 +49,7 @@
<None Remove="Assets\icon.png" />
<None Remove="UserControls\ArgumentsListView.xaml" />
<None Remove="UserControls\Titlebar.xaml" />
<None Remove="Views\Settings\AppearancePage.xaml" />
<None Remove="Views\Settings\GeneralPage.xaml" />
<None Remove="Views\Settings\SettingsPage.xaml" />
</ItemGroup>
Expand Down Expand Up @@ -90,4 +91,8 @@
<UpToDateCheckInput Remove="UserControls\ArgumentsListView.xaml" />
</ItemGroup>

<ItemGroup>
<UpToDateCheckInput Remove="Views\Settings\AppearancePage.xaml" />
</ItemGroup>

</Project>
48 changes: 30 additions & 18 deletions Emerald/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ public static class Extensions
// }
//}

public static int GetMemoryGB()
public static int? GetMemoryGB()
{
SystemMemoryUsageReport systemMemoryUsageReport = SystemDiagnosticInfo.GetForCurrentSystem().MemoryUsage.GetReport();
SystemMemoryUsageReport? systemMemoryUsageReport = SystemDiagnosticInfo.GetForCurrentSystem()?.MemoryUsage?.GetReport();

long memkb = Convert.ToInt64(systemMemoryUsageReport.TotalPhysicalSizeInBytes);
return Convert.ToInt32(memkb / Math.Pow(1024, 3));
try
{
long memkb = Convert.ToInt64(systemMemoryUsageReport?.TotalPhysicalSizeInBytes);
return Convert.ToInt32(memkb / Math.Pow(1024, 3));
}
catch
{

return null;
}
}

public static string KiloFormat(this int num)
Expand All @@ -56,20 +64,24 @@ public static string KiloFormat(this int num)
return num.ToString("#,0");
}

//public static ContentDialog ToContentDialog(this UIElement content, string title, string closebtnText = null, ContentDialogButton defaultButton = ContentDialogButton.Close)
//{
// ContentDialog dialog = new()
// {
// XamlRoot = App.Current.MainWindow.Content.XamlRoot,
// Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
// Title = title,
// CloseButtonText = closebtnText,
// DefaultButton = defaultButton,
// Content = content,
// RequestedTheme = (ElementTheme)Settings.SettingsSystem.Settings.App.Appearance.Theme
// };
// return dialog;
//}
public static ContentDialog ToContentDialog(this UIElement content, string title, string closebtnText = null, ContentDialogButton defaultButton = ContentDialogButton.Close, bool addScrollBar = true)
{
ContentDialog dialog = new()
{
XamlRoot = App.Current.MainWindow.Content.XamlRoot,
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
Title = title,
CloseButtonText = closebtnText,
DefaultButton = defaultButton,
Content = addScrollBar ? new ScrollViewer()
{
Content = content,
Padding = new(12)
} : content,
RequestedTheme = (ElementTheme)Settings.SettingsSystem.Settings.App.Appearance.Theme
};
return dialog;
}

public static int Remove<T>(this ObservableCollection<T> coll, Func<T, bool> condition)
{
Expand Down
116 changes: 116 additions & 0 deletions Emerald/Views/Settings/AppearancePage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<Page
x:Class="Emerald.Views.Settings.AppearancePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Emerald.Views.Settings" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:Main="using:Emerald" xmlns:SS="using:Emerald.Helpers.Settings" xmlns:helpers="using:Emerald.Helpers"
DataContext="{x:Bind SS:SettingsSystem.Settings}" xmlns:cn="using:CommunityToolkit.WinUI.Controls" xmlns:uc="using:Emerald.UserControls" xmlns:windowsui="using:Windows.UI">
<Grid
Margin="16">
<StackPanel
Spacing="4">
<cn:SettingsCard
Header="{helpers:Localize Name=ColorMode}"
Description="{helpers:Localize Name=ColorModeDescription}"
HeaderIcon="{helpers:FontIcon Glyph=}">
<ComboBox
SelectedIndex="{Binding App.Appearance.Theme, Mode=TwoWay}">
<ComboBoxItem
Content="{helpers:Localize Name=SystemDefault}" />
<ComboBoxItem
Content="{helpers:Localize Name=Light}" />
<ComboBoxItem
Content="{helpers:Localize Name=Dark}" />
</ComboBox>
</cn:SettingsCard>
<cn:SettingsCard
Header="{helpers:Localize Name=MicaType}"
Description="{helpers:Localize Name=MicaTypeDescription}"
HeaderIcon="{helpers:FontIcon Glyph=}">
<ComboBox
SelectedIndex="{Binding App.Appearance.MicaType, Mode=TwoWay}">
<ComboBoxItem
Content="Mica" />
<ComboBoxItem
Content="Mica Alt" />
</ComboBox>
</cn:SettingsCard>
<cn:SettingsCard
Header="{helpers:Localize Name=NavIconStyle}"
Description="{helpers:Localize Name=NavIconStyleDescription}"
HeaderIcon="{helpers:FontIcon Glyph=}">
<ComboBox
SelectedIndex="{Binding App.Appearance.NavIconType, Mode=TwoWay}">
<ComboBoxItem
Content="{helpers:Localize Name=Default}" />
<ComboBoxItem
Content="{helpers:Localize Name=Colorful}" />
</ComboBox>
</cn:SettingsCard>
<cn:SettingsExpander
IsExpanded="True"
Header="{helpers:Localize Name=WindowTintColor}"
Description="{helpers:Localize Name=WindowTintColorDescription}"
HeaderIcon="{helpers:FontIcon Glyph=}">
<cn:SettingsExpander.Content>
<ComboBox
SelectedIndex="{Binding App.Appearance.MicaTintColor, Mode=TwoWay}">
<ComboBoxItem
Content="{helpers:Localize Name=NoColor}" />
<ComboBoxItem
Content="{helpers:Localize Name=AccentColor}" />
<ComboBoxItem
Content="{helpers:Localize Name=CustomColor}" />
</ComboBox>
</cn:SettingsExpander.Content>
<cn:SettingsExpander.ItemsHeader>
<Grid
Padding="12"
Background="{StaticResource ExpanderHeaderBackground}">
<GridView
DataContext="{x:Bind}"
x:Name="GVColorList"
ItemsSource="{x:Bind TintColorsList}"
SelectionChanged="GVColorList_SelectionChanged"
SelectionMode="Single">
<GridView.ItemContainerStyle>
<Style
TargetType="GridViewItem">
<Setter
Property="Margin"
Value="2" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid
MaximumRowsOrColumns="12"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate
x:DataType="windowsui:Color">
<Border
Width="48"
Height="48"
CornerRadius="6">
<Border.Background>
<SolidColorBrush
Color="{x:Bind}" />
</Border.Background>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</cn:SettingsExpander.ItemsHeader>
<cn:SettingsExpander.Items>
<cn:SettingsCard
Header="{helpers:Localize Name=CustomColors}">
<Button
Click="CustomTintColor_Click"
Content="{helpers:Localize Name=Add}" />
</cn:SettingsCard>
</cn:SettingsExpander.Items>
</cn:SettingsExpander>
</StackPanel>
</Grid>
</Page>
147 changes: 147 additions & 0 deletions Emerald/Views/Settings/AppearancePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Emerald.Helpers;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using SS = Emerald.Helpers.Settings.SettingsSystem;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Emerald.Views.Settings;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AppearancePage : Page
{

public ObservableCollection<Color> TintColorsList { get; } = new()
{
Color.FromArgb(255, 255, 185, 0),
Color.FromArgb(255, 255, 140, 0),
Color.FromArgb(255, 247, 99, 12),
Color.FromArgb(255, 202, 80, 16),
Color.FromArgb(255, 218, 59, 1),
Color.FromArgb(255, 239, 105, 80),
Color.FromArgb(255, 209, 52, 56),
Color.FromArgb(255, 255, 67, 67),
Color.FromArgb(255, 231, 72, 86),
Color.FromArgb(255, 232, 17, 35),
Color.FromArgb(255, 234, 0, 94),
Color.FromArgb(255, 195, 0, 82),
Color.FromArgb(255, 227, 0, 140),
Color.FromArgb(255, 191, 0, 119),
Color.FromArgb(255, 194, 57, 179),
Color.FromArgb(255, 154, 0, 137),
Color.FromArgb(255, 0, 120, 212),
Color.FromArgb(255, 0, 99, 177),
Color.FromArgb(255, 142, 140, 216),
Color.FromArgb(255, 107, 105, 214),
Color.FromArgb(255, 135, 100, 184),
Color.FromArgb(255, 116, 77, 169),
Color.FromArgb(255, 177, 70, 194),
Color.FromArgb(255, 136, 23, 152),
Color.FromArgb(255, 0, 153, 188),
Color.FromArgb(255, 45, 125, 154),
Color.FromArgb(255, 0, 183, 195),
Color.FromArgb(255, 3, 131, 135),
Color.FromArgb(255, 0, 178, 148),
Color.FromArgb(255, 1, 133, 116),
Color.FromArgb(255, 0, 204, 106),
Color.FromArgb(255, 16, 137, 62),
Color.FromArgb(255, 122, 117, 116),
Color.FromArgb(255, 93, 90, 88),
Color.FromArgb(255, 104, 118, 138),
Color.FromArgb(255, 81, 92, 107),
Color.FromArgb(255, 86, 124, 115),
Color.FromArgb(255, 72, 104, 96),
Color.FromArgb(255, 73, 130, 5),
Color.FromArgb(255, 16, 124, 16),
Color.FromArgb(255, 118, 118, 118),
Color.FromArgb(255, 76, 74, 72),
Color.FromArgb(255, 105, 121, 126),
Color.FromArgb(255, 74, 84, 89),
Color.FromArgb(255, 100, 124, 100),
Color.FromArgb(255, 82, 94, 84),
Color.FromArgb(255, 132, 117, 69),
Color.FromArgb(255, 126, 115, 95)
};

public AppearancePage()
{
InitializeComponent();

if (SS.Settings.App.Appearance.MicaTintColor == (int)Helpers.Settings.Enums.MicaTintColor.CustomColor)
{
if (SS.Settings.App.Appearance.CustomMicaTintColor != null)
{
var c = SS.Settings.App.Appearance.CustomMicaTintColor;
var cl = Color.FromArgb((byte)c.Value.A, (byte)c.Value.R, (byte)c.Value.G, (byte)c.Value.B);

if (TintColorsList.Contains(cl))
GVColorList.SelectedIndex = TintColorsList.IndexOf(cl);
else
{
TintColorsList.Add(cl);
GVColorList.SelectedIndex = TintColorsList.Count - 1;
}
}
}
}

private void GVColorList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var c = TintColorsList[GVColorList.SelectedIndex];

SS.Settings.App.Appearance.MicaTintColor = (int)Helpers.Settings.Enums.MicaTintColor.CustomColor;
SS.Settings.App.Appearance.CustomMicaTintColor = (c.A, c.R, c.G, c.B);
}

private void CustomTintColor_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
var c = SS.Settings.App.Appearance.CustomMicaTintColor;
var cp = new ColorPicker()
{
ColorSpectrumShape = ColorSpectrumShape.Box,
IsMoreButtonVisible = false,
IsColorSliderVisible = true,
IsColorChannelTextInputVisible = true,
IsHexInputVisible = true,
IsAlphaEnabled = true,
IsAlphaSliderVisible = true,
IsAlphaTextInputVisible = false,
Color = Color.FromArgb((byte)(c?.A ?? 0), (byte)(c?.R ?? 0), (byte)(c?.G ?? 0), (byte)(c?.B ?? 0))
};

var d = cp.ToContentDialog("CreateAColor".Localize(), "Cancel".Localize(), ContentDialogButton.Primary);

d.PrimaryButtonText = "OK".Localize();

d.PrimaryButtonClick += (_, _) =>
{
var cl = cp.Color;
if (TintColorsList.Contains(cl))
{
GVColorList.SelectedIndex = TintColorsList.IndexOf(cl);
}
else
{
TintColorsList.Add(cl);
GVColorList.SelectedIndex = TintColorsList.Count - 1;
}
};

_ = d.ShowAsync();
}
}
2 changes: 1 addition & 1 deletion Emerald/Views/Settings/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private void Navigate(NavigationViewItem itm)
switch (itm.Tag)
{
case "Appearance":
NavigateOnce(typeof(SettingsPage));
NavigateOnce(typeof(AppearancePage));
break;
case "About":
NavigateOnce(typeof(SettingsPage));
Expand Down

0 comments on commit 1055403

Please sign in to comment.