Browse Source

Added generic enum property view

CPKreuz 1 year ago
parent
commit
e59ec8032f

+ 5 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Nodes/NodePropertyViewModel.cs

@@ -128,6 +128,11 @@ internal abstract class NodePropertyViewModel : ViewModelBase, INodePropertyHand
         Type viewModelType = Type.GetType($"PixiEditor.AvaloniaUI.ViewModels.Nodes.Properties.{name}");
         if (viewModelType == null)
         {
+            if (propertyType.IsEnum)
+            {
+                return new GenericEnumPropertyViewModel(node, type, propertyType);
+            }
+            
             return new GenericPropertyViewModel(node, type);
         }
         

+ 13 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Nodes/Properties/GenericEnumPropertyViewModel.cs

@@ -0,0 +1,13 @@
+using PixiEditor.AvaloniaUI.Models.Handlers;
+
+namespace PixiEditor.AvaloniaUI.ViewModels.Nodes.Properties;
+
+internal class GenericEnumPropertyViewModel : NodePropertyViewModel
+{
+    public GenericEnumPropertyViewModel(INodeHandler node, Type propertyType, Type enumType) : base(node, propertyType)
+    {
+        Values = Enum.GetValues(enumType);
+    }
+
+    public Array Values { get; }
+}

+ 16 - 0
src/PixiEditor.AvaloniaUI/Views/Nodes/Properties/GenericEnumPropertyView.axaml

@@ -0,0 +1,16 @@
+<properties:NodePropertyView xmlns="https://github.com/avaloniaui"
+                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+                             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                             xmlns:properties="clr-namespace:PixiEditor.AvaloniaUI.Views.Nodes.Properties"
+                             xmlns:input="clr-namespace:PixiEditor.AvaloniaUI.Views.Input"
+                             xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
+                             xmlns:converters="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Converters"
+                             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+                             x:Class="PixiEditor.AvaloniaUI.Views.Nodes.Properties.GenericEnumPropertyView">
+    <Grid HorizontalAlignment="{Binding IsInput, Converter={converters:BoolToValueConverter FalseValue='Right', TrueValue='Stretch'}}">
+        <TextBlock VerticalAlignment="Center" ui:Translator.Key="{Binding DisplayName}"/>
+        <ComboBox HorizontalAlignment="Right" MinWidth="100" IsVisible="{Binding IsInput}"
+                  SelectedValue="{Binding Value, Mode=TwoWay}" ItemsSource="{Binding Values}" />
+    </Grid>
+</properties:NodePropertyView>

+ 13 - 0
src/PixiEditor.AvaloniaUI/Views/Nodes/Properties/GenericEnumPropertyView.axaml.cs

@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace PixiEditor.AvaloniaUI.Views.Nodes.Properties;
+
+public partial class GenericEnumPropertyView : NodePropertyView
+{
+    public GenericEnumPropertyView()
+    {
+        InitializeComponent();
+    }
+}