[NUI] Support dp converter for Width/Height specification (#3601)
authorXianbing Teng <xb.teng@samsung.com>
Mon, 27 Sep 2021 04:59:44 +0000 (12:59 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 27 Sep 2021 08:27:23 +0000 (17:27 +0900)
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/XamlBinding/IntDpTypeConverter.cs [new file with mode: 0755]

index 1cb8d86..e0ddc66 100755 (executable)
@@ -2299,6 +2299,7 @@ namespace Tizen.NUI.BaseComponents
         /// </code>
         /// </example>
         /// <since_tizen> 6 </since_tizen>
+        [Binding.TypeConverter(typeof(IntDpTypeConverter))]
         public int WidthSpecification
         {
             get
@@ -2355,6 +2356,7 @@ namespace Tizen.NUI.BaseComponents
         /// </code>
         /// </example>
         /// <since_tizen> 6 </since_tizen>
+        [Binding.TypeConverter(typeof(IntDpTypeConverter))]
         public int HeightSpecification
         {
             get
diff --git a/src/Tizen.NUI/src/public/XamlBinding/IntDpTypeConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/IntDpTypeConverter.cs
new file mode 100755 (executable)
index 0000000..9867ff4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.Linq;
+using System.Reflection;
+using System.Globalization;
+
+using Tizen.NUI;
+using Tizen.NUI.Xaml;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+    /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.IntDpTypeConverter")]
+    public class IntDpTypeConverter : TypeConverter
+    {
+        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override object ConvertFromInvariantString(string value)
+        {
+            if(!string.IsNullOrEmpty(value))
+            {
+                return (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(value.Trim());
+            }
+
+            throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(int)}");
+        }
+
+        /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override string ConvertToString(object value)
+        {
+            if (value != null)
+            {
+                int integer = (int)value;
+                return integer.ToString();
+            }
+            return "";
+        }
+    }
+}