From 63c604bfa94dbba107cb397b90e2272ae775a128 Mon Sep 17 00:00:00 2001 From: Xianbing Teng Date: Mon, 27 Sep 2021 12:59:44 +0800 Subject: [PATCH] [NUI] Support dp converter for Width/Height specification (#3601) --- src/Tizen.NUI/src/public/BaseComponents/View.cs | 2 + .../src/public/XamlBinding/IntDpTypeConverter.cs | 58 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 src/Tizen.NUI/src/public/XamlBinding/IntDpTypeConverter.cs diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 1cb8d86..e0ddc66 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -2299,6 +2299,7 @@ namespace Tizen.NUI.BaseComponents /// /// /// 6 + [Binding.TypeConverter(typeof(IntDpTypeConverter))] public int WidthSpecification { get @@ -2355,6 +2356,7 @@ namespace Tizen.NUI.BaseComponents /// /// /// 6 + [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 index 0000000..9867ff4 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/IntDpTypeConverter.cs @@ -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 ""; + } + } +} -- 2.7.4