Răsfoiți Sursa

Added editor for float inputs

Krzysztof Krysiński 2 luni în urmă
părinte
comite
ce6452d5f4

+ 3 - 0
src/PixiEditor/ViewLocator.cs

@@ -4,9 +4,11 @@ using Avalonia.Controls.Templates;
 using CommunityToolkit.Mvvm.ComponentModel;
 using PixiDocks.Core.Docking;
 using PixiEditor.ViewModels.Dock;
+using PixiEditor.ViewModels.Nodes.Properties;
 using PixiEditor.ViewModels.SubViewModels;
 using PixiEditor.Views.Dock;
 using PixiEditor.Views.Layers;
+using PixiEditor.Views.Nodes.Properties;
 
 namespace PixiEditor;
 
@@ -17,6 +19,7 @@ public class ViewLocator : IDataTemplate
         [typeof(ViewportWindowViewModel)] = typeof(DocumentTemplate),
         [typeof(LazyViewportWindowViewModel)] = typeof(LazyDocumentTemplate),
         [typeof(LayersDockViewModel)] = typeof(LayersManager),
+        [typeof(SinglePropertyViewModel)] = typeof(DoublePropertyView),
     };
 
     public Control Build(object? data)

+ 3 - 1
src/PixiEditor/ViewModels/Nodes/NodePropertyViewModel.cs

@@ -179,7 +179,9 @@ internal abstract class NodePropertyViewModel : ViewModelBase, INodePropertyHand
             propertyType = type.GetMethod("Invoke").ReturnType.BaseType.GenericTypeArguments[0];
         }
 
-        string name = $"{propertyType.Name}PropertyViewModel";
+        string typeName = propertyType.Name;
+
+        string name = $"{typeName}PropertyViewModel";
 
         Type viewModelType = Type.GetType($"PixiEditor.ViewModels.Nodes.Properties.{name}");
         if (viewModelType == null)

+ 59 - 0
src/PixiEditor/ViewModels/Nodes/Properties/SinglePropertyViewModel.cs

@@ -0,0 +1,59 @@
+using System.ComponentModel;
+using Avalonia;
+using Avalonia.Media;
+using CommunityToolkit.Mvvm.ComponentModel;
+
+namespace PixiEditor.ViewModels.Nodes.Properties;
+
+internal class SinglePropertyViewModel : NodePropertyViewModel<float>
+{
+    private double min = double.MinValue;
+    private double max = double.MaxValue;
+
+    private NumberPickerMode numberPickerMode = NumberPickerMode.NumberInput;
+
+    private SliderSettings sliderSettings = new SliderSettings();
+
+    public NumberPickerMode NumberPickerMode
+    {
+        get => numberPickerMode;
+        set => SetProperty(ref numberPickerMode, value);
+    }
+
+    public double DoubleValue
+    {
+        get => Value;
+        set => Value = (float)value;
+    }
+
+    public double Min
+    {
+        get => min;
+        set => SetProperty(ref min, value);
+    }
+
+    public double Max
+    {
+        get => max;
+        set => SetProperty(ref max, value);
+    }
+
+    public SliderSettings SliderSettings
+    {
+        get => sliderSettings;
+        set => SetProperty(ref sliderSettings, value);
+    }
+
+    public SinglePropertyViewModel(NodeViewModel node, Type valueType) : base(node, valueType)
+    {
+    }
+
+    protected override void OnPropertyChanged(PropertyChangedEventArgs e)
+    {
+        base.OnPropertyChanged(e);
+        if (e.PropertyName == nameof(Value))
+        {
+            OnPropertyChanged(nameof(DoubleValue));
+        }
+    }
+}