diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-09-04 20:50:36 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-10-04 23:19:09 +0300 |
commit | 655e2775af7ebe30ed38522c9ec8bc7242244a31 (patch) | |
tree | bc055afff31245e1335208596bb896bcbbab3dae | |
parent | 5d9c94157b17afa8f1174392626e7c193a6cb491 (diff) |
[Core] AutoResizingPropertyViewModel
5 files changed, 104 insertions, 2 deletions
diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockControl.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockControl.cs index 585bb7f..0302d6f 100644 --- a/Xamarin.PropertyEditing.Tests/MockControls/MockControl.cs +++ b/Xamarin.PropertyEditing.Tests/MockControls/MockControl.cs @@ -15,10 +15,10 @@ namespace Xamarin.PropertyEditing.Tests.MockControls bool canWrite = true, bool flag = false, IEnumerable<Type> converterTypes = null, string description = null, bool constrained = true, ValueSources valueSources = ValueSources.Local | ValueSources.Default | ValueSources.Binding, - IReadOnlyList<InputMode> inputModes = null, PropertyVariationOption[] options = null, bool isUncommon = false, ITypeInfo realType = null) + IReadOnlyList<InputMode> inputModes = null, PropertyVariationOption[] options = null, bool isUncommon = false, ITypeInfo realType = null, bool ignoreEnum = false) { IPropertyInfo propertyInfo; - if (typeof(T).IsEnum) { + if (typeof(T).IsEnum && !ignoreEnum) { var underlyingType = typeof (T).GetEnumUnderlyingType (); var enumPropertyInfoType = typeof (MockEnumPropertyInfo<,>) .MakeGenericType (underlyingType, typeof (T)); diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs index 8fec0e1..a3c3d1f 100644 --- a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs +++ b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs @@ -11,6 +11,7 @@ namespace Xamarin.PropertyEditing.Tests.MockControls { public MockSampleControl () { + AddProperty<AutoResizingFlags> ("Autoresizing", ReadWrite, valueSources: ValueSources.Local, ignoreEnum: true); AddProperty<TimeSpan> ("TimeSpan", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); AddProperty<TimeSpan> ("TimeSpanReadOnly", ReadOnly, canWrite: false, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); AddProperty<bool> ("Boolean", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); diff --git a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs index f970cb3..a2b4e6a 100644 --- a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs +++ b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs @@ -113,6 +113,7 @@ namespace Xamarin.PropertyEditing.Windows { typeof(TypePropertyViewModel), typeof(TypeEditorControl) }, { typeof(CollectionPropertyViewModel), typeof(CollectionEditor) }, { typeof(RatioViewModel), typeof(RatioEditorControl) }, + { typeof(AutoResizingPropertyViewModel), typeof(AutoResizingMaskEditorControl) } }; } } diff --git a/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs new file mode 100644 index 0000000..43e965d --- /dev/null +++ b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Windows.Input; +using Xamarin.PropertyEditing.Common; + +namespace Xamarin.PropertyEditing.ViewModels +{ + internal class AutoResizingPropertyViewModel + : PropertyViewModel<AutoResizingFlags> + { + public AutoResizingPropertyViewModel (TargetPlatform platform, IPropertyInfo property, IEnumerable<IObjectEditor> editors, PropertyVariation variation = null) + : base (platform, property, editors, variation) + { + ToggleMaskCommand = new RelayCommand<AutoResizingFlags> (ToggleFlag); + CycleSizingCommand = new RelayCommand (OnCycleSizing); + } + + public ICommand ToggleMaskCommand + { + get; + } + + public ICommand CycleSizingCommand + { + get; + } + + public bool LeftMarginFixed + { + get => (Value & AutoResizingFlags.FlexibleLeftMargin) != AutoResizingFlags.FlexibleLeftMargin; + set => SetFlag (AutoResizingFlags.FlexibleLeftMargin, !value); + } + + public bool RightMarginFixed + { + get => (Value & AutoResizingFlags.FlexibleRightMargin) != AutoResizingFlags.FlexibleRightMargin; + set => SetFlag (AutoResizingFlags.FlexibleRightMargin, !value); + } + + public bool TopMarginFixed + { + get => (Value & AutoResizingFlags.FlexibleTopMargin) != AutoResizingFlags.FlexibleTopMargin; + set => SetFlag (AutoResizingFlags.FlexibleTopMargin, !value); + } + + public bool BottomMarginFixed + { + get => (Value & AutoResizingFlags.FlexibleBottomMargin) != AutoResizingFlags.FlexibleBottomMargin; + set => SetFlag (AutoResizingFlags.FlexibleBottomMargin, !value); + } + + public bool HeightSizable + { + get => (Value & AutoResizingFlags.FlexibleHeight) == AutoResizingFlags.FlexibleHeight; + set => SetFlag (AutoResizingFlags.FlexibleHeight, value); + } + + public bool WidthSizable + { + get => (Value & AutoResizingFlags.FlexibleWidth) == AutoResizingFlags.FlexibleWidth; + set => SetFlag (AutoResizingFlags.FlexibleWidth, value); + } + + protected override void OnValueChanged () + { + base.OnValueChanged (); + + OnPropertyChanged (nameof(LeftMarginFixed)); + OnPropertyChanged (nameof(RightMarginFixed)); + OnPropertyChanged (nameof(TopMarginFixed)); + OnPropertyChanged (nameof(BottomMarginFixed)); + OnPropertyChanged (nameof(HeightSizable)); + OnPropertyChanged (nameof(WidthSizable)); + } + + private void SetFlag (AutoResizingFlags flag, bool set) + { + Value = (set) ? Value | flag : Value & ~flag; + } + + private void ToggleFlag (AutoResizingFlags flag) + { + Value = Value ^ flag; + } + + private void OnCycleSizing () + { + if (!WidthSizable && !HeightSizable) { + WidthSizable = true; + } else if (WidthSizable && !HeightSizable) { + HeightSizable = true; + } else if (WidthSizable && HeightSizable) { + WidthSizable = false; + } else if (!WidthSizable && HeightSizable) { + HeightSizable = false; + } + } + } +} diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs index 8e5cceb..5862ad9 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs @@ -655,6 +655,7 @@ namespace Xamarin.PropertyEditing.ViewModels { typeof(object), (tp,p,e,v) => new ObjectPropertyViewModel (tp, p, e, v) }, { typeof(ITypeInfo), (tp,p,e,v) => new TypePropertyViewModel (tp, p, e, v) }, { typeof(CommonRatio), (tp, p, e, v) => new RatioViewModel (tp, p, e, v) }, + { typeof(AutoResizingFlags), (tp, p, e, v) => new AutoResizingPropertyViewModel (tp, p, e, v) }, }; } } |