From 90fd8ab3752d740c529da03138a66196793f3546 Mon Sep 17 00:00:00 2001 From: Ano-sys Date: Thu, 5 Feb 2026 16:49:49 +0100 Subject: [PATCH] Added Light and Dark Themes, switchable via Button in the bottom right --- DelaunayTriangulation/App.axaml | 11 ++- .../Themes/ColorPalette.axaml | 90 +++++++++++++++++++ DelaunayTriangulation/Themes/Styles.axaml | 34 +++++++ .../ViewModels/MainWindowViewModel.cs | 24 +++++ DelaunayTriangulation/Views/MainWindow.axaml | 64 ++++++------- 5 files changed, 191 insertions(+), 32 deletions(-) create mode 100644 DelaunayTriangulation/Themes/ColorPalette.axaml create mode 100644 DelaunayTriangulation/Themes/Styles.axaml diff --git a/DelaunayTriangulation/App.axaml b/DelaunayTriangulation/App.axaml index b55681b..863c64d 100644 --- a/DelaunayTriangulation/App.axaml +++ b/DelaunayTriangulation/App.axaml @@ -2,14 +2,23 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="DelaunayTriangulation.App" xmlns:local="using:DelaunayTriangulation" - RequestedThemeVariant="Default"> + RequestedThemeVariant="Dark"> + + + + + + + + + \ No newline at end of file diff --git a/DelaunayTriangulation/Themes/ColorPalette.axaml b/DelaunayTriangulation/Themes/ColorPalette.axaml new file mode 100644 index 0000000..dda8976 --- /dev/null +++ b/DelaunayTriangulation/Themes/ColorPalette.axaml @@ -0,0 +1,90 @@ + + + + + + + #FFF6F7F9 + #FFFFFFFF + #FF111827 + #FF6B7280 + #FFE5E7EB + #FF2563EB + #FFDC2626 + + #14000000 + #33000000 + #66FFFFFF + #33000000 + + #FF16A34A + #FF6D28D9 + #FFEA580C + #FF2563EB + #FF111827 + + + + + + + + + + + + + + + + + + + + + + + + #FF0B1220 + #FF111A2E + #FFE5E7EB + #FF9CA3AF + #FF263248 + #FF60A5FA + #FFFB7185 + + #30000000 + #20FFFFFF + #DD000000 + #AA000000 + + #FFADFF2F + #FF8A2BE2 + #FFFF8C00 + #FF6495ED + #FFFFFFFF + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DelaunayTriangulation/Themes/Styles.axaml b/DelaunayTriangulation/Themes/Styles.axaml new file mode 100644 index 0000000..5f24a43 --- /dev/null +++ b/DelaunayTriangulation/Themes/Styles.axaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/DelaunayTriangulation/ViewModels/MainWindowViewModel.cs b/DelaunayTriangulation/ViewModels/MainWindowViewModel.cs index 1a61e94..63cac3c 100644 --- a/DelaunayTriangulation/ViewModels/MainWindowViewModel.cs +++ b/DelaunayTriangulation/ViewModels/MainWindowViewModel.cs @@ -6,8 +6,10 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Avalonia; using Avalonia.Media; using Avalonia.Rendering.Composition.Animations; +using Avalonia.Styling; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using DelaunatorSharp; @@ -42,6 +44,11 @@ public partial class MainWindowViewModel : ViewModelBase [ObservableProperty] private bool _isGenerationRunning = false; + [ObservableProperty] private string _switchThemeBtnContent = StandardDarkIcon; + + private const string StandardLightIcon = "\ud83c\udf1e"; + private const string StandardDarkIcon = "\ud83c\udf1a"; + public double Width { get; set; } = 1280; public double Height { get; set; } = 720; @@ -56,6 +63,21 @@ public partial class MainWindowViewModel : ViewModelBase public IAsyncRelayCommand GenerateCommand { get; } + [RelayCommand] + private void SwitchTheme() + { + if(Application.Current!.ActualThemeVariant == ThemeVariant.Light) + { + Application.Current!.RequestedThemeVariant = ThemeVariant.Dark; + SwitchThemeBtnContent = StandardDarkIcon; + } + else + { + Application.Current!.RequestedThemeVariant = ThemeVariant.Light; + SwitchThemeBtnContent = StandardLightIcon; + } + } + // gets distance of a and b edge to calc hypotenuse aka dist of two points double PointDistance(Geometries.Point p1, Geometries.Point p2) => Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)); @@ -102,6 +124,8 @@ public partial class MainWindowViewModel : ViewModelBase async Task GenerateRandomPoints(int count, CancellationToken ct) { + if (PointCount == null) return; + bool CheckAdd(Geometries.Point p1, IList p) => !p.Any(x => PointDistance(p1, x) <= MinPointDistance); diff --git a/DelaunayTriangulation/Views/MainWindow.axaml b/DelaunayTriangulation/Views/MainWindow.axaml index 4f60765..0574b82 100644 --- a/DelaunayTriangulation/Views/MainWindow.axaml +++ b/DelaunayTriangulation/Views/MainWindow.axaml @@ -19,6 +19,7 @@ Height="{Binding Height, Mode=TwoWay}" MinWidth="1200" MinHeight="700" + > @@ -34,8 +35,8 @@