diff --git a/src/Eto/Drawing/Size.cs b/src/Eto/Drawing/Size.cs index 8a8325f08f..a8a9541156 100644 --- a/src/Eto/Drawing/Size.cs +++ b/src/Eto/Drawing/Size.cs @@ -101,6 +101,17 @@ public static Size Ceiling (SizeF size) /// public static readonly Size MinValue = new Size (Int32.MinValue, Int32.MinValue); + /// + /// Initializes a new Size class with an identical width and height + /// + /// Initial width and height of the size + public Size (int size) + : this() + { + Width = size; + Height = size; + } + /// /// Initializes a new Size class with the specified width and height /// @@ -405,4 +416,4 @@ public bool Equals (Size other) { return other == this; } -} \ No newline at end of file +} diff --git a/src/Eto/Drawing/SizeConverter.cs b/src/Eto/Drawing/SizeConverter.cs index c7bb9de45e..d9c2dd1d05 100644 --- a/src/Eto/Drawing/SizeConverter.cs +++ b/src/Eto/Drawing/SizeConverter.cs @@ -39,6 +39,21 @@ public override object ConvertFrom(sc.ITypeDescriptorContext context, CultureInf if (text != null) { string[] parts = text.Split(DimensionSplitter, StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length == 1) + { + try + { + return new Size( + int.Parse(parts[0]) + ); + } + catch + { + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}' as Size. Should be a single integer", text)); + } + } + if (parts.Length != 2) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}' as Size. Should be in the form of 'width, height'", text)); diff --git a/src/Eto/Drawing/SizeF.cs b/src/Eto/Drawing/SizeF.cs index fa63380911..d7ef4148c8 100644 --- a/src/Eto/Drawing/SizeF.cs +++ b/src/Eto/Drawing/SizeF.cs @@ -74,7 +74,18 @@ public static SizeF Abs (SizeF size) /// A SizeF with the width and height set to float.NegativeInfinity /// public static readonly SizeF NegativeInfinity = new SizeF (float.NegativeInfinity, float.NegativeInfinity); - + + /// + /// Initializes a new Size class with an identical width and height + /// + /// Initial width and height of the size + public SizeF (float size) + : this() + { + Width = size; + Height = size; + } + /// /// Initializes a new SizeF class with the specified width and height /// @@ -337,4 +348,4 @@ public bool Equals (SizeF other) { return other == this; } -} \ No newline at end of file +} diff --git a/src/Eto/Drawing/SizeFConverter.cs b/src/Eto/Drawing/SizeFConverter.cs index fb72b9e098..db1d7d25bc 100644 --- a/src/Eto/Drawing/SizeFConverter.cs +++ b/src/Eto/Drawing/SizeFConverter.cs @@ -39,6 +39,21 @@ public override object ConvertFrom(sc.ITypeDescriptorContext context, CultureInf if (text != null) { string[] parts = text.Split(DimensionSplitter, StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length == 1) + { + try + { + return new SizeF( + int.Parse(parts[0]) + ); + } + catch + { + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}' as SizeF. Should be a single integer", text)); + } + } + if (parts.Length != 2) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}' as SizeF. Should be in the form of 'width, height'", text));