From: neostom432 <31119276+neostom432@users.noreply.github.com>
Date: Wed, 1 Apr 2020 08:06:12 +0000 (+0900)
Subject: [NUI] Create Color from Hex Color Code (#1511)
X-Git-Tag: accepted/tizen/unified/20210219.040944~804
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8fcc24ae8fbbc2aa5069cbc57800aca60561319b;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git
[NUI] Create Color from Hex Color Code (#1511)
* [NUI] Create Color from Hex Color Code
Create color object from Hex Color Code (string).
1. Code with "#", it will be remove.
2. Without alpha channel, alpah channel will be set 1.0f.
3. Working both. Lowercase and uppercase,
"#FF0000FF" - Good
"#ff0000ff" - Good
"FF0000FF" - Good
"FF0000" - Good
"FF" - Bad ( too short )
* [NUI] Add ArgumentException to Color constructor
---
diff --git a/src/Tizen.NUI/src/public/Color.cs b/src/Tizen.NUI/src/public/Color.cs
index d7ad7b0..8aafc54 100755
--- a/src/Tizen.NUI/src/public/Color.cs
+++ b/src/Tizen.NUI/src/public/Color.cs
@@ -117,6 +117,30 @@ namespace Tizen.NUI
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
+ ///
+ /// The conversion constructor from an hexcode of four floats.
+ ///
+ /// Hex color code
+ /// 6
+ /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Color(string hexColor) : this(Interop.Vector4.new_Vector4__SWIG_0(), true)
+ {
+ try
+ {
+ hexColor = hexColor.Replace("#", "");
+
+ R = ((float)Convert.ToInt32(hexColor.Substring(0,2), 16))/255.0f;
+ G = ((float)Convert.ToInt32(hexColor.Substring(2,2), 16))/255.0f;
+ B = ((float)Convert.ToInt32(hexColor.Substring(4,2), 16))/255.0f;
+ A = hexColor.Length > 6 ? ((float)Convert.ToInt32(hexColor.Substring(6,2), 16))/255.0f : 1.0f;
+ }
+ catch
+ {
+ throw new global::System.ArgumentException("Please check your hex code");
+ }
+ }
+
internal Color(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
hashDummy = false;