From f89e7d43fe63338f712bcf70553ac7629ed8255e Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 18 Jun 2022 11:45:41 +0200 Subject: [PATCH] Property input - Implemented remaining properties --- src/.idea/.idea.Artemis/.idea/avalonia.xml | 3 ++ .../FloatPropertyInputView.axaml | 4 +-- .../FloatPropertyInputViewModel.cs | 14 ++++---- .../FloatRangePropertyInputView.axaml | 35 +++++++++++++++++-- .../FloatRangePropertyInputView.axaml.cs | 12 +++++++ .../FloatRangePropertyInputViewModel.cs | 16 ++++----- .../PropertyInput/IntPropertyInputView.axaml | 4 +-- .../IntPropertyInputViewModel.cs | 14 ++++---- .../IntRangePropertyInputView.axaml | 35 +++++++++++++++++-- .../IntRangePropertyInputView.axaml.cs | 12 +++++++ .../IntRangePropertyInputViewModel.cs | 14 ++++---- .../SKPointPropertyInputView.axaml | 4 +++ .../SKPointPropertyInputViewModel.cs | 16 ++++----- .../SKSizePropertyInputView.axaml | 4 +++ .../SKSizePropertyInputViewModel.cs | 17 ++++----- 15 files changed, 147 insertions(+), 57 deletions(-) diff --git a/src/.idea/.idea.Artemis/.idea/avalonia.xml b/src/.idea/.idea.Artemis/.idea/avalonia.xml index a58199850..4aa1c9d1b 100644 --- a/src/.idea/.idea.Artemis/.idea/avalonia.xml +++ b/src/.idea/.idea.Artemis/.idea/avalonia.xml @@ -23,7 +23,10 @@ + + + diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputView.axaml b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputView.axaml index 19521c951..25a273cf3 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputView.axaml +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputView.axaml @@ -15,8 +15,8 @@ Value="{CompiledBinding InputValue}" Prefix="{CompiledBinding Prefix}" Suffix="{CompiledBinding Affix}" - Minimum="{CompiledBinding MinInputValue}" - Maximum="{CompiledBinding MaxInputValue}" + Minimum="{CompiledBinding Min}" + Maximum="{CompiledBinding Max}" LargeChange="{Binding LayerProperty.PropertyDescription.InputStepSize}" SimpleNumberFormat="F3" VerticalAlignment="Center" diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputViewModel.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputViewModel.cs index d648eebf6..6b22572d6 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputViewModel.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatPropertyInputViewModel.cs @@ -13,19 +13,17 @@ public class FloatPropertyInputViewModel : PropertyInputViewModel { if (LayerProperty.PropertyDescription.MinInputValue.IsNumber()) { - float minInputValue = Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue); - this.ValidationRule(vm => vm.InputValue, i => i >= minInputValue, $"Value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - MinInputValue = minInputValue; + Min = Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.InputValue, i => i >= Min, $"Value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - float maxInputValue = Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue); - this.ValidationRule(vm => vm.InputValue, i => i <= maxInputValue, $"Value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - MaxInputValue = maxInputValue; + Max = Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.InputValue, i => i <= Max, $"Value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } - public float MinInputValue { get; } = float.MinValue; - public float MaxInputValue { get; } = float.MaxValue; + public float Min { get; } = float.MinValue; + public float Max { get; } = float.MaxValue; } \ No newline at end of file diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml index 2db8defef..07d3faeab 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml @@ -2,7 +2,38 @@ 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:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared" + xmlns:propertyInput="clr-namespace:Artemis.UI.DefaultTypes.PropertyInput" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Artemis.UI.DefaultTypes.PropertyInput.FloatRangePropertyInputView"> - TODO + x:Class="Artemis.UI.DefaultTypes.PropertyInput.FloatRangePropertyInputView" + x:DataType="propertyInput:FloatRangePropertyInputViewModel"> + + + - + + diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml.cs index 4602aad94..ed446c2f8 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputView.axaml.cs @@ -1,3 +1,5 @@ +using System; +using Artemis.UI.Shared.Controls; using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; @@ -16,5 +18,15 @@ namespace Artemis.UI.DefaultTypes.PropertyInput { AvaloniaXamlLoader.Load(this); } + + private void DraggableNumberBox_OnDragStarted(DraggableNumberBox sender, EventArgs args) + { + ViewModel?.StartPreview(); + } + + private void DraggableNumberBox_OnDragFinished(DraggableNumberBox sender, EventArgs args) + { + ViewModel?.ApplyPreview(); + } } } diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputViewModel.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputViewModel.cs index 2bfbbb04e..52fb5ad67 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputViewModel.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/FloatRangePropertyInputViewModel.cs @@ -17,18 +17,14 @@ public class FloatRangePropertyInputViewModel : PropertyInputViewModel vm.Start, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"Start value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - this.ValidationRule(vm => vm.End, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"End value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + Min = Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.Start, i => i >= Min, $"Start value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - this.ValidationRule(vm => vm.Start, i => i < Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"Start value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - this.ValidationRule(vm => vm.End, i => i < Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"End value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + Max = Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.End, i => i < Max, $"End value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } @@ -59,7 +55,9 @@ public class FloatRangePropertyInputViewModel : PropertyInputViewModel { if (LayerProperty.PropertyDescription.MinInputValue.IsNumber()) { - int minInputValue = Convert.ToInt32(LayerProperty.PropertyDescription.MinInputValue); - this.ValidationRule(vm => vm.InputValue, i => i >= minInputValue, $"Value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - MinInputValue = minInputValue; + Min = Convert.ToInt32(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.InputValue, i => i >= Min, $"Value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - int maxInputValue = Convert.ToInt32(LayerProperty.PropertyDescription.MaxInputValue); - this.ValidationRule(vm => vm.InputValue, i => i < maxInputValue, $"Value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - MaxInputValue = maxInputValue; + Max = Convert.ToInt32(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.InputValue, i => i < Max, $"Value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } - public int MinInputValue { get; } = int.MinValue; - public int MaxInputValue { get; } = int.MaxValue; + public int Min { get; } = int.MinValue; + public int Max { get; } = int.MaxValue; } \ No newline at end of file diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml index 51785b5fe..512006830 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml @@ -2,7 +2,38 @@ 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:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared" + xmlns:propertyInput="clr-namespace:Artemis.UI.DefaultTypes.PropertyInput" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Artemis.UI.DefaultTypes.PropertyInput.IntRangePropertyInputView"> - TODO + x:Class="Artemis.UI.DefaultTypes.PropertyInput.IntRangePropertyInputView" + x:DataType="propertyInput:IntRangePropertyInputViewModel"> + + + - + + diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml.cs index 841670b58..4f51c4386 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputView.axaml.cs @@ -1,3 +1,5 @@ +using System; +using Artemis.UI.Shared.Controls; using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; @@ -16,5 +18,15 @@ namespace Artemis.UI.DefaultTypes.PropertyInput { AvaloniaXamlLoader.Load(this); } + + private void DraggableNumberBox_OnDragStarted(DraggableNumberBox sender, EventArgs args) + { + ViewModel?.StartPreview(); + } + + private void DraggableNumberBox_OnDragFinished(DraggableNumberBox sender, EventArgs args) + { + ViewModel?.ApplyPreview(); + } } } diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputViewModel.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputViewModel.cs index 9fb62c16b..94004713e 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputViewModel.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/IntRangePropertyInputViewModel.cs @@ -17,18 +17,14 @@ public class IntRangePropertyInputViewModel : PropertyInputViewModel if (LayerProperty.PropertyDescription.MinInputValue.IsNumber()) { - this.ValidationRule(vm => vm.Start, i => i >= Convert.ToInt32(LayerProperty.PropertyDescription.MinInputValue), - $"Start value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - this.ValidationRule(vm => vm.End, i => i >= Convert.ToInt32(LayerProperty.PropertyDescription.MinInputValue), - $"End value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + Min = Convert.ToInt32(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.Start, i => i >= Min, $"Start value must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - this.ValidationRule(vm => vm.Start, i => i < Convert.ToInt32(LayerProperty.PropertyDescription.MaxInputValue), - $"Start value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - this.ValidationRule(vm => vm.End, i => i < Convert.ToInt32(LayerProperty.PropertyDescription.MaxInputValue), - $"End value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + Max = Convert.ToInt32(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.End, i => i < Max, $"End value must be smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } @@ -60,6 +56,8 @@ public class IntRangePropertyInputViewModel : PropertyInputViewModel } } + public int Min { get; } = int.MinValue; + public int Max { get; } = int.MaxValue; protected override void OnInputValueChanged() { diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputView.axaml b/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputView.axaml index 7b63f8414..bd8ca6049 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputView.axaml +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputView.axaml @@ -13,6 +13,8 @@ Value="{CompiledBinding X}" Prefix="{CompiledBinding Prefix}" Suffix="{CompiledBinding Affix}" + Minimum="{CompiledBinding Min}" + Maximum="{CompiledBinding Max}" LargeChange="{Binding LayerProperty.PropertyDescription.InputStepSize}" SimpleNumberFormat="F3" VerticalAlignment="Center" @@ -25,6 +27,8 @@ Value="{CompiledBinding Y}" Prefix="{CompiledBinding Prefix}" Suffix="{CompiledBinding Affix}" + Minimum="{CompiledBinding Min}" + Maximum="{CompiledBinding Max}" LargeChange="{Binding LayerProperty.PropertyDescription.InputStepSize}" SimpleNumberFormat="F3" VerticalAlignment="Center" diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputViewModel.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputViewModel.cs index 4f711f997..bfbebc68c 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputViewModel.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/SKPointPropertyInputViewModel.cs @@ -15,18 +15,16 @@ public class SKPointPropertyInputViewModel : PropertyInputViewModel { if (LayerProperty.PropertyDescription.MinInputValue.IsNumber()) { - this.ValidationRule(vm => vm.X, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"X must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - this.ValidationRule(vm => vm.Y, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"Y must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + Min = Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.X, i => i >= Min, $"X must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + this.ValidationRule(vm => vm.Y, i => i >= Min, $"Y must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - this.ValidationRule(vm => vm.X, i => i <= Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"X must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - this.ValidationRule(vm => vm.Y, i => i <= Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"Y must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + Max = Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.X, i => i <= Max, $"X must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + this.ValidationRule(vm => vm.Y, i => i <= Max, $"Y must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } @@ -42,6 +40,8 @@ public class SKPointPropertyInputViewModel : PropertyInputViewModel set => InputValue = new SKPoint(X, value); } + public float Min { get; } = float.MinValue; + public float Max { get; } = float.MaxValue; protected override void OnInputValueChanged() { diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputView.axaml b/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputView.axaml index a89fe697a..64f0b1c13 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputView.axaml +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputView.axaml @@ -13,6 +13,8 @@ Value="{CompiledBinding Height}" Prefix="{CompiledBinding Prefix}" Suffix="{CompiledBinding Affix}" + Minimum="{CompiledBinding Min}" + Maximum="{CompiledBinding Max}" LargeChange="{Binding LayerProperty.PropertyDescription.InputStepSize}" SimpleNumberFormat="F3" VerticalAlignment="Center" @@ -25,6 +27,8 @@ Value="{CompiledBinding Width}" Prefix="{CompiledBinding Prefix}" Suffix="{CompiledBinding Affix}" + Minimum="{CompiledBinding Min}" + Maximum="{CompiledBinding Max}" LargeChange="{Binding LayerProperty.PropertyDescription.InputStepSize}" SimpleNumberFormat="F3" VerticalAlignment="Center" diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputViewModel.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputViewModel.cs index e1c006d32..17d53ee6c 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputViewModel.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputViewModel.cs @@ -17,18 +17,16 @@ public class SKSizePropertyInputViewModel : PropertyInputViewModel { if (LayerProperty.PropertyDescription.MinInputValue.IsNumber()) { - this.ValidationRule(vm => vm.Width, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"Width must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); - this.ValidationRule(vm => vm.Height, i => i >= Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue), - $"Height must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + Min = Convert.ToSingle(LayerProperty.PropertyDescription.MinInputValue); + this.ValidationRule(vm => vm.Width, i => i >= Min, $"Width must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); + this.ValidationRule(vm => vm.Height, i => i >= Min, $"Height must be equal to or greater than {LayerProperty.PropertyDescription.MinInputValue}."); } if (LayerProperty.PropertyDescription.MaxInputValue.IsNumber()) { - this.ValidationRule(vm => vm.Width, i => i <= Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"Width must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); - this.ValidationRule(vm => vm.Height, i => i <= Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue), - $"Height must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + Max = Convert.ToSingle(LayerProperty.PropertyDescription.MaxInputValue); + this.ValidationRule(vm => vm.Width, i => i <= Max, $"Width must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); + this.ValidationRule(vm => vm.Height, i => i <= Max, $"Height must be equal to or smaller than {LayerProperty.PropertyDescription.MaxInputValue}."); } } @@ -45,6 +43,9 @@ public class SKSizePropertyInputViewModel : PropertyInputViewModel set => InputValue = new SKSize(Width, value); } + public float Min { get; } = float.MinValue; + public float Max { get; } = float.MaxValue; + protected override void OnInputValueChanged() { this.RaisePropertyChanged(nameof(Width));