Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <dolouis@microsoft.com>2019-10-10 19:56:20 +0300
committerGitHub <noreply@github.com>2019-10-10 19:56:20 +0300
commit20568bdc43bccc2c9896e891508d761b705d7d6a (patch)
treeb1832df5b4da7681740444557c552a4e23539d2d /Xamarin.PropertyEditing
parentc366f9537724f73421feb80e80be3e45cd984777 (diff)
parentde1cc1d9b78864e5023d958b2d6f9e9aafe444b2 (diff)
Merge pull request #649 from xamarin/ermau-autoresizing
Windows Autoresizing Editor
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/Common/AutoResizingFlags.cs19
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.Designer.cs66
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.resx99
-rw-r--r--Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs157
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs1
5 files changed, 311 insertions, 31 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
new file mode 100644
index 0000000..2f29af8
--- /dev/null
+++ b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs
@@ -0,0 +1,157 @@
+using System.Collections.Generic;
+using System.Windows.Input;
+using Xamarin.PropertyEditing.Common;
+using Xamarin.PropertyEditing.Drawing;
+
+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);
+ }
+
+ 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 ();
+
+ 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) },
};
}
}