From de1cc1d9b78864e5023d958b2d6f9e9aafe444b2 Mon Sep 17 00:00:00 2001 From: Eric Maupin Date: Fri, 13 Sep 2019 10:22:37 -0400 Subject: [Win] AutoResizing mask editor --- .../Common/AutoResizingFlags.cs | 19 +++++ .../Properties/Resources.Designer.cs | 66 +++++++++++++++ Xamarin.PropertyEditing/Properties/Resources.resx | 99 +++++++++++++++------- .../ViewModels/AutoResizingPropertyViewModel.cs | 60 ++++++++++++- 4 files changed, 212 insertions(+), 32 deletions(-) create mode 100644 Xamarin.PropertyEditing/Common/AutoResizingFlags.cs (limited to 'Xamarin.PropertyEditing') diff --git a/Xamarin.PropertyEditing/Common/AutoResizingFlags.cs b/Xamarin.PropertyEditing/Common/AutoResizingFlags.cs new file mode 100644 index 0000000..8c21b55 --- /dev/null +++ b/Xamarin.PropertyEditing/Common/AutoResizingFlags.cs @@ -0,0 +1,19 @@ +using System; + +namespace Xamarin.PropertyEditing.Common +{ + [Flags] + public enum AutoResizingFlags + { + None = 0, + FlexibleLeftMargin = 1 << 0, + FlexibleWidth = 1 << 1, + FlexibleRightMargin = 1 << 2, + FlexibleTopMargin = 1 << 3, + FlexibleHeight = 1 << 4, + FlexibleBottomMargin = 1 << 5, + FlexibleMargins = FlexibleBottomMargin | FlexibleTopMargin | FlexibleLeftMargin | FlexibleRightMargin, + FlexibleDimensions = FlexibleHeight | FlexibleWidth, + All = FlexibleMargins | FlexibleDimensions + } +} diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs index c8cc438..1d9813f 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs +++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs @@ -1270,5 +1270,71 @@ namespace Xamarin.PropertyEditing.Properties { return ResourceManager.GetString("PropertyButtonName", resourceCulture); } } + + public static string AutoresizingBottomMarginName { + get { + return ResourceManager.GetString("AutoresizingBottomMarginName", resourceCulture); + } + } + + public static string AutoresizingFixedSized { + get { + return ResourceManager.GetString("AutoresizingFixedSized", resourceCulture); + } + } + + public static string AutoresizingHeightSizable { + get { + return ResourceManager.GetString("AutoresizingHeightSizable", resourceCulture); + } + } + + public static string AutoresizingLeftMarginName { + get { + return ResourceManager.GetString("AutoresizingLeftMarginName", resourceCulture); + } + } + + public static string AutoresizingRightMarginName { + get { + return ResourceManager.GetString("AutoresizingRightMarginName", resourceCulture); + } + } + + public static string AutoresizingSizingHelpText { + get { + return ResourceManager.GetString("AutoresizingSizingHelpText", resourceCulture); + } + } + + public static string AutoresizingSizingName { + get { + return ResourceManager.GetString("AutoresizingSizingName", resourceCulture); + } + } + + public static string AutoresizingTopMarginName { + get { + return ResourceManager.GetString("AutoresizingTopMarginName", resourceCulture); + } + } + + public static string AutoresizingWidthHeightSizable { + get { + return ResourceManager.GetString("AutoresizingWidthHeightSizable", resourceCulture); + } + } + + public static string AutoresizingWidthSizable { + get { + return ResourceManager.GetString("AutoresizingWidthSizable", resourceCulture); + } + } + + public static string Autosizing { + get { + return ResourceManager.GetString("Autosizing", resourceCulture); + } + } } } diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx index e778724..6713737 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.resx +++ b/Xamarin.PropertyEditing/Properties/Resources.resx @@ -1,17 +1,17 @@ - @@ -633,7 +633,7 @@ {0} DateTime Editor Editor for DateTime Value - + {0} X Editor Editor for X Value @@ -649,7 +649,7 @@ {0} Height Editor Editor for Height Value - + Arrange By: @@ -725,7 +725,7 @@ {0} {1} Path Editor Editor for File/Directory Path Editor - + Choose a {0} Choose a File or Directory @@ -751,7 +751,7 @@ Remove Variant - + Create Binding Create Binding for Object.Property @@ -809,4 +809,41 @@ Advanced options + + Left margin fixed + + + Autosizing + + + Example + + + Bottom margin fixed + + + Right margin fixed + + + Cycles through width and height sizable + + + Top margin fixed + + + fixed size + + + height sizable + + + Sizing, {0} + Name, {Current State} + + + width and height sizable + + + width sizable + \ No newline at end of file diff --git a/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs index 43e965d..2f29af8 100644 --- a/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using System.Threading.Tasks; using System.Windows.Input; using Xamarin.PropertyEditing.Common; +using Xamarin.PropertyEditing.Drawing; namespace Xamarin.PropertyEditing.ViewModels { @@ -61,6 +61,64 @@ namespace Xamarin.PropertyEditing.ViewModels set => SetFlag (AutoResizingFlags.FlexibleWidth, value); } + public CommonRectangle GetPreviewElementRectangle (CommonSize window, AutoResizingFlags flags) + { + const int Offset = 5; + const double multiplier = .75; + double width = 10, height = 10; + double left; + bool fixedLeft = !flags.HasFlag (AutoResizingFlags.FlexibleLeftMargin), + fixedRight = !flags.HasFlag (AutoResizingFlags.FlexibleRightMargin); + + if (fixedLeft) + left = Offset; + else if (fixedRight) + left = window.Width - Offset - width; + else + left = (window.Width / 2) - (width / 2); + + if (flags.HasFlag (AutoResizingFlags.FlexibleWidth)) { + if (fixedRight && fixedLeft) { + width = window.Width - (Offset * 2); + } else if (fixedRight) { + left = window.Width - (window.Width * multiplier); + width = window.Width - left - Offset; + } else if (fixedLeft) { + width = (window.Width * multiplier) - Offset; + } else { + width = window.Width * multiplier; + left = (window.Width - width) / 2; + } + } + + double top; + bool fixedTop = !flags.HasFlag (AutoResizingFlags.FlexibleTopMargin), + fixedBottom = !flags.HasFlag (AutoResizingFlags.FlexibleBottomMargin); + + if (fixedTop) + top = Offset; + else if (fixedBottom) + top = window.Height - Offset - height; + else + top = (window.Height / 2) - (height / 2); + + if (flags.HasFlag (AutoResizingFlags.FlexibleHeight)) { + if (fixedBottom && fixedTop) { + height = window.Height - (Offset * 2); + } else if (fixedBottom) { + top = window.Height - (window.Height * multiplier); + height = window.Height - top - Offset; + } else if (fixedTop) { + height = (window.Height * multiplier) - Offset; + } else { + height = window.Height * multiplier; + top = (window.Height - height) / 2; + } + } + + return new CommonRectangle (left, top, width, height); + } + protected override void OnValueChanged () { base.OnValueChanged (); -- cgit v1.2.3