From: Fang Xiaohui Date: Mon, 7 Mar 2022 07:55:39 +0000 (+0800) Subject: [NUI][XamlBuild] 1.Support DP value, 2.Support DataTemplate in EXaml X-Git-Tag: accepted/tizen/unified/20231205.024657~1085 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a7bbf6c4a55346b0856f4f051b55136ac875b97;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI][XamlBuild] 1.Support DP value, 2.Support DataTemplate in EXaml --- diff --git a/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll b/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll index bbe5db2..432cf60 100644 Binary files a/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll and b/pkg/Tizen.NET.API10/xamlbuild/Tizen.NUI.XamlBuild.dll differ diff --git a/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXaml/EXamlCreateObject/EXamlCreateDPObject.cs b/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXaml/EXamlCreateObject/EXamlCreateDPObject.cs index b872363..dfd8595 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXaml/EXamlCreateObject/EXamlCreateDPObject.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXaml/EXamlCreateObject/EXamlCreateDPObject.cs @@ -24,10 +24,10 @@ namespace Tizen.NUI.EXaml { internal class EXamlCreateDPObject : EXamlCreateObject { - public EXamlCreateDPObject(EXamlContext context, object value, TypeReference type, string prefix) : base(context, null, type) + public EXamlCreateDPObject(EXamlContext context, object value, TypeReference type, string subfix) : base(context, null, type) { this.value = value; - this.prefix = prefix; + this.subfix = subfix; } internal override string Write() @@ -39,14 +39,14 @@ namespace Tizen.NUI.EXaml string ret = String.Format("({0} ({1} {2}))\n", eXamlContext.GetValueString((int)EXamlOperationType.CreateDPObject), - eXamlContext.GetValueString(value.ToString() + prefix), + eXamlContext.GetValueString(value.ToString() + subfix), eXamlContext.GetValueString(eXamlContext.GetTypeIndex(Type))); return ret; } private object value; - private string prefix; + private string subfix; } } diff --git a/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXamlContext.cs b/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXamlContext.cs index 2c4de0c..375eab8 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXamlContext.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/EXamlBuild/EXamlContext.cs @@ -374,9 +374,7 @@ namespace Tizen.NUI.EXaml.Build.Tasks if (0 < longStrings.Length) { - ret += String.Format("({0} ({1}))\n", - GetValueString((int)EXamlOperationType.GetLongString), - GetValueString(longStrings)); + ret += String.Format("/{0}\n", longStrings); } return ret; diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/BoundsTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/BoundsTypeConverter.cs index b7d1981..830db1c 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/BoundsTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/BoundsTypeConverter.cs @@ -41,7 +41,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in xywh) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ExtentsTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ExtentsTypeConverter.cs index 2d496d8..fdbdffd 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ExtentsTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ExtentsTypeConverter.cs @@ -49,7 +49,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/PositionTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/PositionTypeConverter.cs index 715d181..db5c2de 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/PositionTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/PositionTypeConverter.cs @@ -84,7 +84,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } @@ -150,7 +150,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/RectangleTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/RectangleTypeConverter.cs index 59b19e9..2c2b82b 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/RectangleTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/RectangleTypeConverter.cs @@ -38,7 +38,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in xywh) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/SizeTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/SizeTypeConverter.cs index cd39e26..0ea880b 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/SizeTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/SizeTypeConverter.cs @@ -47,7 +47,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } @@ -98,7 +98,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ThicknessTypeConverter.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ThicknessTypeConverter.cs index 77f89b2..5dd229b 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ThicknessTypeConverter.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/CompiledConverters/ThicknessTypeConverter.cs @@ -38,7 +38,7 @@ namespace Tizen.NUI.Xaml.Core.XamlC foreach (var thick in thickness) { - if (thick.EndsWith("dp") || thick.EndsWith("px")) + if (null != NodeILExtensions.GetDPValueSubFix(thick)) { return null; } diff --git a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/NodeILExtensions.cs b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/NodeILExtensions.cs index 7e46b32..db96c70 100755 --- a/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/NodeILExtensions.cs +++ b/src/Tizen.NUI.XamlBuild/src/public/XamlBuild/NodeILExtensions.cs @@ -245,6 +245,20 @@ namespace Tizen.NUI.Xaml.Build.Tasks return null; } + private static string[] dpValueSubFixes = { "dp", "sp", "pt", "px"}; + internal static string GetDPValueSubFix(string valueStr) + { + foreach (var subFix in dpValueSubFixes) + { + if (valueStr.EndsWith(subFix)) + { + return subFix; + } + } + + return null; + } + public static object GetBaseValue(this ValueNode node, EXamlContext context, TypeReference targetTypeRef) { var str = (string)node.Value; @@ -252,15 +266,12 @@ namespace Tizen.NUI.Xaml.Build.Tasks if ("System.String" != targetTypeRef.FullName) { - if (str.EndsWith("dp")) - { - var value = GetBaseValue(context, str.Substring(0, str.Length - "dp".Length), targetTypeRef); - ret = new EXamlCreateDPObject(context, value, targetTypeRef, "dp"); - } - else if (str.EndsWith("px")) + string subFix = GetDPValueSubFix(str); + + if (null != subFix) { - var value = GetBaseValue(context, str.Substring(0, str.Length - "px".Length), targetTypeRef); - ret = new EXamlCreateDPObject(context, value, targetTypeRef, "px"); + var value = GetBaseValue(context, str.Substring(0, str.Length - subFix.Length), targetTypeRef); + ret = new EXamlCreateDPObject(context, value, targetTypeRef, subFix); } } @@ -411,7 +422,7 @@ namespace Tizen.NUI.Xaml.Build.Tasks yield return Instruction.Create(OpCodes.Ldc_I4, SByte.Parse(str, CultureInfo.InvariantCulture)); else if (targetTypeRef.FullName == "System.Int16") { - if (str.EndsWith("dp") || str.EndsWith("px")) + if (null != GetDPValueSubFix(str)) { var insOfDPValue = GetDPValue(module, node, targetTypeRef, str); diff --git a/src/Tizen.NUI/src/internal/EXaml/Action/RootAction.cs b/src/Tizen.NUI/src/internal/EXaml/Action/RootAction.cs index 32192f3..30051cf 100755 --- a/src/Tizen.NUI/src/internal/EXaml/Action/RootAction.cs +++ b/src/Tizen.NUI/src/internal/EXaml/Action/RootAction.cs @@ -232,6 +232,12 @@ namespace Tizen.NUI.EXaml { globalDataList.LongStrings = opInfo[0] as string; }; + + createOperations[(int)EXamlOperationType.CreateDPObject] = (GlobalDataList globalDataList, List opInfo) => + { + var operation = new CreateDPObject(globalDataList, opInfo); + globalDataList.Operations.Add(operation); + }; } } } diff --git a/src/Tizen.NUI/src/internal/EXaml/LoadEXaml.cs b/src/Tizen.NUI/src/internal/EXaml/LoadEXaml.cs index 17fcd87..4c0e688 100755 --- a/src/Tizen.NUI/src/internal/EXaml/LoadEXaml.cs +++ b/src/Tizen.NUI/src/internal/EXaml/LoadEXaml.cs @@ -27,10 +27,27 @@ namespace Tizen.NUI.EXaml var globalDataList = new GlobalDataList(); Action currentAction = new RootAction(globalDataList); + var rootAction = currentAction; - foreach (char c in xaml) + int index = 0; + + for (; index < xaml.Length; index++) + { + var c = xaml[index]; + + if (currentAction == rootAction && '/' == c) + { + break; + } + else + { + currentAction = currentAction.DealChar(c); + } + } + + for (index++; index < xaml.Length; index++) { - currentAction = currentAction.DealChar(c); + globalDataList.LongStrings += xaml[index]; } foreach (var op in globalDataList.PreLoadOperations) diff --git a/src/Tizen.NUI/src/internal/EXaml/Operation/CreateDPObject.cs b/src/Tizen.NUI/src/internal/EXaml/Operation/CreateDPObject.cs new file mode 100755 index 0000000..80d49cf --- /dev/null +++ b/src/Tizen.NUI/src/internal/EXaml/Operation/CreateDPObject.cs @@ -0,0 +1,98 @@ +/* + * 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.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Binding; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.EXaml +{ + internal class CreateDPObject : Operation + { + public CreateDPObject(GlobalDataList globalDataList, List operationInfos) + { + this.valueStr = operationInfos[0] as string; + this.typeIndex = (int)operationInfos[1]; + this.globalDataList = globalDataList; + } + + private GlobalDataList globalDataList; + + public void Do() + { + if (0 > typeIndex) + { + object dpValue = null; + + switch (typeIndex) + { + case -3: + dpValue = Convert.ToInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -4: + dpValue = Convert.ToInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -5: + dpValue = Convert.ToInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -7: + dpValue = Convert.ToUInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -8: + dpValue = Convert.ToUInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -9: + dpValue = Convert.ToUInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -15: + dpValue = Convert.ToSingle(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + + case -16: + dpValue = Convert.ToDouble(GraphicsTypeManager.Instance.ConvertScriptToPixel(valueStr)); + break; + } + + if (null == dpValue) + { + throw new Exception($"Can't convert {valueStr} to DP value of typeIndex {typeIndex}"); + } + + globalDataList.GatheredInstances.Add(dpValue); + } + else + { + var type = globalDataList.GatheredTypes[typeIndex]; + throw new Exception($"Can't convert DP value of type {type.FullName}"); + } + } + + private int typeIndex; + private string valueStr; + } +}