From d79dfb1cac4b134ea6a08bb9e1e9c553afb9907c Mon Sep 17 00:00:00 2001 From: Fang Xiaohui Date: Fri, 9 Jul 2021 11:38:47 +0800 Subject: [PATCH] [NUI][Xaml] Support different params in Vector Converter --- .../internal/XamlBinding/VectorTypeConverter.cs | 86 +++++++++++++++++++++- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/src/Tizen.NUI/src/internal/XamlBinding/VectorTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/VectorTypeConverter.cs index cd13715..bc3de59 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/VectorTypeConverter.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/VectorTypeConverter.cs @@ -52,12 +52,17 @@ namespace Tizen.NUI.Binding { var parts = value.Split(','); - if (parts.Length != 2) + if (parts.Length == 2) { - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}"); + return new Vector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + } + else if (parts.Length == 1) + { + var x = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return new Vector2(x, x); } - return new Vector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}"); } internal static string ToString(Vector2 value) @@ -90,6 +95,19 @@ namespace Tizen.NUI.Binding Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture)); } + else if (parts.Length == 2) + { + var vector2 = new Vector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + var vector3 = new Vector3(vector2); + vector2.Dispose(); + return vector3; + } + else if (parts.Length == 1) + { + var floatValue = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return new Vector3(floatValue, floatValue, floatValue); + } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector3)}"); @@ -129,6 +147,28 @@ namespace Tizen.NUI.Binding Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture)); } + else if (parts.Length == 3) + { + var vector3 = new Vector3(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture)); + var vector4 = new Vector4(vector3); + vector3.Dispose(); + return vector4; + } + else if (parts.Length == 2) + { + var vector2 = new Vector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + var vector4 = new Vector4(vector2); + vector2.Dispose(); + return vector4; + } + else if (parts.Length == 1) + { + Vector4 ret = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return ret; + } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector4)}"); @@ -166,6 +206,11 @@ namespace Tizen.NUI.Binding return new RelativeVector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); } + else if (parts.Length == 1) + { + var x = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return new RelativeVector2(x, x); + } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector2)}"); @@ -204,6 +249,19 @@ namespace Tizen.NUI.Binding Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture)); } + else if (parts.Length == 2) + { + var vector2 = new RelativeVector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + var vector3 = new RelativeVector3(vector2); + vector2.Dispose(); + return vector3; + } + else if (parts.Length == 1) + { + var x = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return new RelativeVector3(x, x, x); + } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector3)}"); @@ -243,6 +301,28 @@ namespace Tizen.NUI.Binding Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture)); } + else if (parts.Length == 3) + { + var vector3 = new RelativeVector3(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture)); + var vector4 = new RelativeVector4(vector3); + vector3.Dispose(); + return vector4; + } + else if (parts.Length == 2) + { + var vector2 = new RelativeVector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture)); + var vector4 = new RelativeVector4(vector2); + vector2.Dispose(); + return vector4; + } + else if (parts.Length == 1) + { + var x = Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture); + return new RelativeVector4(x, x, x, x); + } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector4)}"); -- 2.7.4