diff --git a/Project_Periodensystem.View/App.axaml b/Project_Periodensystem.View/App.axaml index aa9cedb..2020807 100644 --- a/Project_Periodensystem.View/App.axaml +++ b/Project_Periodensystem.View/App.axaml @@ -1,10 +1,8 @@ - - - - - - \ No newline at end of file + RequestedThemeVariant="Light"> + + + + diff --git a/Project_Periodensystem.View/App.axaml.cs b/Project_Periodensystem.View/App.axaml.cs index e108f56..c31d742 100644 --- a/Project_Periodensystem.View/App.axaml.cs +++ b/Project_Periodensystem.View/App.axaml.cs @@ -2,22 +2,19 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -namespace Project_Periodensystem.View; - -public partial class App : Application +namespace Project_Periodensystem.View { - public override void Initialize() + public partial class App : Application { - AvaloniaXamlLoader.Load(this); - } + public override void Initialize() + => AvaloniaXamlLoader.Load(this); - public override void OnFrameworkInitializationCompleted() - { - if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + public override void OnFrameworkInitializationCompleted() { - desktop.MainWindow = new MainWindow(); - } + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + desktop.MainWindow = new MainWindow(); - base.OnFrameworkInitializationCompleted(); + base.OnFrameworkInitializationCompleted(); + } } -} \ No newline at end of file +} diff --git a/Project_Periodensystem.View/Components/ElementTile.axaml b/Project_Periodensystem.View/Components/ElementTile.axaml index 09a873b..50f2e2c 100644 --- a/Project_Periodensystem.View/Components/ElementTile.axaml +++ b/Project_Periodensystem.View/Components/ElementTile.axaml @@ -1,43 +1,42 @@ + Width="80" Height="80" + RenderTransformOrigin="0.5,0.5"> - - - - + + + + + + + + + - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + - + diff --git a/Project_Periodensystem.View/Components/ElementTile.axaml.cs b/Project_Periodensystem.View/Components/ElementTile.axaml.cs index 552c5e7..c7326ca 100644 --- a/Project_Periodensystem.View/Components/ElementTile.axaml.cs +++ b/Project_Periodensystem.View/Components/ElementTile.axaml.cs @@ -1,7 +1,8 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Input; -using Avalonia.Media; +using Avalonia.Markup.Xaml; +using Avalonia.Styling; namespace Project_Periodensystem.View.Components { @@ -19,9 +20,10 @@ namespace Project_Periodensystem.View.Components public ElementTile() { InitializeComponent(); - - // Optional: Klick per Code registrieren this.PointerPressed += (_, __) => IsFlipped = !IsFlipped; } + + private void InitializeComponent() + => AvaloniaXamlLoader.Load(this); } } diff --git a/Project_Periodensystem.View/Converters/BoolToScaleXConverter.cs b/Project_Periodensystem.View/Converters/BoolToScaleXConverter.cs index 16da2c3..6bbf753 100644 --- a/Project_Periodensystem.View/Converters/BoolToScaleXConverter.cs +++ b/Project_Periodensystem.View/Converters/BoolToScaleXConverter.cs @@ -7,14 +7,8 @@ namespace Project_Periodensystem.View.Converters public class BoolToScaleXConverter : IValueConverter { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) - { - bool flipped = value is bool b && b; - return flipped ? -1 : 1; - } - + => (value is bool b && b) ? -1 : 1; public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } + => throw new NotSupportedException(); } } diff --git a/Project_Periodensystem.View/Converters/GridPositionConverters.cs b/Project_Periodensystem.View/Converters/GridPositionConverters.cs index b98f288..1e94203 100644 --- a/Project_Periodensystem.View/Converters/GridPositionConverters.cs +++ b/Project_Periodensystem.View/Converters/GridPositionConverters.cs @@ -7,32 +7,18 @@ namespace Project_Periodensystem.View.Converters public class RowToYConverter : IValueConverter { private const double TileHeight = 80; - public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) - { - if (value is int row) - return row * TileHeight; - - return 0; - } - - public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => - throw new NotImplementedException(); + => (value is int r) ? r * TileHeight : 0; + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + => throw new NotImplementedException(); } public class ColumnToXConverter : IValueConverter { private const double TileWidth = 80; - public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) - { - if (value is int column) - return column * TileWidth; - - return 0; - } - - public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => - throw new NotImplementedException(); + => (value is int c) ? c * TileWidth : 0; + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + => throw new NotImplementedException(); } } diff --git a/Project_Periodensystem.View/Converters/SeriesToColorConverter.cs b/Project_Periodensystem.View/Converters/SeriesToColorConverter.cs index 3cfd3bb..5922497 100644 --- a/Project_Periodensystem.View/Converters/SeriesToColorConverter.cs +++ b/Project_Periodensystem.View/Converters/SeriesToColorConverter.cs @@ -10,19 +10,20 @@ namespace Project_Periodensystem.View.Converters public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string series) - return Brushes.Gray; + return new SolidColorBrush(Color.Parse("#222222")); // nocategory return series switch - { - "Nichtmetall" => Brushes.Green, - "Metall" => Brushes.DarkRed, - "Halbmetall" => Brushes.Orange, - "Edelgas" => Brushes.MediumPurple, - "Halogen" => Brushes.DeepPink, - "Lanthanoid" => Brushes.Blue, - "Actinoid" => Brushes.DarkBlue, - "Unbekannt" => Brushes.DimGray, - _ => Brushes.Black + { + "Nichtmetall" => new SolidColorBrush(Color.Parse("#3e6418")), // nonmetal + "Metall" => new SolidColorBrush(Color.Parse("#711019")), // transition + "Halbmetall" => new SolidColorBrush(Color.Parse("#015146")), // metalloid + "Edelgas" => new SolidColorBrush(Color.Parse("#3a2151")), // noble + "Halogen" => new SolidColorBrush(Color.Parse("#846011")), // alkaline (kein halogen-stil da) + "Lanthanoid" => new SolidColorBrush(Color.Parse("#402c17")), + "Actinoid" => new SolidColorBrush(Color.Parse("#732e4c")), + "Alkalimetall" => new SolidColorBrush(Color.Parse("#6c3b01")), // alkali + "Erdalkalimetall" => new SolidColorBrush(Color.Parse("#846011")), // alkaline + _ => new SolidColorBrush(Color.Parse("#222222")), // fallback: nocategory }; } diff --git a/Project_Periodensystem.View/MainWindow.axaml b/Project_Periodensystem.View/MainWindow.axaml index d3419b1..1a76923 100644 --- a/Project_Periodensystem.View/MainWindow.axaml +++ b/Project_Periodensystem.View/MainWindow.axaml @@ -1,25 +1,22 @@ + Title="Periodensystem" + Width="900" Height="650" + CanResize="True"> - - - - - - - - - - - - - - + + + + + + + + + diff --git a/Project_Periodensystem.View/MainWindow.axaml.cs b/Project_Periodensystem.View/MainWindow.axaml.cs index ba1ca40..a1eeb4d 100644 --- a/Project_Periodensystem.View/MainWindow.axaml.cs +++ b/Project_Periodensystem.View/MainWindow.axaml.cs @@ -1,26 +1,46 @@ -// Importiert die Avalonia Controls, also Basisfunktionen wie Window, Button etc. using Avalonia.Controls; - -// Importiert deinen eigenen Controller, der die Daten und Logik bereitstellt +using Avalonia.Markup.Xaml; using Project_Periodensystem.Controller; +using Project_Periodensystem.View.Components; -namespace Project_Periodensystem.View // Namespace entspricht deinem Projektordner „View“ +namespace Project_Periodensystem.View { - // Diese Klasse ist die Code-Behind-Datei für MainWindow.xaml - // Sie erweitert Avalonia's Window-Klasse public partial class MainWindow : Window { - // Der Controller verwaltet die Daten und steuert das Verhalten (MVCP-Prinzip!) - private readonly PeriodensystemController? _controller; + private readonly PeriodensystemController _controller; - // Konstruktor – wird aufgerufen, wenn das Fenster erstellt wird public MainWindow() { - InitializeComponent(); // Initialisiert die grafischen Komponenten aus XAML + InitializeComponent(); _controller = new PeriodensystemController(); - DataContext = _controller; // <-- wichtig! - // Das Fenster (und alles darin) bekommt den Controller als Datenquelle (Binding-Kontext) - // Dadurch funktionieren z.B. Bindings wie {Binding Elements} in der XAML + DataContext = _controller; + PopulateCanvas(); + } + + private void InitializeComponent() + => AvaloniaXamlLoader.Load(this); + + private void PopulateCanvas() + { + // Holt den Canvas aus dem XAML (muss existieren!) + var canvas = this.FindControl("PeriodicCanvas"); + if (canvas == null) + return; + + foreach (var element in _controller.Elements) + { + // Neues Tile für jedes Element + var tile = new ElementTile + { + DataContext = element + }; + + // Position setzen: Column × 80px, Row × 80px + Canvas.SetLeft(tile, element.Column * 80); + Canvas.SetTop(tile, element.Row * 80); + + canvas.Children.Add(tile); + } } } } diff --git a/Project_Periodensystem.View/Program.cs b/Project_Periodensystem.View/Program.cs index 7125e6c..3887d6b 100644 --- a/Project_Periodensystem.View/Program.cs +++ b/Project_Periodensystem.View/Program.cs @@ -1,21 +1,18 @@ -using Avalonia; -using System; +using System; +using Avalonia; -namespace Project_Periodensystem.View; - -class Program +namespace Project_Periodensystem.View { - // Initialization code. Don't use any Avalonia, third-party APIs or any - // SynchronizationContext-reliant code before AppMain is called: things aren't initialized - // yet and stuff might break. - [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); + class Program + { + [STAThread] + public static void Main(string[] args) + => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); - // Avalonia configuration, don't remove; also used by visual designer. - public static AppBuilder BuildAvaloniaApp() - => AppBuilder.Configure() - .UsePlatformDetect() - .WithInterFont() - .LogToTrace(); + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .LogToTrace(); + } }