Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Eto/Drawing/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ public static Size Ceiling (SizeF size)
/// </summary>
public static readonly Size MinValue = new Size (Int32.MinValue, Int32.MinValue);

/// <summary>
/// Initializes a new Size class with an identical width and height
/// </summary>
/// <param name="size">Initial width and height of the size</param>
public Size (int size)
: this()
{
Width = size;
Height = size;
}

/// <summary>
/// Initializes a new Size class with the specified width and height
/// </summary>
Expand Down Expand Up @@ -405,4 +416,4 @@ public bool Equals (Size other)
{
return other == this;
}
}
}
15 changes: 15 additions & 0 deletions src/Eto/Drawing/SizeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
15 changes: 13 additions & 2 deletions src/Eto/Drawing/SizeF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ public static SizeF Abs (SizeF size)
/// A SizeF with the width and height set to float.NegativeInfinity
/// </summary>
public static readonly SizeF NegativeInfinity = new SizeF (float.NegativeInfinity, float.NegativeInfinity);


/// <summary>
/// Initializes a new Size class with an identical width and height
/// </summary>
/// <param name="size">Initial width and height of the size</param>
public SizeF (float size)
: this()
{
Width = size;
Height = size;
}

/// <summary>
/// Initializes a new SizeF class with the specified width and height
/// </summary>
Expand Down Expand Up @@ -337,4 +348,4 @@ public bool Equals (SizeF other)
{
return other == this;
}
}
}
15 changes: 15 additions & 0 deletions src/Eto/Drawing/SizeFConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down