Browse Source
Merge pull request #3329 from donandren/improveparsing
add some parsing of primitive types
pull/3343/head
Jumar Macato
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
51 additions and
4 deletions
src/Avalonia.Visuals/Matrix.cs
src/Avalonia.Visuals/Media/Transform.cs
src/Avalonia.Visuals/Point.cs
src/Avalonia.Visuals/RelativePoint.cs
src/Avalonia.Visuals/Vector.cs
@ -306,7 +306,7 @@ namespace Avalonia
/// <summary>
/// Parses a <see cref="Matrix"/> string.
/// </summary>
/// <param name="s">The string. </param>
/// <param name="s">Six comma-delimited double values (m11, m12, m21, m22, offsetX, offsetY) that describe the new <see cref="Matrix"/> </param>
/// <returns>The <see cref="Matrix"/>.</returns>
public static Matrix Parse ( string s )
{
@ -28,6 +28,16 @@ namespace Avalonia.Media
/// </summary>
public abstract Matrix Value { get ; }
/// <summary>
/// Parses a <see cref="Transform"/> string.
/// </summary>
/// <param name="s">Six comma-delimited double values that describe the new <see cref="Transform"/>. For details check <see cref="Matrix.Parse(string)"/> </param>
/// <returns>The <see cref="Transform"/>.</returns>
public static Transform Parse ( string s )
{
return new MatrixTransform ( Matrix . Parse ( s ) ) ;
}
/// <summary>
/// Raises the <see cref="Changed"/> event.
/// </summary>
@ -35,5 +45,14 @@ namespace Avalonia.Media
{
Changed ? . Invoke ( this , EventArgs . Empty ) ;
}
/// <summary>
/// Returns a String representing this transform matrix instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString ( )
{
return Value . ToString ( ) ;
}
}
}
@ -175,7 +175,7 @@ namespace Avalonia
/// Parses a <see cref="Point"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>The <see cref="Thickness "/>.</returns>
/// <returns>The <see cref="Point "/>.</returns>
public static Point Parse ( string s )
{
using ( var tokenizer = new StringTokenizer ( s , CultureInfo . InvariantCulture , exceptionMessage : "Invalid Point." ) )
@ -177,5 +177,16 @@ namespace Avalonia
unit ) ;
}
}
/// <summary>
/// Returns a String representing this RelativePoint instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString ( )
{
return _ unit = = RelativeUnit . Absolute ?
_ point . ToString ( ) :
string . Format ( CultureInfo . InvariantCulture , "{0}%, {1}%" , _ point . X * 1 0 0 , _ point . Y * 1 0 0 ) ;
}
}
}
@ -4,6 +4,7 @@
using System ;
using System.Globalization ;
using Avalonia.Animation.Animators ;
using Avalonia.Utilities ;
using JetBrains.Annotations ;
namespace Avalonia
@ -85,6 +86,22 @@ namespace Avalonia
public static Vector operator / ( Vector vector , double scale )
= > Divide ( vector , scale ) ;
/// <summary>
/// Parses a <see cref="Vector"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>The <see cref="Vector"/>.</returns>
public static Vector Parse ( string s )
{
using ( var tokenizer = new StringTokenizer ( s , CultureInfo . InvariantCulture , exceptionMessage : "Invalid Vector." ) )
{
return new Vector (
tokenizer . ReadDouble ( ) ,
tokenizer . ReadDouble ( )
) ;
}
}
/// <summary>
/// Length of the vector
/// </summary>
@ -166,9 +183,9 @@ namespace Avalonia
}
/// <summary>
/// Returns the string representation of the point .
/// Returns the string representation of the vector .
/// </summary>
/// <returns>The string representation of the point .</returns>
/// <returns>The string representation of the vector .</returns>
public override string ToString ( )
{
return string . Format ( CultureInfo . InvariantCulture , "{0}, {1}" , _ x , _ y ) ;