diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-09-13 17:22:37 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-10-04 23:19:09 +0300 |
commit | de1cc1d9b78864e5023d958b2d6f9e9aafe444b2 (patch) | |
tree | 00e6a2de8598ef1adecd4e8f6a7a30332ccddd28 /Xamarin.PropertyEditing | |
parent | 655e2775af7ebe30ed38522c9ec8bc7242244a31 (diff) |
[Win] AutoResizing mask editor
Diffstat (limited to 'Xamarin.PropertyEditing')
4 files changed, 212 insertions, 32 deletions
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 @@ <?xml version="1.0" encoding="utf-8"?> <root> - <!-- - Microsoft ResX Schema - + <!-- + Microsoft ResX Schema + Version 2.0 - - The primary goals of this format is to allow a simple XML format - that is mostly human readable. The generation and parsing of the - various data types are done through the TypeConverter classes + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes associated with the data types. - + Example: - + ... ado.net/XML headers & schema ... <resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="version">2.0</resheader> @@ -26,36 +26,36 @@ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <comment>This is a comment</comment> </data> - - There are any number of "resheader" rows that contain simple + + There are any number of "resheader" rows that contain simple name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can read any of the formats listed below. - + mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with + value : The object must be serialized with : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. - + mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with + value : The object must be serialized with : System.Runtime.Serialization.Formatters.Soap.SoapFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array + value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> @@ -633,7 +633,7 @@ <data name="AccessibilityDateTime" xml:space="preserve"> <value>{0} DateTime Editor</value> <comment>Editor for DateTime Value</comment> - </data> + </data> <data name="AccessibilityXEditor" xml:space="preserve"> <value>{0} X Editor</value> <comment>Editor for X Value</comment> @@ -649,7 +649,7 @@ <data name="AccessibilityHeightEditor" xml:space="preserve"> <value>{0} Height Editor</value> <comment>Editor for Height Value</comment> - </data> + </data> <data name="ArrangeByLabel" xml:space="preserve"> <value>Arrange By:</value> </data> @@ -725,7 +725,7 @@ <data name="AccessibilityPathEditor" xml:space="preserve"> <value>{0} {1} Path Editor</value> <comment>Editor for File/Directory Path Editor</comment> - </data> + </data> <data name="ChooseFileOrDirectory" xml:space="preserve"> <value>Choose a {0}</value> <comment>Choose a File or Directory</comment> @@ -751,7 +751,7 @@ </data> <data name="RemoveVariant" xml:space="preserve"> <value>Remove Variant</value> - </data> + </data> <data name="CreateBindingTitle" xml:space="preserve"> <value>Create Binding</value> <comment>Create Binding for Object.Property</comment> @@ -809,4 +809,41 @@ <data name="PropertyButtonName" xml:space="preserve"> <value>Advanced options</value> </data> + <data name="AutoresizingLeftMarginName" xml:space="preserve"> + <value>Left margin fixed</value> + </data> + <data name="Autosizing" xml:space="preserve"> + <value>Autosizing</value> + </data> + <data name="Example" xml:space="preserve"> + <value>Example</value> + </data> + <data name="AutoresizingBottomMarginName" xml:space="preserve"> + <value>Bottom margin fixed</value> + </data> + <data name="AutoresizingRightMarginName" xml:space="preserve"> + <value>Right margin fixed</value> + </data> + <data name="AutoresizingSizingHelpText" xml:space="preserve"> + <value>Cycles through width and height sizable</value> + </data> + <data name="AutoresizingTopMarginName" xml:space="preserve"> + <value>Top margin fixed</value> + </data> + <data name="AutoresizingFixedSized" xml:space="preserve"> + <value>fixed size</value> + </data> + <data name="AutoresizingHeightSizable" xml:space="preserve"> + <value>height sizable</value> + </data> + <data name="AutoresizingSizingName" xml:space="preserve"> + <value>Sizing, {0}</value> + <comment>Name, {Current State}</comment> + </data> + <data name="AutoresizingWidthHeightSizable" xml:space="preserve"> + <value>width and height sizable</value> + </data> + <data name="AutoresizingWidthSizable" xml:space="preserve"> + <value>width sizable</value> + </data> </root>
\ 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 (); |