From db321986b37b5e511f687ab77032f346fbaa3b1c Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Fri, 16 Apr 2021 17:17:07 +0900 Subject: [PATCH] [NUI] Make bindable properties in Style and View have same property name. (#2850) Signed-off-by: Jiyun Yang --- src/Tizen.NUI.Components/Controls/Button.cs | 20 +- src/Tizen.NUI.Components/Controls/Slider.cs | 8 +- src/Tizen.NUI.Components/Controls/Switch.cs | 19 +- .../src/public/BaseComponents/ImageView.cs | 90 +++--- .../public/BaseComponents/Style/ImageViewStyle.cs | 28 +- .../src/public/BaseComponents/Style/Selector.cs | 62 ++-- .../public/BaseComponents/Style/TextFieldStyle.cs | 104 +++--- .../public/BaseComponents/Style/TextLabelStyle.cs | 14 +- .../src/public/BaseComponents/Style/ViewStyle.cs | 53 +-- .../Style/ViewStyleBindableProperty.cs | 14 +- .../src/public/BaseComponents/TextField.cs | 16 +- .../BaseComponents/TextFieldBindableProperty.cs | 138 +------- .../public/BaseComponents/TextFieldSelectorData.cs | 61 ---- .../src/public/BaseComponents/TextLabel.cs | 3 - .../BaseComponents/TextLabelBindableProperty.cs | 282 +++++++++++----- .../public/BaseComponents/TextLabelSelectorData.cs | 27 +- src/Tizen.NUI/src/public/BaseComponents/View.cs | 29 -- .../public/BaseComponents/ViewBindableProperty.cs | 359 ++++++++++----------- .../src/public/BaseComponents/ViewInternal.cs | 7 - .../src/public/BaseComponents/ViewSelectorData.cs | 40 ++- 20 files changed, 600 insertions(+), 774 deletions(-) delete mode 100755 src/Tizen.NUI/src/public/BaseComponents/TextFieldSelectorData.cs diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index df811f3..042e662 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.cs @@ -484,7 +484,7 @@ namespace Tizen.NUI.Components /// 6 public StringSelector TextSelector { - get => buttonText == null ? null : new StringSelector((Selector)buttonText.GetValue(TextLabel.TextSelectorProperty)); + get => buttonText == null ? null : new StringSelector(buttonText.TextSelector); set { if (value == null || buttonText == null) @@ -493,7 +493,7 @@ namespace Tizen.NUI.Components } else { - buttonText.SetValue(TextLabel.TextSelectorProperty, value); + buttonText.TextSelector = value; } } } @@ -506,7 +506,7 @@ namespace Tizen.NUI.Components /// 6 public StringSelector TranslatableTextSelector { - get => buttonText == null ? null : new StringSelector((Selector)buttonText.GetValue(TextLabel.TranslatableTextSelectorProperty)); + get => buttonText == null ? null : new StringSelector(buttonText.TranslatableTextSelector); set { if (value == null || buttonText == null) @@ -515,7 +515,7 @@ namespace Tizen.NUI.Components } else { - buttonText.SetValue(TextLabel.TranslatableTextSelectorProperty, value); + buttonText.TranslatableTextSelector = value; } } } @@ -528,7 +528,7 @@ namespace Tizen.NUI.Components /// 6 public ColorSelector TextColorSelector { - get => buttonText == null ? null : new ColorSelector((Selector)buttonText.GetValue(TextLabel.TextColorSelectorProperty)); + get => buttonText == null ? null : new ColorSelector(buttonText.TextColorSelector); set { if (value == null || buttonText == null) @@ -537,7 +537,7 @@ namespace Tizen.NUI.Components } else { - buttonText.SetValue(TextLabel.TextColorSelectorProperty, value); + buttonText.TextColorSelector = value; } } } @@ -550,7 +550,7 @@ namespace Tizen.NUI.Components /// 6 public FloatSelector PointSizeSelector { - get => buttonText == null ? null : new FloatSelector((Selector)buttonText.GetValue(TextLabel.PointSizeSelectorProperty)); + get => buttonText == null ? null : new FloatSelector(buttonText.PointSizeSelector); set { if (value == null || buttonText == null) @@ -559,7 +559,7 @@ namespace Tizen.NUI.Components } else { - buttonText.SetValue(TextLabel.PointSizeSelectorProperty, value); + buttonText.PointSizeSelector = value; } } } @@ -572,7 +572,7 @@ namespace Tizen.NUI.Components /// 6 public StringSelector IconURLSelector { - get => buttonIcon == null ? null : new StringSelector((Selector)buttonIcon.GetValue(ImageView.ResourceUrlSelectorProperty)); + get => buttonIcon == null ? null : new StringSelector(buttonIcon.ResourceUrlSelector); set { if (value == null || buttonIcon == null) @@ -581,7 +581,7 @@ namespace Tizen.NUI.Components } else { - buttonIcon.SetValue(ImageView.ResourceUrlSelectorProperty, value); + buttonIcon.ResourceUrlSelector = value; } } } diff --git a/src/Tizen.NUI.Components/Controls/Slider.cs b/src/Tizen.NUI.Components/Controls/Slider.cs index 5460e95..b2696f5 100755 --- a/src/Tizen.NUI.Components/Controls/Slider.cs +++ b/src/Tizen.NUI.Components/Controls/Slider.cs @@ -510,7 +510,7 @@ namespace Tizen.NUI.Components /// 6 public StringSelector ThumbImageURLSelector { - get => thumbImage == null ? null : new StringSelector((Selector)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty)); + get => thumbImage == null ? null : new StringSelector(thumbImage.ResourceUrlSelector); set { if (value == null || thumbImage == null) @@ -519,7 +519,7 @@ namespace Tizen.NUI.Components } else { - thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value); + thumbImage.ResourceUrlSelector = value; thumbImageUrlSelector = value; } } @@ -540,7 +540,7 @@ namespace Tizen.NUI.Components } else { - return (Selector)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty); + return thumbImage.ResourceUrlSelector; } } set @@ -551,7 +551,7 @@ namespace Tizen.NUI.Components } else { - thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value); + thumbImage.ResourceUrlSelector = value; thumbImageUrlSelector = value; } } diff --git a/src/Tizen.NUI.Components/Controls/Switch.cs b/src/Tizen.NUI.Components/Controls/Switch.cs index b0efa7b..6b67536 100755 --- a/src/Tizen.NUI.Components/Controls/Switch.cs +++ b/src/Tizen.NUI.Components/Controls/Switch.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019 Samsung Electronics Co., Ltd. + * 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. @@ -16,6 +16,7 @@ */ using System; using System.ComponentModel; +using System.Diagnostics; using Tizen.NUI.BaseComponents; using Tizen.NUI.Components.Extension; @@ -175,8 +176,12 @@ namespace Tizen.NUI.Components /// 6 public StringSelector SwitchBackgroundImageURLSelector { - get => track == null ? null : new StringSelector((Selector)track.GetValue(ImageView.ResourceUrlSelectorProperty)); - set => track?.SetValue(ImageView.ResourceUrlSelectorProperty, value); + get => new StringSelector(track.ResourceUrlSelector); + set + { + Debug.Assert(track != null); + track.ResourceUrlSelector = value; + } } /// @@ -202,8 +207,12 @@ namespace Tizen.NUI.Components /// 6 public StringSelector SwitchHandlerImageURLSelector { - get => thumb == null ? null : new StringSelector((Selector)thumb.GetValue(ImageView.ResourceUrlSelectorProperty)); - set => thumb?.SetValue(ImageView.ResourceUrlSelectorProperty, value); + get => new StringSelector(thumb.ResourceUrlSelector); + set + { + Debug.Assert(thumb != null); + thumb.ResourceUrlSelector = value; + } } /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index a251914..c4da073 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -36,15 +36,16 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) => { var imageView = (ImageView)bindable; - string url = (string)newValue; - url = (url == null ? "" : url); - if (url.StartsWith("*Resource*")) + + if (newValue is Selector selector) { - string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource; - url = url.Replace("*Resource*", resource); + imageView.ResourceUrlSelector = selector; + } + else + { + imageView.resourceUrlSelector?.Reset(imageView); + imageView.SetResourceUrl((string)newValue); } - imageView._resourceUrl = url; - imageView.UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); }, defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => { @@ -162,10 +163,16 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) => { var imageView = (ImageView)bindable; - if (newValue != null) + imageView.borderSelector?.Reset(imageView); + + if (newValue is Selector selector) + { + if (selector.HasAll()) imageView.SetBorder(selector.All); + else imageView.borderSelector = new TriggerableSelector(imageView, selector, imageView.SetBorder, true); + } + else { - imageView._border = new Rectangle((Rectangle)newValue); - imageView.UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(imageView._border)); + imageView.SetBorder((Rectangle)newValue); } }, defaultValueCreator: (bindable) => @@ -233,28 +240,6 @@ namespace Tizen.NUI.BaseComponents return ret; })); - internal static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) => - { - var imageView = (ImageView)bindable; - imageView.resourceUrlSelector.Update(imageView, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var imageView = (ImageView)bindable; - return imageView.GetSelector(imageView.resourceUrlSelector, ImageView.ResourceUrlProperty); - }); - - internal static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) => - { - var imageView = (ImageView)bindable; - imageView.borderSelector.Update(imageView, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var imageView = (ImageView)bindable; - return imageView.GetSelector(imageView.borderSelector, ImageView.BorderProperty); - }); - private EventHandler _resourceReadyEventHandler; private ResourceReadyEventCallbackType _resourceReadyEventCallback; private EventHandler _resourceLoadedEventHandler; @@ -267,8 +252,8 @@ namespace Tizen.NUI.BaseComponents private int _desired_width = -1; private int _desired_height = -1; private VisualFittingModeType _fittingMode = VisualFittingModeType.Fill; - private readonly TriggerableSelector resourceUrlSelector = new TriggerableSelector(ResourceUrlProperty); - private readonly TriggerableSelector borderSelector = new TriggerableSelector(BorderProperty); + private TriggerableSelector resourceUrlSelector; + private TriggerableSelector borderSelector; /// /// Creates an initialized ImageView. @@ -454,7 +439,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(ResourceUrlProperty, value); - resourceUrlSelector.Reset(this); NotifyPropertyChanged(); } } @@ -589,7 +573,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(BorderProperty, value); - borderSelector.Reset(this); NotifyPropertyChanged(); } } @@ -1083,6 +1066,19 @@ namespace Tizen.NUI.BaseComponents } } + internal Selector ResourceUrlSelector + { + get => GetSelector(resourceUrlSelector, ImageView.ResourceUrlProperty); + set + { + resourceUrlSelector?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetResourceUrl(value.All); + else resourceUrlSelector = new TriggerableSelector(this, value, SetResourceUrl, true); + } + } + /// /// Get attributes, it is abstract function and must be override. /// @@ -1173,6 +1169,28 @@ namespace Tizen.NUI.BaseComponents } } + private void SetResourceUrl(string value) + { + value = (value == null ? "" : value); + if (value.StartsWith("*Resource*")) + { + string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource; + value = value.Replace("*Resource*", resource); + } + _resourceUrl = value; + UpdateImage(ImageVisualProperty.URL, new PropertyValue(value)); + } + + private void SetBorder(Rectangle value) + { + if (value == null) + { + return; + } + _border = new Rectangle(value); + UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border)); + } + private void UpdateImageMap(PropertyMap fromMap) { PropertyMap imageMap = new PropertyMap(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ImageViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ImageViewStyle.cs index bacd141..3e8a1ca 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ImageViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ImageViewStyle.cs @@ -28,27 +28,27 @@ namespace Tizen.NUI.BaseComponents { /// 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 static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector), typeof(ImageViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ResourceUrl), typeof(Selector), typeof(ImageViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var imageViewStyle = (ImageViewStyle)bindable; - imageViewStyle.resourceUrlSelector = ((Selector)newValue)?.Clone(); + imageViewStyle.resourceUrl = ((Selector)newValue)?.Clone(); }, defaultValueCreator: (bindable) => { var imageViewStyle = (ImageViewStyle)bindable; - return imageViewStyle.resourceUrlSelector; + return imageViewStyle.resourceUrl; }); /// 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 static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector), typeof(ImageViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Selector), typeof(ImageViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var imageViewStyle = (ImageViewStyle)bindable; - imageViewStyle.borderSelector = ((Selector)newValue)?.Clone(); + imageViewStyle.border = ((Selector)newValue)?.Clone(); }, defaultValueCreator: (bindable) => { var imageViewStyle = (ImageViewStyle)bindable; - return imageViewStyle.borderSelector; + return imageViewStyle.border; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] @@ -90,8 +90,8 @@ namespace Tizen.NUI.BaseComponents private bool? borderOnly; private bool? synchronosLoading; private bool? orientationCorrection; - private Selector resourceUrlSelector; - private Selector borderSelector; + private Selector resourceUrl; + private Selector border; static ImageViewStyle() { } @@ -136,10 +136,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector tmp = (Selector)GetValue(ResourceUrlSelectorProperty); - return (null != tmp) ? tmp : resourceUrlSelector = new Selector(); + Selector tmp = (Selector)GetValue(ResourceUrlProperty); + return (null != tmp) ? tmp : resourceUrl = new Selector(); } - set => SetValue(ResourceUrlSelectorProperty, value); + set => SetValue(ResourceUrlProperty, value); } /// @@ -151,10 +151,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector tmp = (Selector)GetValue(BorderSelectorProperty); - return (null != tmp) ? tmp : borderSelector = new Selector(); + Selector tmp = (Selector)GetValue(BorderProperty); + return (null != tmp) ? tmp : border = new Selector(); } - set => SetValue(BorderSelectorProperty, value); + set => SetValue(BorderProperty, value); } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs index a6d6977..81b932e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs @@ -511,9 +511,9 @@ namespace Tizen.NUI.BaseComponents return (hash * 23) + itemSum; } - internal bool HasMultiValue() + internal bool HasAll() { - return SelectorItems.Count > 1; + return all != null; } internal void AddWithoutDuplicationCheck(ControlState state, T value) @@ -553,67 +553,57 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public class TriggerableSelector { - private readonly BindableProperty targetBindableProperty; + private readonly Action targetPropertySetter; private Selector selector; /// /// Create an TriggerableSelector. /// - /// The TriggerableSelector will change this bindable property value when the view's ControlState has changed. - [EditorBrowsable(EditorBrowsableState.Never)] - public TriggerableSelector(BindableProperty targetBindableProperty) - { - this.targetBindableProperty = targetBindableProperty; - } - - /// - /// Return the containing selector. It can be null. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public Selector Get() => selector; - - /// - /// Update containing selector from the other selector. - /// /// The View that is affected by this TriggerableSelector. - /// The copy target. - /// Whether it updates the target view after update the selector or not. - /// Thrown when view is null. + /// The selector value. + /// The TriggerableSelector will call this setter when the view's ControlState has changed. + /// Whether it updates the target view after create a instance. + /// Thrown when given argument is null. [EditorBrowsable(EditorBrowsableState.Never)] - public void Update(View view, Selector otherSelector, bool updateView = false) + public TriggerableSelector(View view, Selector selector, Action targetPropertySetter, bool updateView = false) { - Reset(view); - - if (null == view) + if (view == null) { throw new ArgumentNullException(nameof(view)); } - if (otherSelector == null) - { - return; - } + this.selector = selector ?? throw new ArgumentNullException(nameof(selector)); + this.targetPropertySetter = targetPropertySetter ?? throw new ArgumentNullException(nameof(targetPropertySetter)); - selector = otherSelector; - - if (otherSelector.HasMultiValue()) + if (!selector.HasAll()) { view.ControlStateChangeEventInternal += OnViewControlState; } - if (updateView && otherSelector.GetValue(view.ControlState, out var value)) + if (updateView && selector.GetValue(view.ControlState, out var value)) { - view.SetValue(targetBindableProperty, value); + targetPropertySetter.Invoke(value); } } /// + /// Return the containing selector. It can be null. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Selector Get() => selector; + + /// /// Reset selector and listeners. /// /// The View that is affected by this TriggerableSelector. [EditorBrowsable(EditorBrowsableState.Never)] public void Reset(View view) { + if (selector == null) + { + return; + } + if (view != null) { view.ControlStateChangeEventInternal -= OnViewControlState; @@ -626,7 +616,7 @@ namespace Tizen.NUI.BaseComponents View view = obj as View; if (null != view && selector.GetValue(controlStateChangedInfo.CurrentState, out var value)) { - view.SetValue(targetBindableProperty, value); + targetPropertySetter.Invoke(value); } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/TextFieldStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/TextFieldStyle.cs index 7a00eeb..dd3ec94 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/TextFieldStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/TextFieldStyle.cs @@ -28,63 +28,63 @@ namespace Tizen.NUI.BaseComponents public class TextFieldStyle : ViewStyle { [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty FontFamilySelectorProperty = BindableProperty.Create("FontFamilySelector", typeof(Selector), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.fontFamilySelector = ((Selector)newValue)?.Clone(); + textFieldStyle.fontFamily = (string)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.fontFamilySelector; + return textFieldStyle.fontFamily; }); /// 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 static readonly BindableProperty PointSizeSelectorProperty = BindableProperty.Create("PointSizeSelector", typeof(Selector), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PointSizeProperty = BindableProperty.Create(nameof(PointSize), typeof(float?), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.pointSizeSelector = ((Selector)newValue)?.Clone(); + textFieldStyle.pointSize = (float?)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.pointSizeSelector; + return textFieldStyle.pointSize; }); /// 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 static readonly BindableProperty TextColorSelectorProperty = BindableProperty.Create("TextColorSelector", typeof(Selector), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.textColorSelector = ((Selector)newValue)?.Clone(); + textFieldStyle.textColor = (Color)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.textColorSelector; + return textFieldStyle.textColor; }); /// 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 static readonly BindableProperty PlaceholderTextColorSelectorProperty = BindableProperty.Create("PlaceholderTextColorSelector", typeof(Selector), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PlaceholderTextColorProperty = BindableProperty.Create(nameof(PlaceholderTextColor), typeof(Vector4), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.placeholderTextColorSelector = ((Selector)newValue)?.Clone(); + textFieldStyle.placeholderTextColor = (Vector4)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.placeholderTextColorSelector; + return textFieldStyle.placeholderTextColor; }); /// 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 static readonly BindableProperty PrimaryCursorColorSelectorProperty = BindableProperty.Create("PrimaryCursorColorSelector", typeof(Selector), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PrimaryCursorColorProperty = BindableProperty.Create(nameof(PrimaryCursorColor), typeof(Vector4), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.primaryCursorColorSelector = ((Selector)newValue)?.Clone(); + textFieldStyle.primaryCursorColor = (Vector4)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.primaryCursorColorSelector; + return textFieldStyle.primaryCursorColor; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -437,15 +437,15 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty PixelSizeSelectorProperty = BindableProperty.Create("PixelSizeSelector", typeof(float?), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PixelSizeProperty = BindableProperty.Create(nameof(PixelSize), typeof(float?), typeof(TextFieldStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var textFieldStyle = (TextFieldStyle)bindable; - textFieldStyle.pixelSizeSelector = ((Selector)newValue)?.Clone(); + textFieldStyle.pixelSize = (float?)newValue; }, defaultValueCreator: (bindable) => { var textFieldStyle = (TextFieldStyle)bindable; - return textFieldStyle.pixelSizeSelector; + return textFieldStyle.pixelSize; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] @@ -525,15 +525,15 @@ namespace Tizen.NUI.BaseComponents private string emboss; private string inputEmboss; private string inputOutline; - private Selector pixelSizeSelector; + private float? pixelSize; private bool? enableSelection; private bool? ellipsis; private bool? matchSystemLanguageDirection; - private Selector fontFamilySelector; - private Selector textColorSelector; - private Selector pointSizeSelector; - private Selector placeholderTextColorSelector; - private Selector primaryCursorColorSelector; + private string fontFamily; + private Color textColor; + private float? pointSize; + private Vector4 placeholderTextColor; + private Vector4 primaryCursorColor; private PropertyMap fontStyle; static TextFieldStyle() { } @@ -564,14 +564,10 @@ namespace Tizen.NUI.BaseComponents /// 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 Selector FontFamily + public string FontFamily { - get - { - Selector tmp = (Selector)GetValue(FontFamilySelectorProperty); - return (null != tmp) ? tmp : fontFamilySelector = new Selector(); - } - set => SetValue(FontFamilySelectorProperty, value); + get => (string)GetValue(FontFamilyProperty); + set => SetValue(FontFamilyProperty, value); } /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -789,10 +785,10 @@ namespace Tizen.NUI.BaseComponents /// 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 Selector PixelSize + public float? PixelSize { - get => (Selector)GetValue(PixelSizeSelectorProperty) ?? (pixelSizeSelector = new Selector()); - set => SetValue(PixelSizeSelectorProperty, value); + get => (float?)GetValue(PixelSizeProperty); + set => SetValue(PixelSizeProperty, value); } /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -821,38 +817,26 @@ namespace Tizen.NUI.BaseComponents /// 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 Selector TextColor + public Color TextColor { - get - { - Selector tmp = (Selector)GetValue(TextColorSelectorProperty); - return (null != tmp) ? tmp : textColorSelector = new Selector(); - } - set => SetValue(TextColorSelectorProperty, value); + get => (Color)GetValue(TextColorProperty); + set => SetValue(TextColorProperty, value); } /// 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 Selector PointSize + public float? PointSize { - get - { - Selector tmp = (Selector)GetValue(PointSizeSelectorProperty); - return (null != tmp) ? tmp : pointSizeSelector = new Selector(); - } - set => SetValue(PointSizeSelectorProperty, value); + get => (float?)GetValue(PointSizeProperty); + set => SetValue(PointSizeProperty, value); } /// 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 Selector PlaceholderTextColor + public Vector4 PlaceholderTextColor { - get - { - Selector tmp = (Selector)GetValue(PlaceholderTextColorSelectorProperty); - return (null != tmp) ? tmp : placeholderTextColorSelector = new Selector(); - } - set => SetValue(PlaceholderTextColorSelectorProperty, value); + get => (Vector4)GetValue(PlaceholderTextColorProperty); + set => SetValue(PlaceholderTextColorProperty, value); } /// @@ -861,14 +845,10 @@ namespace Tizen.NUI.BaseComponents /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public Selector PrimaryCursorColor + public Vector4 PrimaryCursorColor { - get - { - Selector tmp = (Selector)GetValue(PrimaryCursorColorSelectorProperty); - return (null != tmp) ? tmp : primaryCursorColorSelector = new Selector(); - } - set => SetValue(PrimaryCursorColorSelectorProperty, value); + get => (Vector4)GetValue(PrimaryCursorColorProperty); + set => SetValue(PrimaryCursorColorProperty, value); } /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API. diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs index e0bb5ca..3bd0ccb 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/TextLabelStyle.cs @@ -28,7 +28,7 @@ namespace Tizen.NUI.BaseComponents { /// 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 static readonly BindableProperty TranslatableTextSelectorProperty = BindableProperty.Create("TranslatableTextSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty TranslatableTextSelectorProperty = BindableProperty.Create(nameof(TranslatableText), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).translatableTextSelector = ((Selector)newValue)?.Clone(); }, @@ -38,7 +38,7 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty TextSelectorProperty = BindableProperty.Create("TextSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty TextSelectorProperty = BindableProperty.Create(nameof(Text), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).textSelector = ((Selector)newValue)?.Clone(); }, @@ -48,7 +48,7 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty FontFamilySelectorProperty = BindableProperty.Create("FontFamilySelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty FontFamilySelectorProperty = BindableProperty.Create(nameof(FontFamily), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).fontFamilySelector = ((Selector)newValue)?.Clone(); }, @@ -58,7 +58,7 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty PointSizeSelectorProperty = BindableProperty.Create("PointSizeSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PointSizeSelectorProperty = BindableProperty.Create(nameof(PointSize), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).pointSizeSelector = ((Selector)newValue)?.Clone(); }, @@ -68,7 +68,7 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty TextColorSelectorProperty = BindableProperty.Create("TextColorSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty TextColorSelectorProperty = BindableProperty.Create(nameof(TextColor), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).textColorSelector = ((Selector)newValue)?.Clone(); }, @@ -199,7 +199,7 @@ namespace Tizen.NUI.BaseComponents }); /// 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 static readonly BindableProperty PixelSizeSelectorProperty = BindableProperty.Create("PixelSizeSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty PixelSizeSelectorProperty = BindableProperty.Create(nameof(PixelSize), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).pixelSizeSelector = ((Selector)newValue)?.Clone(); }, @@ -281,7 +281,7 @@ namespace Tizen.NUI.BaseComponents }); /// A BindableProperty for ImageShadow [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty TextShadowProperty = BindableProperty.Create("TextShadowSelector", typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty TextShadowProperty = BindableProperty.Create(nameof(TextShadow), typeof(Selector), typeof(TextLabelStyle), null, propertyChanged: (bindable, oldValue, newValue) => { ((TextLabelStyle)bindable).textShadow = ((Selector)newValue)?.Clone(); }, diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index 516c446..c616500 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -78,10 +78,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector image = (Selector)GetValue(BackgroundImageSelectorProperty); + Selector image = (Selector)GetValue(BackgroundImageProperty); return (null != image) ? image : backgroundImageSelector = new Selector(); } - set => SetValue(BackgroundImageSelectorProperty, value); + set => SetValue(BackgroundImageProperty, value); } /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -107,10 +107,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector opacity = (Selector)GetValue(OpacitySelectorProperty); + Selector opacity = (Selector)GetValue(OpacityProperty); return (null != opacity) ? opacity : opacitySelector = new Selector(); } - set => SetValue(OpacitySelectorProperty, value); + set => SetValue(OpacityProperty, value); } /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -297,10 +297,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector color = (Selector)GetValue(BackgroundColorSelectorProperty); + Selector color = (Selector)GetValue(BackgroundColorProperty); return (null != color) ? color : backgroundColorSelector = new Selector(); } - set => SetValue(BackgroundColorSelectorProperty, value); + set => SetValue(BackgroundColorProperty, value); } /// @@ -309,8 +309,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public Selector Color { - get => (Selector)GetValue(ColorSelectorProperty) ?? (colorSelector = new Selector()); - set => SetValue(ColorSelectorProperty, value); + get => (Selector)GetValue(ColorProperty) ?? (colorSelector = new Selector()); + set => SetValue(ColorProperty, value); } /// View BackgroundBorder @@ -320,10 +320,10 @@ namespace Tizen.NUI.BaseComponents { get { - Selector border = (Selector)GetValue(BackgroundImageBorderSelectorProperty); + Selector border = (Selector)GetValue(BackgroundImageBorderProperty); return (null != border) ? border : backgroundImageBorderSelector = new Selector(); } - set => SetValue(BackgroundImageBorderSelectorProperty, value); + set => SetValue(BackgroundImageBorderProperty, value); } /// @@ -336,8 +336,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public Selector ImageShadow { - get => (Selector)GetValue(ImageShadowSelectorProperty); - set => SetValue(ImageShadowSelectorProperty, value); + get => (Selector)GetValue(ImageShadowProperty); + set => SetValue(ImageShadowProperty, value); } /// @@ -347,8 +347,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public Selector BoxShadow { - get => (Selector)GetValue(BoxShadowSelectorProperty); - set => SetValue(BoxShadowSelectorProperty, value); + get => (Selector)GetValue(BoxShadowProperty); + set => SetValue(BoxShadowProperty, value); } /// @@ -400,31 +400,6 @@ namespace Tizen.NUI.BaseComponents /// internal HashSet DirtyProperties { get; private set; } - /// - /// Set style's bindable properties from the view. - /// - /// The view that includes property data. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void CopyPropertiesFromView(View view) - { - if (view == null) return; - - BindableProperty.GetBindablePropertysOfType(GetType(), out var styleProperties); - BindableProperty.GetBindablePropertysOfType(view.GetType(), out var viewProperties); - - - if (styleProperties == null || viewProperties == null) return; - - foreach (var stylePropertyItem in styleProperties) - { - viewProperties.TryGetValue(stylePropertyItem.Key, out var viewProperty); - - if (viewProperty == null) continue; - - SetValue(stylePropertyItem.Value, view.GetValue(viewProperty)); - } - } - /// Create a cloned ViewStyle. [EditorBrowsable(EditorBrowsableState.Never)] public ViewStyle Clone() diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs index ba2f38e..1dba1f3 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs @@ -23,7 +23,7 @@ namespace Tizen.NUI.BaseComponents { /// Bindable property of BackgroundImage. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty BackgroundImageSelectorProperty = BindableProperty.Create("BackgroundImageSelector", typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create(nameof(BackgroundImage), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var viewStyle = (ViewStyle)bindable; @@ -64,7 +64,7 @@ namespace Tizen.NUI.BaseComponents /// Bindable property of Opacity. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty OpacitySelectorProperty = BindableProperty.Create("OpacitySelector", typeof(Selector), typeof(ViewStyle), null, + public static readonly BindableProperty OpacityProperty = BindableProperty.Create(nameof(Opacity), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => ((ViewStyle)bindable).opacitySelector = (Selector)newValue, defaultValueCreator: (bindable) => ((ViewStyle)bindable).opacitySelector ); @@ -299,7 +299,7 @@ namespace Tizen.NUI.BaseComponents /// Bindable property of BackgroundColor. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty BackgroundColorSelectorProperty = BindableProperty.Create("BackgroundColorSelector", typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var viewStyle = (ViewStyle)bindable; @@ -321,21 +321,21 @@ namespace Tizen.NUI.BaseComponents /// Bindable property of ColorSelector. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ColorSelectorProperty = BindableProperty.Create("ColorSelector", typeof(Selector), typeof(ViewStyle), null, + public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => ((ViewStyle)bindable).colorSelector = (Selector)newValue, defaultValueCreator: (bindable) => ((ViewStyle)bindable).colorSelector ); /// Bindable property of BackgroundImageBorder. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty BackgroundImageBorderSelectorProperty = BindableProperty.Create("BackgroundImageBorderSelector", typeof(Selector), typeof(ViewStyle), null, + public static readonly BindableProperty BackgroundImageBorderProperty = BindableProperty.Create(nameof(BackgroundImageBorder), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => ((ViewStyle)bindable).backgroundImageBorderSelector = (Selector)newValue, defaultValueCreator: (bindable) => ((ViewStyle)bindable).backgroundImageBorderSelector ); /// Bindable property of ImageShadow. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ImageShadowSelectorProperty = BindableProperty.Create("ImageShadowSelector", typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty ImageShadowProperty = BindableProperty.Create(nameof(ImageShadow), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var viewStyle = (ViewStyle)bindable; @@ -354,7 +354,7 @@ namespace Tizen.NUI.BaseComponents /// Bindable property of BoxShadow. Please do not open it. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty BoxShadowSelectorProperty = BindableProperty.Create("BoxShadowSelector", typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty BoxShadowProperty = BindableProperty.Create(nameof(BoxShadow), typeof(Selector), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) => { var viewStyle = (ViewStyle)bindable; diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index 47ba1b8..ec800c7 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019 Samsung Electronics Co., Ltd. + * 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. @@ -35,7 +35,6 @@ namespace Tizen.NUI.BaseComponents private string textFieldPlaceHolderTextFocusedSid = null; private bool systemlangTextFlag = false; private InputMethodContext inputMethodCotext = null; - private TextFieldSelectorData selectorData; private float fontSizeScale = 1.0f; private bool hasFontSizeChangedCallback = false; @@ -119,7 +118,6 @@ namespace Tizen.NUI.BaseComponents } set { - selectorData?.TranslatableText?.Reset(this); SetValue(TranslatableTextProperty, value); } } @@ -158,7 +156,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TranslatablePlaceholderTextProperty, value); - selectorData?.TranslatablePlaceholderText?.Reset(this); } } private string translatablePlaceholderText @@ -197,7 +194,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TranslatablePlaceholderTextFocusedProperty, value); - selectorData?.TranslatablePlaceholderTextFocused?.Reset(this); } } private string translatablePlaceholderTextFocused @@ -231,7 +227,6 @@ namespace Tizen.NUI.BaseComponents set { SetValueAndForceSendChangeSignal(TextProperty, value); - selectorData?.Text?.Reset(this); NotifyPropertyChanged(); } } @@ -283,7 +278,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(FontFamilyProperty, value); - selectorData?.FontFamily?.Reset(this); NotifyPropertyChanged(); } } @@ -318,7 +312,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PointSizeProperty, value); - selectorData?.PointSize?.Reset(this); NotifyPropertyChanged(); } } @@ -409,7 +402,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextColorProperty, value); - selectorData?.TextColor?.Reset(this); NotifyPropertyChanged(); } } @@ -431,7 +423,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PlaceholderTextColorProperty, value); - selectorData?.PlaceholderTextColor?.Reset(this); NotifyPropertyChanged(); } } @@ -509,7 +500,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PrimaryCursorColorProperty, value); - selectorData?.PrimaryCursorColor?.Reset(this); NotifyPropertyChanged(); } } @@ -1087,7 +1077,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(PixelSizeProperty, value); - selectorData?.PixelSize?.Reset(this); NotifyPropertyChanged(); } } @@ -1433,8 +1422,6 @@ namespace Tizen.NUI.BaseComponents } } - private TextFieldSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new TextFieldSelectorData()); - /// /// Get the InputMethodContext instance. /// @@ -1511,7 +1498,6 @@ namespace Tizen.NUI.BaseComponents //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. - selectorData?.Reset(this); } //Release your own unmanaged resources here. diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs index 209b6cc..b332ed7 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019 Samsung Electronics Co., Ltd. + * 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. @@ -1023,141 +1023,5 @@ namespace Tizen.NUI.BaseComponents Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)textField.SwigCPtr, TextField.Property.GrabHandleColor).Get(temp); return temp; })); - - #region Selectors - internal static readonly BindableProperty TranslatableTextSelectorProperty = BindableProperty.Create("TranslatableTextSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureTranslatableText().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.TranslatableText, TextField.TranslatableTextProperty); - }); - internal static readonly BindableProperty TranslatablePlaceholderTextSelectorProperty = BindableProperty.Create("TranslatablePlaceholderTextSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureTranslatablePlaceholderText().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.TranslatablePlaceholderText, TextField.TranslatablePlaceholderTextProperty); - }); - internal static readonly BindableProperty TranslatablePlaceholderTextFocusedSelectorProperty = BindableProperty.Create("TranslatablePlaceholderTextFocusedSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureTranslatablePlaceholderTextFocused().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.TranslatablePlaceholderTextFocused, TextField.TranslatablePlaceholderTextFocusedProperty); - }); - internal static readonly BindableProperty TextSelectorProperty = BindableProperty.Create("TextSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureText().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.Text, TextField.TextProperty); - }); - internal static readonly BindableProperty FontFamilySelectorProperty = BindableProperty.Create("FontFamilySelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureFontFamily().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.FontFamily, TextField.FontFamilyProperty); - }); - internal static readonly BindableProperty PointSizeSelectorProperty = BindableProperty.Create("PointSizeSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsurePointSize().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.PointSize, TextField.PointSizeProperty); - }); - internal static readonly BindableProperty PixelSizeSelectorProperty = BindableProperty.Create("PixelSizeSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsurePixelSize().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - return textField.GetSelector(textField.selectorData?.PixelSize, TextField.PixelSizeProperty); - }); - internal static readonly BindableProperty TextColorSelectorProperty = BindableProperty.Create("TextColorSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsureTextColor().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - var selector = textField.selectorData?.TextColor?.Get(); - if (selector != null) - { - return selector; - } - - Color color = new Color(); - if (!textField.GetProperty(TextField.Property.TextColor).Get(color)) - { - return null; - } - return new Selector(color); - }); - internal static readonly BindableProperty PlaceholderTextColorSelectorProperty = BindableProperty.Create("PlaceholderTextColorSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsurePlaceholderTextColor().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - var selector = textField.selectorData?.PlaceholderTextColor?.Get(); - if (selector != null) - { - return selector; - } - - Color color = new Color(); - if (!textField.GetProperty(TextField.Property.PlaceholderTextColor).Get(color)) - { - return null; - } - return new Selector(color); - }); - internal static readonly BindableProperty PrimaryCursorColorSelectorProperty = BindableProperty.Create("PrimaryCursorColorSelector", typeof(Selector), typeof(TextField), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textField = (TextField)bindable; - textField.EnsureSelectorData().EnsurePrimaryCursorColor().Update(textField, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var textField = (TextField)bindable; - var selector = textField.selectorData?.PrimaryCursorColor?.Get(); - if (selector != null) - { - return selector; - } - - Color color = new Color(); - if (!textField.GetProperty(TextField.Property.PrimaryCursorColor).Get(color)) - { - return null; - } - return new Selector(color); - }); - #endregion } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldSelectorData.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldSelectorData.cs deleted file mode 100755 index 1a73502..0000000 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldSelectorData.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright(c) 2020 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. - * - */ - -namespace Tizen.NUI.BaseComponents -{ - /// - /// The class storing extra data for a TextField to optimize size of it. - /// - internal class TextFieldSelectorData - { - public TriggerableSelector TranslatableText { get; private set; } - public TriggerableSelector Text { get; private set; } - public TriggerableSelector FontFamily { get; private set; } - public TriggerableSelector TextColor { get; private set; } - public TriggerableSelector PointSize { get; private set; } - public TriggerableSelector PixelSize { get; private set; } - public TriggerableSelector TranslatablePlaceholderText { get; private set; } - public TriggerableSelector TranslatablePlaceholderTextFocused { get; private set; } - public TriggerableSelector PlaceholderTextColor { get; private set; } - public TriggerableSelector PrimaryCursorColor { get; private set; } - - public TriggerableSelector EnsureTranslatableText() => TranslatableText ?? (TranslatableText = new TriggerableSelector(TextField.TranslatableTextProperty)); - public TriggerableSelector EnsureText() => Text ?? (Text = new TriggerableSelector(TextField.TextProperty)); - public TriggerableSelector EnsureFontFamily() => FontFamily ?? (FontFamily = new TriggerableSelector(TextField.FontFamilyProperty)); - public TriggerableSelector EnsureTextColor() => TextColor ?? (TextColor = new TriggerableSelector(TextField.TextColorProperty)); - public TriggerableSelector EnsurePointSize() => PointSize ?? (PointSize = new TriggerableSelector(TextField.PointSizeProperty)); - public TriggerableSelector EnsurePixelSize() => PixelSize ?? (PixelSize = new TriggerableSelector(TextField.PixelSizeProperty)); - public TriggerableSelector EnsureTranslatablePlaceholderText() => TranslatablePlaceholderText ?? (TranslatablePlaceholderText = new TriggerableSelector(TextField.TranslatablePlaceholderTextProperty)); - public TriggerableSelector EnsureTranslatablePlaceholderTextFocused() => TranslatablePlaceholderTextFocused ?? (TranslatablePlaceholderTextFocused = new TriggerableSelector(TextField.TranslatablePlaceholderTextFocusedProperty)); - public TriggerableSelector EnsurePlaceholderTextColor() => PlaceholderTextColor ?? (PlaceholderTextColor = new TriggerableSelector(TextField.PlaceholderTextColorProperty)); - public TriggerableSelector EnsurePrimaryCursorColor() => PrimaryCursorColor ?? (PrimaryCursorColor = new TriggerableSelector(TextField.PrimaryCursorColorProperty)); - - public void Reset(View view) - { - TranslatableText?.Reset(view); - Text?.Reset(view); - FontFamily?.Reset(view); - TextColor?.Reset(view); - PointSize?.Reset(view); - PixelSize?.Reset(view); - TranslatablePlaceholderText?.Reset(view); - TranslatablePlaceholderTextFocused?.Reset(view); - PlaceholderTextColor?.Reset(view); - PrimaryCursorColor?.Reset(view); - } - } -} diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index dcc903c..c989f02 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -186,7 +186,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TranslatableTextProperty, value); - selectorData?.TranslatableText?.Reset(this); } } private string translatableText @@ -367,7 +366,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextColorProperty, value); - selectorData?.TextColor?.Reset(this); NotifyPropertyChanged(); } } @@ -684,7 +682,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(TextShadowProperty, value); - selectorData?.TextShadow?.Reset(this); NotifyPropertyChanged(); } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs index e795e8e..a77a2d4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * 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. @@ -35,9 +35,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty TranslatableTextProperty = BindableProperty.Create(nameof(TranslatableText), typeof(string), typeof(TextLabel), string.Empty, propertyChanged: (bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.TranslatableTextSelector = selector; + } + else { - textLabel.translatableText = (string)newValue; + textLabel.selectorData?.TranslatableText?.Reset(textLabel); + textLabel.SetTranslatableText((string)newValue); } }, defaultValueCreator: (bindable) => @@ -50,11 +56,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(TextLabel), string.Empty, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.TextSelector = selector; + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue((string)newValue)); textLabel.selectorData?.Text?.Reset(textLabel); - textLabel.RequestLayout(); + textLabel.SetText((string)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -69,11 +79,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(TextLabel), string.Empty, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.FontFamilySelector = selector; + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, TextLabel.Property.FontFamily, new Tizen.NUI.PropertyValue((string)newValue)); textLabel.selectorData?.FontFamily?.Reset(textLabel); - textLabel.RequestLayout(); + textLabel.SetFontFamily((string)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -106,11 +120,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty PointSizeProperty = BindableProperty.Create(nameof(PointSize), typeof(float), typeof(TextLabel), default(float), propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.PointSizeSelector = selector; + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, TextLabel.Property.PointSize, new Tizen.NUI.PropertyValue((float)newValue)); textLabel.selectorData?.PointSize?.Reset(textLabel); - textLabel.RequestLayout(); + textLabel.SetPointSize((float?)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -188,9 +206,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TextLabel), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.TextColorSelector = selector; + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, TextLabel.Property.TextColor, new Tizen.NUI.PropertyValue((Color)newValue)); + textLabel.selectorData?.TextColor?.Reset(textLabel); + textLabel.SetTextColor((Color)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -343,9 +367,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty TextShadowProperty = BindableProperty.Create(nameof(TextShadow), typeof(TextShadow), typeof(TextLabel), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.TextShadowSelector = selector; + } + else { - Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, Property.SHADOW, TextShadow.ToPropertyValue((TextShadow)newValue)); + textLabel.selectorData?.TextShadow?.Reset(textLabel); + textLabel.SetTextShadow((TextShadow)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -394,11 +424,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty PixelSizeProperty = BindableProperty.Create(nameof(PixelSize), typeof(float), typeof(TextLabel), default(float), propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var textLabel = (TextLabel)bindable; - if (newValue != null) + + if (newValue is Selector selector) + { + textLabel.PixelSizeSelector = selector; + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textLabel.SwigCPtr, TextLabel.Property.PixelSize, new Tizen.NUI.PropertyValue((float)newValue)); textLabel.selectorData?.PixelSize?.Reset(textLabel); - textLabel.RequestLayout(); + textLabel.SetPixelSize((float?)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -575,91 +609,169 @@ namespace Tizen.NUI.BaseComponents return temp; })); - #region Selectors - internal static readonly BindableProperty TranslatableTextSelectorProperty = BindableProperty.Create("TranslatableTextSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsureTranslatableText().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + internal Selector TranslatableTextSelector { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.TranslatableText, TextLabel.TranslatableTextProperty); - }); - internal static readonly BindableProperty TextSelectorProperty = BindableProperty.Create("TextSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => - { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsureText().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + get => GetSelector(selectorData?.TranslatableText, TextLabel.TranslatableTextProperty); + set + { + selectorData?.TranslatableText?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetTranslatableText(value.All); + else EnsureSelectorData().TranslatableText = new TriggerableSelector(this, value, SetTranslatableText, true); + } + } + + internal Selector TextSelector { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.Text, TextLabel.TextProperty); - }); - internal static readonly BindableProperty FontFamilySelectorProperty = BindableProperty.Create("FontFamilySelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => + get => GetSelector(selectorData?.Text, TextLabel.TextProperty); + set + { + selectorData?.Text?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetText(value.All); + else EnsureSelectorData().Text = new TriggerableSelector(this, value, SetText, true); + } + } + + internal Selector FontFamilySelector { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsureFontFamily().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + get => GetSelector(selectorData?.FontFamily, TextLabel.FontFamilyProperty); + set + { + selectorData?.FontFamily?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetFontFamily(value.All); + else EnsureSelectorData().FontFamily = new TriggerableSelector(this, value, SetFontFamily, true); + } + } + + internal Selector PointSizeSelector { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.FontFamily, TextLabel.FontFamilyProperty); - }); - internal static readonly BindableProperty PointSizeSelectorProperty = BindableProperty.Create("PointSizeSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => + get => GetSelector(selectorData?.PointSize, TextLabel.PointSizeProperty); + set + { + selectorData?.PointSize?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetPointSize(value.All); + else EnsureSelectorData().PointSize = new TriggerableSelector(this, value, SetPointSize, true); + } + } + + internal Selector TextColorSelector { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsurePointSize().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + get + { + var selector = selectorData?.TextColor?.Get(); + if (selector != null) + { + return selector; + } + + Color color = new Color(); + if (!GetProperty(TextLabel.Property.TextColor).Get(color)) + { + return null; + } + return new Selector(color); + } + set + { + selectorData?.TextColor?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetTextColor(value.All); + else EnsureSelectorData().TextColor = new TriggerableSelector(this, value, SetTextColor, true); + } + } + + internal Selector PixelSizeSelector { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.PointSize, TextLabel.PointSizeProperty); - }); - internal static readonly BindableProperty TextColorSelectorProperty = BindableProperty.Create("TextColorSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => + get => GetSelector(selectorData?.PixelSize, TextLabel.PixelSizeProperty); + set + { + selectorData?.PixelSize?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetPixelSize(value.All); + else EnsureSelectorData().PixelSize = new TriggerableSelector(this, value, SetPixelSize, true); + } + } + + internal Selector TextShadowSelector { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsureTextColor().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + get => GetSelector(selectorData?.TextShadow, TextLabel.TextShadowProperty); + set + { + selectorData?.TextShadow?.Reset(this); + if (value == null) return; + + if (value.HasAll()) SetTextShadow(value.All); + else EnsureSelectorData().TextShadow = new TriggerableSelector(this, value, SetTextShadow); + } + } + + private void SetTranslatableText(string value) { - var textLabel = (TextLabel)bindable; - var selector = textLabel.selectorData?.TextColor?.Get(); - if (selector != null) + if (value != null) { - return selector; + translatableText = value; } + } - Color color = new Color(); - if (!textLabel.GetProperty(TextLabel.Property.TextColor).Get(color)) + private void SetText(string value) + { + if (value != null) { - return null; + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, TextLabel.Property.TEXT, new Tizen.NUI.PropertyValue(value)); + RequestLayout(); } - return new Selector(color); - }); + } - internal static readonly BindableProperty TextShadowSelectorProperty = BindableProperty.Create("TextShadowSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => + private void SetFontFamily(string value) { - var textLabel = (TextLabel)bindable; - textLabel.EnsureSelectorData().EnsureTextShadow().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + if (value != null) + { + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, TextLabel.Property.FontFamily, new Tizen.NUI.PropertyValue(value)); + RequestLayout(); + } + } + + private void SetTextColor(Color value) { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.TextShadow, TextLabel.TextShadowProperty); - }); + if (value != null) + { + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, TextLabel.Property.TextColor, new Tizen.NUI.PropertyValue(value)); + } + } - internal static readonly BindableProperty PixelSizeSelectorProperty = BindableProperty.Create("PixelSizeSelector", typeof(Selector), typeof(TextLabel), null, propertyChanged: (bindable, oldValue, newValue) => + private void SetPointSize(float? value) { - var textLabel = (TextLabel)bindable; - ((TextLabel)bindable).EnsureSelectorData().EnsurePixelSize().Update(textLabel, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => + if (value != null) + { + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, TextLabel.Property.PointSize, new Tizen.NUI.PropertyValue((float)value)); + RequestLayout(); + } + } + + private void SetPixelSize(float? value) { - var textLabel = (TextLabel)bindable; - return textLabel.GetSelector(textLabel.selectorData?.PixelSize, TextLabel.PixelSizeProperty); - }); - #endregion + if (value != null) + { + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, TextLabel.Property.PixelSize, new Tizen.NUI.PropertyValue((float)value)); + RequestLayout(); + } + } + private void SetTextShadow(TextShadow value) + { + if (value != null) + { + Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, Property.SHADOW, TextShadow.ToPropertyValue(value)); + } + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabelSelectorData.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabelSelectorData.cs index 09f7699..24da1a4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabelSelectorData.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabelSelectorData.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * 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. @@ -15,6 +15,9 @@ * */ +using System; +using System.Diagnostics; + namespace Tizen.NUI.BaseComponents { /// @@ -22,21 +25,13 @@ namespace Tizen.NUI.BaseComponents /// internal class TextLabelSelectorData { - public TriggerableSelector TranslatableText { get; private set; } - public TriggerableSelector Text { get; private set; } - public TriggerableSelector FontFamily { get; private set; } - public TriggerableSelector TextColor { get; private set; } - public TriggerableSelector PointSize { get; private set; } - public TriggerableSelector PixelSize { get; private set; } - public TriggerableSelector TextShadow { get; private set; } - - public TriggerableSelector EnsureTranslatableText() => TranslatableText ?? (TranslatableText = new TriggerableSelector(TextLabel.TranslatableTextProperty)); - public TriggerableSelector EnsureText() => Text ?? (Text = new TriggerableSelector(TextLabel.TextProperty)); - public TriggerableSelector EnsureFontFamily() => FontFamily ?? (FontFamily = new TriggerableSelector(TextLabel.FontFamilyProperty)); - public TriggerableSelector EnsureTextColor() => TextColor ?? (TextColor = new TriggerableSelector(TextLabel.TextColorProperty)); - public TriggerableSelector EnsurePointSize() => PointSize ?? (PointSize = new TriggerableSelector(TextLabel.PointSizeProperty)); - public TriggerableSelector EnsurePixelSize() => PixelSize ?? (PixelSize = new TriggerableSelector(TextLabel.PixelSizeProperty)); - public TriggerableSelector EnsureTextShadow() => TextShadow ?? (TextShadow = new TriggerableSelector(TextLabel.TextShadowProperty)); + public TriggerableSelector TranslatableText { get; set; } + public TriggerableSelector Text { get; set; } + public TriggerableSelector FontFamily { get; set; } + public TriggerableSelector TextColor { get; set; } + public TriggerableSelector PointSize { get; set; } + public TriggerableSelector PixelSize { get; set; } + public TriggerableSelector TextShadow { get; set; } public virtual void Reset(View view) { diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index d761c21..8543c7f 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Runtime.InteropServices; using Tizen.NUI.Binding; -using Tizen.NUI.Components; namespace Tizen.NUI.BaseComponents { @@ -318,11 +317,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(BackgroundColorProperty, value); - if (selectorData != null) - { - selectorData.BackgroundImage?.Reset(this); - selectorData.BackgroundColor?.Reset(this); - } NotifyPropertyChanged(); } } @@ -340,11 +334,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(BackgroundImageProperty, value); - if (selectorData != null) - { - selectorData.BackgroundColor?.Reset(this); - selectorData.BackgroundImage?.Reset(this); - } NotifyPropertyChanged(); } } @@ -363,7 +352,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(BackgroundImageBorderProperty, value); - selectorData?.BackgroundImageBorder?.Reset(this); NotifyPropertyChanged(); } } @@ -415,11 +403,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(ImageShadowProperty, value); - if (selectorData != null) - { - selectorData.BoxShadow?.Reset(this); - selectorData.ImageShadow?.Reset(this); - } NotifyPropertyChanged(); } } @@ -454,11 +437,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(BoxShadowProperty, value); - if (selectorData != null) - { - selectorData.ImageShadow?.Reset(this); - selectorData.BoxShadow?.Reset(this); - } NotifyPropertyChanged(); } } @@ -1091,7 +1069,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(OpacityProperty, value); - selectorData?.Opacity?.Reset(this); NotifyPropertyChanged(); } } @@ -2394,7 +2371,6 @@ namespace Tizen.NUI.BaseComponents set { SetValue(ColorProperty, value); - selectorData?.Color?.Reset(this); NotifyPropertyChanged(); } } @@ -2696,11 +2672,6 @@ namespace Tizen.NUI.BaseComponents return false; } - if (styleProperty.ReturnType.IsGenericType && styleProperty.ReturnType.GetGenericTypeDefinition() == typeof(Selector<>)) - { - return dirtyPropertySet.Contains(styleProperty.PropertyName.Substring(0, styleProperty.PropertyName.Length - 8)); - } - return dirtyPropertySet.Contains(styleProperty.PropertyName); } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index 32038e7..f94516c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -81,26 +81,17 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(View), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var view = (View)bindable; - if (newValue != null) - { - if (view.backgroundExtraData == null) - { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue((Color)newValue)); - return; - } - - PropertyMap map = new PropertyMap(); - - // TODO Fix to support Vector4 for corner radius after dali support it. - // Current code only gets first argument of Vector4. - float cornerRadius = view.backgroundExtraData.CornerRadius?.X ?? 0.0f; - map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color)) - .Add(ColorVisualProperty.MixColor, new PropertyValue((Color)newValue)) - .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) - .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(view.backgroundExtraData.CornerRadiusPolicy))); + view.selectorData?.ClearBackground(view); - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); + if (newValue is Selector selector) + { + if (selector.HasAll()) view.SetBackgroundColor(selector.All); + else view.EnsureSelectorData().BackgroundColor = new TriggerableSelector(view, selector, view.SetBackgroundColor, true); + } + else + { + view.SetBackgroundColor((Color)newValue); } }), defaultValueCreator: (bindable) => @@ -126,7 +117,15 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => { var view = (View)bindable; - if (newValue != null) + + view.selectorData?.Color?.Reset(view); + + if (newValue is Selector selector) + { + if (selector.HasAll()) view.SetColor(selector.All); + else view.EnsureSelectorData().Color = new TriggerableSelector(view, selector, view.SetColor, true); + } + else { view.SetColor((Color)newValue); } @@ -138,57 +137,27 @@ namespace Tizen.NUI.BaseComponents view.GetProperty(Interop.ActorProperty.ColorGet()).Get(color); return color; }); - /// BackgroundImageProperty [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create(nameof(BackgroundImage), typeof(string), typeof(View), default(string), propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { var view = (View)bindable; - string url = (string)newValue; - if (string.IsNullOrEmpty(url)) + if (view.selectorData != null) { - // Clear background - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue()); - return; + view.selectorData.BackgroundColor?.Reset(view); + view.selectorData.BackgroundImage?.Reset(view); } - if (url.StartsWith("*Resource*")) + if (newValue is Selector selector) { - string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource; - url = url.Replace("*Resource*", resource); - } - - if (view.backgroundExtraData == null) - { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue(url)); - view.BackgroundImageSynchronosLoading = view.backgroundImageSynchronosLoading; - - return; - } - - PropertyMap map = new PropertyMap(); - - // TODO Fix to support Vector4 for corner radius after dali support it. - // Current code only gets first argument of Vector4. - float cornerRadius = view.backgroundExtraData.CornerRadius?.X ?? 0.0f; - - map.Add(ImageVisualProperty.URL, new PropertyValue(url)) - .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) - .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(view.backgroundExtraData.CornerRadiusPolicy))) - .Add(ImageVisualProperty.SynchronousLoading, new PropertyValue(view.backgroundImageSynchronosLoading)); - - if (view.backgroundExtraData.BackgroundImageBorder != null) - { - map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch)) - .Add(NpatchImageVisualProperty.Border, new PropertyValue(view.backgroundExtraData.BackgroundImageBorder)); + if (selector.HasAll()) view.SetBackgroundImage(selector.All); + else view.EnsureSelectorData().BackgroundImage = new TriggerableSelector(view, selector, view.SetBackgroundImage, true); } else { - map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); + view.SetBackgroundImage((string)newValue); } - - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); }), defaultValueCreator: (bindable) => { @@ -206,37 +175,17 @@ namespace Tizen.NUI.BaseComponents { var view = (View)bindable; - bool isEmptyValue = Rectangle.IsNullOrZero((Rectangle)newValue); + view.selectorData?.BackgroundImageBorder?.Reset(view); - var backgroundImageBorder = isEmptyValue ? null : (Rectangle)newValue; - - (view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).BackgroundImageBorder = backgroundImageBorder; - - if (isEmptyValue) + if (newValue is Selector selector) { - return; + if (selector.HasAll()) view.SetBackgroundImageBorder(selector.All); + else view.EnsureSelectorData().BackgroundImageBorder = new TriggerableSelector(view, selector, view.SetBackgroundImageBorder, true); } - - PropertyMap map = view.Background; - - if (map.Empty()) - { - return; - } - - map[NpatchImageVisualProperty.Border] = new PropertyValue(backgroundImageBorder); - - int visualType = 0; - - map.Find(Visual.Property.Type)?.Get(out visualType); - - if (visualType == (int)Visual.Type.Image) + else { - map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch); + view.SetBackgroundImageBorder((Rectangle)newValue); } - - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); - }), defaultValueCreator: (bindable) => { @@ -650,9 +599,16 @@ namespace Tizen.NUI.BaseComponents { var view = (View)bindable; - if (newValue != null) + view.selectorData?.Opacity?.Reset(view); + + if (newValue is Selector selector) + { + if (selector.HasAll()) view.SetOpacity(selector.All); + else view.EnsureSelectorData().Opacity = new TriggerableSelector(view, selector, view.SetOpacity, true); + } + else { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.OPACITY, new Tizen.NUI.PropertyValue((float)newValue)); + view.SetOpacity((float?)newValue); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -1541,9 +1497,19 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty ImageShadowProperty = BindableProperty.Create(nameof(ImageShadow), typeof(ImageShadow), typeof(View), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { - var shadow = (ImageShadow)newValue; var view = (View)bindable; - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SHADOW, shadow == null ? new PropertyValue() : shadow.ToPropertyValue(view)); + + view.selectorData?.ClearShadow(view); + + if (newValue is Selector selector) + { + if (selector.HasAll()) view.SetShadow(selector.All); + else view.EnsureSelectorData().ImageShadow = new TriggerableSelector(view, selector, view.SetShadow, true); + } + else + { + view.SetShadow((ImageShadow)newValue); + } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => { @@ -1562,9 +1528,19 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty BoxShadowProperty = BindableProperty.Create(nameof(BoxShadow), typeof(Shadow), typeof(View), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => { - var shadow = (Shadow)newValue; var view = (View)bindable; - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SHADOW, shadow == null ? new PropertyValue() : shadow.ToPropertyValue(view)); + + view.selectorData?.ClearShadow(view); + + if (newValue is Selector selector) + { + if (selector.HasAll()) view.SetShadow(selector.All); + else view.EnsureSelectorData().BoxShadow = new TriggerableSelector(view, selector, view.SetShadow, true); + } + else + { + view.SetShadow((Shadow)newValue); + } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => { @@ -1793,130 +1769,139 @@ namespace Tizen.NUI.BaseComponents return temp; }); - #region Selectors - internal static readonly BindableProperty BackgroundImageSelectorProperty = BindableProperty.Create("BackgroundImageSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => - { - var view = (View)bindable; - view.EnsureSelectorData().EnsureBackgroundImage().Update(view, (Selector)newValue, true); - if (newValue != null) view.EnsureSelectorData().BackgroundColor?.Reset(view); - }, - defaultValueCreator: (bindable) => + private void SetBackgroundImage(string value) { - var view = (View)bindable; - var selector = view.selectorData?.BackgroundImage?.Get(); - if (selector != null) + if (string.IsNullOrEmpty(value)) { - return selector; + // Clear background + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue()); + return; } - string backgroundImage = null; - view.Background.Find(ImageVisualProperty.URL)?.Get(out backgroundImage); - return backgroundImage == null ? null : new Selector(backgroundImage); - }); + if (value.StartsWith("*Resource*")) + { + string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource; + value = value.Replace("*Resource*", resource); + } - internal static readonly BindableProperty BackgroundColorSelectorProperty = BindableProperty.Create("BackgroundColorSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => - { - var view = (View)bindable; - view.EnsureSelectorData().EnsureBackgroundColor().Update(view, (Selector)newValue, true); - if (newValue != null) view.EnsureSelectorData().BackgroundImage?.Reset(view); - }, - defaultValueCreator: (bindable) => - { - var view = (View)bindable; - var selector = view.selectorData?.BackgroundColor?.Get(); - if (selector != null) + if (backgroundExtraData == null) { - return selector; + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(value)); + BackgroundImageSynchronosLoading = backgroundImageSynchronosLoading; + + return; } - var background = view.Background; - int visualType = 0; - background.Find(Visual.Property.Type)?.Get(out visualType); - if (visualType != (int)Visual.Type.Color) + PropertyMap map = new PropertyMap(); + + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = backgroundExtraData.CornerRadius?.X ?? 0.0f; + + map.Add(ImageVisualProperty.URL, new PropertyValue(value)) + .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) + .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy))) + .Add(ImageVisualProperty.SynchronousLoading, new PropertyValue(backgroundImageSynchronosLoading)); + + if (backgroundExtraData.BackgroundImageBorder != null) { - return null; + map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch)) + .Add(NpatchImageVisualProperty.Border, new PropertyValue(backgroundExtraData.BackgroundImageBorder)); + } + else + { + map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); } - Color backgroundColor = new Color(); - background.Find(ColorVisualProperty.MixColor)?.Get(backgroundColor); - return new Selector(backgroundColor); - }); + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); + } - internal static readonly BindableProperty BackgroundImageBorderSelectorProperty = BindableProperty.Create("BackgroundImageBorderSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => + private void SetBackgroundImageBorder(Rectangle value) { - var view = (View)bindable; - view.EnsureSelectorData().EnsureBackgroundImageBorder().Update(view, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var view = (View)bindable; - return view.GetSelector(view.selectorData?.BackgroundImageBorder, View.BackgroundImageBorderProperty); - }); + bool isEmptyValue = Rectangle.IsNullOrZero(value); - internal static readonly BindableProperty ColorSelectorProperty = BindableProperty.Create("ColorSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => - { - var view = (View)bindable; - view.EnsureSelectorData().EnsureColor().Update(view, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var view = (View)bindable; - var selector = view.selectorData?.Color?.Get(); - if (selector != null) + var backgroundImageBorder = isEmptyValue ? null : value; + + (backgroundExtraData ?? (backgroundExtraData = new BackgroundExtraData())).BackgroundImageBorder = backgroundImageBorder; + + if (isEmptyValue) { - return selector; + return; } - Color color = new Color(); - if (!view.GetProperty(Interop.ActorProperty.ColorGet()).Get(color)) + PropertyMap map = Background; + + if (map.Empty()) { - return null; + return; } - return new Selector(color); - }); - internal static readonly BindableProperty OpacitySelectorProperty = BindableProperty.Create("OpacitySelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => - { - var view = (View)bindable; - view.EnsureSelectorData().EnsureOpacity().Update(view, (Selector)newValue, true); - }, - defaultValueCreator: (bindable) => - { - var view = (View)bindable; - return view.GetSelector(view.selectorData?.Opacity, View.OpacityProperty); - }); + map[NpatchImageVisualProperty.Border] = new PropertyValue(backgroundImageBorder); - /// - /// ImageShadow Selector Property for binding to ViewStyle - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ImageShadowSelectorProperty = BindableProperty.Create("ImageShadowSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => + int visualType = 0; + + map.Find(Visual.Property.Type)?.Get(out visualType); + + if (visualType == (int)Visual.Type.Image) + { + map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch); + } + + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); + } + + private void SetBackgroundColor(Color value) { - var view = (View)bindable; - view.EnsureSelectorData().EnsureImageShadow().Update(view, (Selector)newValue, true); - if (newValue != null) view.EnsureSelectorData().BoxShadow?.Reset(view); - }, - defaultValueCreator: (bindable) => + if (value == null) + { + return; + } + + if (backgroundExtraData == null) + { + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(value)); + return; + } + + PropertyMap map = new PropertyMap(); + + // TODO Fix to support Vector4 for corner radius after dali support it. + // Current code only gets first argument of Vector4. + float cornerRadius = backgroundExtraData.CornerRadius?.X ?? 0.0f; + + map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color)) + .Add(ColorVisualProperty.MixColor, new PropertyValue(value)) + .Add(Visual.Property.CornerRadius, new PropertyValue(cornerRadius)) + .Add(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy))); + + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map)); + } + + private void SetColor(Color value) { - var view = (View)bindable; - return view.GetSelector(view.selectorData?.ImageShadow, View.ImageShadowProperty); - }); + if (value == null) + { + return; + } - /// - /// BoxShadow Selector Property for binding to ViewStyle - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty BoxShadowSelectorProperty = BindableProperty.Create("BoxShadowSelector", typeof(Selector), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) => + Interop.ActorInternal.SetColor(SwigCPtr, value.SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + private void SetOpacity(float? value) { - var view = (View)bindable; - view.EnsureSelectorData().EnsureBoxShadow().Update(view, (Selector)newValue, true); - if (newValue != null) view.EnsureSelectorData().ImageShadow?.Reset(view); - }, - defaultValueCreator: (bindable) => + if (value == null) + { + return; + } + + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.OPACITY, new Tizen.NUI.PropertyValue((float)value)); + } + + private void SetShadow(ShadowBase value) { - var view = (View)bindable; - return view.GetSelector(view.selectorData?.BoxShadow, View.BoxShadowProperty); - }); - #endregion + Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.SHADOW, value == null ? new PropertyValue() : value.ToPropertyValue(this)); + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index e4b0d75..431860e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -826,13 +826,6 @@ namespace Tizen.NUI.BaseComponents return ret; } - internal void SetColor(Vector4 color) - { - Interop.ActorInternal.SetColor(SwigCPtr, Vector4.getCPtr(color)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - internal Vector4 GetCurrentColor() { Vector4 ret = new Vector4(Interop.ActorInternal.GetCurrentColor(SwigCPtr), true); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewSelectorData.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewSelectorData.cs index 4801fab..cb791c6 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewSelectorData.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewSelectorData.cs @@ -15,6 +15,9 @@ * */ +using System; +using System.Diagnostics; + namespace Tizen.NUI.BaseComponents { /// @@ -24,21 +27,30 @@ namespace Tizen.NUI.BaseComponents { internal ViewSelectorData() { } - public TriggerableSelector BackgroundColor { get; private set; } - public TriggerableSelector BackgroundImage { get; private set; } - public TriggerableSelector BackgroundImageBorder { get; private set; } - public TriggerableSelector Color { get; private set; } - public TriggerableSelector Opacity { get; private set; } - public TriggerableSelector ImageShadow { get; private set; } - public TriggerableSelector BoxShadow { get; private set; } + public TriggerableSelector BackgroundColor{ get; set; } + public TriggerableSelector BackgroundImage{ get; set; } + public TriggerableSelector BackgroundImageBorder{ get; set; } + public TriggerableSelector Color{ get; set; } + public TriggerableSelector Opacity{ get; set; } + public TriggerableSelector ImageShadow{ get; set; } + public TriggerableSelector BoxShadow{ get; set; } - public TriggerableSelector EnsureBackgroundColor() => BackgroundColor ?? (BackgroundColor = new TriggerableSelector(View.BackgroundColorProperty)); - public TriggerableSelector EnsureBackgroundImage() => BackgroundImage ?? (BackgroundImage = new TriggerableSelector(View.BackgroundImageProperty)); - public TriggerableSelector EnsureBackgroundImageBorder() => BackgroundImageBorder ?? (BackgroundImageBorder = new TriggerableSelector(View.BackgroundImageBorderProperty)); - public TriggerableSelector EnsureColor() => Color ?? (Color = new TriggerableSelector(View.ColorProperty)); - public TriggerableSelector EnsureOpacity() => Opacity ?? (Opacity = new TriggerableSelector(View.OpacityProperty)); - public TriggerableSelector EnsureImageShadow() => ImageShadow ?? (ImageShadow = new TriggerableSelector(View.ImageShadowProperty)); - public TriggerableSelector EnsureBoxShadow() => BoxShadow ?? (BoxShadow = new TriggerableSelector(View.BoxShadowProperty)); + public void ClearBackground(View view) + { + BackgroundColor?.Reset(view); + BackgroundImage?.Reset(view); + BackgroundImageBorder?.Reset(view); + BackgroundColor = null; + BackgroundImage = null; + BackgroundImageBorder = null; + } + public void ClearShadow(View view) + { + ImageShadow?.Reset(view); + BoxShadow?.Reset(view); + ImageShadow = null; + BoxShadow = null; + } public void Reset(View view) { -- 2.7.4