From acd7a1eea8ff3b0e31c7d832686939efaa67011c Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Mon, 15 Mar 2021 11:24:41 +0900 Subject: [PATCH] [NUI] Theme change do not overwrite user set properties. (#2731) * [NUI] Theme change do not overwrite user set properties. * Note that this works only for the bindable properties. Signed-off-by: Jiyun Yang * [NUI] Components share style instance in a theme Hence a component should not modify connected style instance. --- .../Controls/Button.Internal.cs | 28 +-- src/Tizen.NUI.Components/Controls/Button.cs | 45 +--- src/Tizen.NUI.Components/Controls/CheckBox.cs | 18 +- src/Tizen.NUI.Components/Controls/Control.cs | 27 +-- .../Controls/FlexibleView/FlexibleView.cs | 4 +- .../Controls/ImageScrollBar.cs | 87 ++++---- src/Tizen.NUI.Components/Controls/Loading.cs | 184 +++++++--------- src/Tizen.NUI.Components/Controls/Pagination.cs | 245 +++++++++++---------- src/Tizen.NUI.Components/Controls/Popup.cs | 223 +++++-------------- src/Tizen.NUI.Components/Controls/Progress.cs | 144 ++++-------- src/Tizen.NUI.Components/Controls/RadioButton.cs | 17 +- .../Controls/RecyclerView/Item/DefaultGridItem.cs | 22 -- .../RecyclerView/Item/DefaultLinearItem.cs | 24 -- .../Controls/RecyclerView/Item/DefaultTitleItem.cs | 22 -- .../Controls/RecyclerView/Item/RecyclerViewItem.cs | 33 --- src/Tizen.NUI.Components/Controls/Scrollbar.cs | 189 +++++++--------- src/Tizen.NUI.Components/Controls/SelectButton.cs | 18 +- .../Controls/Slider.Internal.cs | 18 +- src/Tizen.NUI.Components/Controls/Slider.cs | 47 +--- src/Tizen.NUI.Components/Controls/Switch.cs | 36 +-- src/Tizen.NUI.Components/Controls/Tab.cs | 16 +- src/Tizen.NUI.Components/Controls/Toast.cs | 97 +++----- src/Tizen.NUI.Components/Style/PaginationStyle.cs | 4 +- .../Theme/DefaultThemeCommon.cs | 4 +- .../src/public/CircularPagination.cs | 4 +- .../src/public/CircularProgress.cs | 18 -- .../src/public/CircularScrollbar.cs | 18 -- .../src/public/CircularSlider.cs | 18 -- src/Tizen.NUI.Wearable/src/public/Title.cs | 10 - .../src/public/BaseComponents/CustomView.cs | 14 +- .../src/public/BaseComponents/Style/Selector.cs | 56 +++++ .../src/public/BaseComponents/Style/ViewStyle.cs | 31 ++- src/Tizen.NUI/src/public/BaseComponents/View.cs | 49 ++++- .../src/public/BaseComponents/ViewInternal.cs | 52 ++++- src/Tizen.NUI/src/public/CustomView/ViewWrapper.cs | 10 +- src/Tizen.NUI/src/public/Theme/Theme.cs | 8 +- src/Tizen.NUI/src/public/Theme/ThemeManager.cs | 33 ++- 37 files changed, 738 insertions(+), 1135 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Button.Internal.cs b/src/Tizen.NUI.Components/Controls/Button.Internal.cs index 8ddec6d..f4fd6c1 100755 --- a/src/Tizen.NUI.Components/Controls/Button.Internal.cs +++ b/src/Tizen.NUI.Components/Controls/Button.Internal.cs @@ -410,6 +410,16 @@ namespace Tizen.NUI.Components { base.OnInitialize(); SetAccessibilityConstructor(Role.PushButton); + + AccessibilityHighlightable = true; + EnableControlStatePropagation = true; + LayoutDirectionChanged += OnLayoutDirectionChanged; + + AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Button"); + +#if PROFILE_MOBILE + Feedback = true; +#endif } /// @@ -433,24 +443,6 @@ namespace Tizen.NUI.Components } } - /// - /// It is hijack by using protected, style copy problem when class inherited from Button. - /// - /// 6 - private void Initialize() - { - AccessibilityHighlightable = true; - EnableControlStatePropagation = true; - UpdateState(); - LayoutDirectionChanged += OnLayoutDirectionChanged; - - AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Button"); - -#if PROFILE_MOBILE - Feedback = true; -#endif - } - private void UpdateUIContent() { MeasureText(); diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index 3be84d7..ed56c0a 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.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. @@ -75,12 +75,6 @@ namespace Tizen.NUI.Components if (instance.isEnabled != newEnabled) { instance.isEnabled = newEnabled; - - if (instance.buttonStyle != null) - { - instance.buttonStyle.IsEnabled = newEnabled; - } - instance.UpdateState(); } } @@ -98,11 +92,6 @@ namespace Tizen.NUI.Components { instance.isSelected = newSelected; - if (instance.buttonStyle != null) - { - instance.buttonStyle.IsSelected = newSelected; - } - if (instance.isSelectable) { instance.UpdateState(); @@ -126,12 +115,6 @@ namespace Tizen.NUI.Components if (instance.isSelectable != newSelectable) { instance.isSelectable = newSelectable; - - if (instance.buttonStyle != null) - { - instance.buttonStyle.IsSelectable = newSelectable; - } - instance.UpdateState(); } } @@ -173,7 +156,6 @@ namespace Tizen.NUI.Components /// 6 public Button() : base() { - Initialize(); } /// @@ -183,7 +165,6 @@ namespace Tizen.NUI.Components /// 8 public Button(string style) : base(style) { - Initialize(); } /// @@ -193,7 +174,6 @@ namespace Tizen.NUI.Components /// 8 public Button(ButtonStyle buttonStyle) : base(buttonStyle) { - Initialize(); } /// @@ -352,25 +332,13 @@ namespace Tizen.NUI.Components } /// - /// Return a copied Style instance of Button + /// Return currently applied style. /// /// - /// It returns copied Style instance and changing it does not effect to the Button. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) + /// Modifying contents in style may cause unexpected behaviour. /// /// 8 - public new ButtonStyle Style - { - get - { - var result = (ButtonStyle)ViewStyle.Clone(); - result.CopyPropertiesFromView(this); - result.Text.CopyPropertiesFromView(TextLabel); - result.Icon.CopyPropertiesFromView(Icon); - result.Overlay.CopyPropertiesFromView(OverlayImage); - return result; - } - } + public ButtonStyle Style => (ButtonStyle)(ViewStyle as ButtonStyle)?.Clone(); /// /// The text of Button. @@ -683,8 +651,6 @@ namespace Tizen.NUI.Components set => SetValue(TextPaddingProperty, value); } - private ButtonStyle buttonStyle => ViewStyle as ButtonStyle; - /// /// Called after a key event is received by the view that has had its focus set. /// @@ -779,7 +745,7 @@ namespace Tizen.NUI.Components base.ApplyStyle(viewStyle); - if (null != buttonStyle) + if (viewStyle is ButtonStyle buttonStyle) { Extension = buttonStyle.CreateExtension(); if (buttonStyle.Overlay != null) @@ -799,6 +765,7 @@ namespace Tizen.NUI.Components } styleApplied = true; + UpdateState(); } /// diff --git a/src/Tizen.NUI.Components/Controls/CheckBox.cs b/src/Tizen.NUI.Components/Controls/CheckBox.cs index 55b0a27..9af37fd 100755 --- a/src/Tizen.NUI.Components/Controls/CheckBox.cs +++ b/src/Tizen.NUI.Components/Controls/CheckBox.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. @@ -50,6 +50,7 @@ namespace Tizen.NUI.Components public override void OnInitialize() { base.OnInitialize(); + SetAccessibilityConstructor(Role.CheckBox); } @@ -73,21 +74,6 @@ namespace Tizen.NUI.Components /// [EditorBrowsable(EditorBrowsableState.Never)] - public override void ApplyStyle(ViewStyle viewStyle) - { - if (viewStyle is ButtonStyle buttonStyle) - { - if (buttonStyle.IsSelectable == null) - { - buttonStyle.IsSelectable = true; - } - - base.ApplyStyle(buttonStyle); - } - } - - /// - [EditorBrowsable(EditorBrowsableState.Never)] protected override ImageView CreateIcon() { return new ImageView diff --git a/src/Tizen.NUI.Components/Controls/Control.cs b/src/Tizen.NUI.Components/Controls/Control.cs index 1eba802..5f07a78 100755 --- a/src/Tizen.NUI.Components/Controls/Control.cs +++ b/src/Tizen.NUI.Components/Controls/Control.cs @@ -46,10 +46,6 @@ namespace Tizen.NUI.Components private Feedback feedback = null; - /// 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 ControlStyle Style => (ControlStyle)ViewStyle.Clone(); - static Control() { ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance); @@ -83,7 +79,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Control(ControlStyle style) : base(style) { - Initialize(); } /// @@ -93,15 +88,14 @@ namespace Tizen.NUI.Components /// 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 Control(string styleName) : this(ThemeManager.GetStyle(styleName) as ControlStyle) + public Control(string styleName) : this(new ControlStyle() /* Apply empty style */) { if (ThemeManager.GetStyle(styleName) == null) { throw new InvalidOperationException($"There is no style {styleName}"); } - this.styleName = styleName; - ThemeChangeSensitive = true; + StyleName = styleName; } /// @@ -207,12 +201,14 @@ namespace Tizen.NUI.Components base.Dispose(type); } - /// - /// OnInitialize - /// + /// public override void OnInitialize() { base.OnInitialize(); + + LeaveRequired = true; + StateFocusableOnTouchMode = false; + EnableControlState = true; } /// @@ -312,14 +308,5 @@ namespace Tizen.NUI.Components // If the OnThemeChangedEvent is not implemented, ApplyStyle() base.OnThemeChanged(sender, e); } - - private void Initialize() - { - LeaveRequired = true; - - StateFocusableOnTouchMode = false; - - EnableControlState = true; - } } } diff --git a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs index ee3f35d..c92587d 100755 --- a/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs +++ b/src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleView.cs @@ -657,11 +657,11 @@ namespace Tizen.NUI.Components } if (mScrollBar.Direction == ScrollBar.DirectionType.Vertical) { - mScrollBar.Style.Thumb.Size = new Size(thickness, length); + mScrollBar.ThumbSize = new Size(thickness, length); } else { - mScrollBar.Style.Thumb.Size = new Size(length, thickness); + mScrollBar.ThumbSize = new Size(length, thickness); } mScrollBar.MinValue = 0; mScrollBar.MaxValue = (int)(range - extent); diff --git a/src/Tizen.NUI.Components/Controls/ImageScrollBar.cs b/src/Tizen.NUI.Components/Controls/ImageScrollBar.cs index c019dc4..7966172 100755 --- a/src/Tizen.NUI.Components/Controls/ImageScrollBar.cs +++ b/src/Tizen.NUI.Components/Controls/ImageScrollBar.cs @@ -39,14 +39,14 @@ namespace Tizen.NUI.Components var instance = (ScrollBar)bindable; if (newValue != null) { - instance.Style.Direction = (DirectionType?)newValue; + instance.direction = (DirectionType)newValue; instance.UpdateValue(); } }, defaultValueCreator: (bindable) => { var instance = (ScrollBar)bindable; - return instance.Style.Direction; + return instance.direction; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] @@ -112,7 +112,7 @@ namespace Tizen.NUI.Components var instance = (ScrollBar)bindable; if (newValue != null) { - instance.Style.Duration = (uint)newValue; + instance.duration = (uint)newValue; if (instance.scrollAniPlayer != null) { instance.scrollAniPlayer.Duration = (int)(uint)newValue; @@ -122,7 +122,7 @@ namespace Tizen.NUI.Components defaultValueCreator: (bindable) => { var instance = (ScrollBar)bindable; - return instance.Style.Duration; + return instance.duration; }); private ImageView trackImage; @@ -134,6 +134,8 @@ namespace Tizen.NUI.Components private int minValue; private int maxValue; private int curValue; + private DirectionType direction = DirectionType.Horizontal; + private uint duration; static ScrollBar() { } /// @@ -144,7 +146,6 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public ScrollBar() : base() { - Initialize(); } /// @@ -154,7 +155,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public ScrollBar(string style) : base(style) { - Initialize(); } /// @@ -164,7 +164,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public ScrollBar(ScrollBarStyle scrollBarStyle) : base(scrollBarStyle) { - Initialize(); } /// @@ -194,12 +193,6 @@ namespace Tizen.NUI.Components #region public property /// - /// Get style of scrollbar. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new ScrollBarStyle Style => ViewStyle as ScrollBarStyle; - - /// /// The property to get/set the direction of the ScrollBar. /// /// 6 @@ -241,13 +234,13 @@ namespace Tizen.NUI.Components { get { - return Style?.Thumb?.Size; + return thumbImage?.Size; } set { - if (null != Style?.Thumb) + if (thumbImage != null) { - Style.Thumb.Size = value; + thumbImage.Size = value; RelayoutRequest(); } } @@ -263,13 +256,13 @@ namespace Tizen.NUI.Components { get { - return Style?.Track?.ResourceUrl?.All; + return trackImage?.ResourceUrl; } set { - if (null != Style?.Track) + if (trackImage != null) { - Style.Track.ResourceUrl = value; + trackImage.ResourceUrl = value; RelayoutRequest(); } } @@ -285,14 +278,13 @@ namespace Tizen.NUI.Components { get { - return Style?.Track?.BackgroundColor?.All; + return trackImage?.BackgroundColor; } set { - if (null != Style?.Track) + if (trackImage != null) { - Style.Track.BackgroundColor = value; - RelayoutRequest(); + trackImage.BackgroundColor = value; } } } @@ -307,14 +299,13 @@ namespace Tizen.NUI.Components { get { - return Style?.Thumb?.BackgroundColor?.All; + return thumbImage?.BackgroundColor; } set { - if (null != Style?.Thumb) + if (thumbImage != null) { - Style.Thumb.BackgroundColor = value; - RelayoutRequest(); + thumbImage.BackgroundColor = value; } } } @@ -499,8 +490,12 @@ namespace Tizen.NUI.Components return new ScrollBarStyle(); } - private void Initialize() + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() { + base.OnInitialize(); + this.Focusable = false; trackImage = new ImageView @@ -513,7 +508,7 @@ namespace Tizen.NUI.Components PivotPoint = Tizen.NUI.PivotPoint.CenterLeft }; this.Add(trackImage); - trackImage.ApplyStyle(Style.Track); + thumbImage = new ImageView { @@ -525,7 +520,7 @@ namespace Tizen.NUI.Components PivotPoint = Tizen.NUI.PivotPoint.CenterLeft }; this.Add(thumbImage); - thumbImage.ApplyStyle(Style.Thumb); + scrollAniPlayer = new Animation(334); scrollAniPlayer.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear); @@ -535,6 +530,20 @@ namespace Tizen.NUI.Components LayoutDirectionChanged += OnLayoutDirectionChanged; } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void ApplyStyle(ViewStyle style) + { + base.ApplyStyle(style); + + if (style is ScrollBarStyle scrollBarStyle) + { + trackImage.ApplyStyle(scrollBarStyle.Track); + thumbImage.ApplyStyle(scrollBarStyle.Thumb); + UpdateValue(); + } + } + private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e) { RelayoutRequest(); @@ -548,18 +557,18 @@ namespace Tizen.NUI.Components float height = (float)Size2D.Height; float thumbW = 0.0f; float thumbH = 0.0f; - if (Style.Thumb.Size == null) + if (thumbImage == null || thumbImage.Size == null) { return; } else { - thumbW = Style.Thumb.Size.Width; - thumbH = Style.Thumb.Size.Height; + thumbW = thumbImage.Size.Width; + thumbH = thumbImage.Size.Height; } float ratio = (float)(curValue - minValue) / (float)(maxValue - minValue); - if (Style.Direction == DirectionType.Horizontal) + if (direction == DirectionType.Horizontal) { if (LayoutDirection == ViewLayoutDirectionType.RTL) { @@ -618,16 +627,6 @@ namespace Tizen.NUI.Components if (enableAni) enableAni = false; } - private DirectionType CurrentDirection() - { - DirectionType dir = DirectionType.Horizontal; - if (null != Style.Direction) - { - dir = Style.Direction.Value; - } - return dir; - } - private int CalculateCurrentValue(float offset, DirectionType dir) { if (dir == DirectionType.Horizontal) diff --git a/src/Tizen.NUI.Components/Controls/Loading.cs b/src/Tizen.NUI.Components/Controls/Loading.cs index 7b22f2b..95e65f6 100755 --- a/src/Tizen.NUI.Components/Controls/Loading.cs +++ b/src/Tizen.NUI.Components/Controls/Loading.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. @@ -14,9 +14,10 @@ * limitations under the License. * */ -using System; + using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using Tizen.NUI.Accessibility; @@ -29,78 +30,55 @@ namespace Tizen.NUI.Components /// 6 public class Loading : Control { - /// The ImageArray bindable property. + /// The ImageList bindable property. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ImageArrayProperty = BindableProperty.Create(nameof(ImageArray), typeof(string[]), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty ImageListProperty = BindableProperty.Create(nameof(ImageList), typeof(IList), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) => { - var instance = (Loading)bindable; - if (newValue != null) - { - instance.loadingStyle.Images = (string[])newValue; - instance.imageVisual.URLS = instance.loadingStyle.ImageList as List; - } + Debug.Assert(((Loading)bindable).imageVisual != null); + + var newList = newValue as List; + ((Loading)bindable).imageVisual.URLS = newList == null ? new List() : newList; }, defaultValueCreator: (bindable) => { - var instance = (Loading)bindable; - return instance.loadingStyle.Images; + Debug.Assert(((Loading)bindable).imageVisual != null); + return ((Loading)bindable).imageVisual.URLS; }); - /// The ImageList bindable property. + /// The Size bindable property. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ImageListProperty = BindableProperty.Create(nameof(ImageList), typeof(IList), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) => + public new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Loading)bindable; if (newValue != null) { - var newValueList = newValue as List; - instance.loadingStyle.ImageList = newValueList; - if (instance.imageVisual != null) instance.imageVisual.URLS = newValueList; + Size size = (Size)newValue; + ((View)bindable).Size = size; } }, defaultValueCreator: (bindable) => { - return ((Loading)bindable).loadingStyle.ImageList; - }); - /// The Size bindable property. - [EditorBrowsable(EditorBrowsableState.Never)] - public new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) => - { - var instance = (Loading)bindable; - if (newValue != null) - { - Size size = (Size)newValue; - ((View)bindable).Size = size; - instance.loadingStyle.LoadingSize = size; - } - }, - defaultValueCreator: (bindable) => - { var instance = (View)bindable; return instance.Size; }); /// The FrameRate bindable property. [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty FrameRateProperty = BindableProperty.Create(nameof(FrameRate), typeof(int), typeof(Loading), (int)(1000 / 16.6f), propertyChanged: (bindable, oldValue, newValue) => - { - var instance = (Loading)bindable; - if (newValue != null) - { - int frameRate = (int)newValue; - if (0 != frameRate) //It will crash if 0 - { - instance.loadingStyle.FrameRate = frameRate; - instance.imageVisual.FrameDelay = 1000.0f / frameRate; - } - } - }, + { + Debug.Assert(((Loading)bindable).imageVisual != null); + + int frameRate = (int)newValue; + if (0 != frameRate) //It will crash if 0 + { + ((Loading)bindable).imageVisual.FrameDelay = 1000.0f / frameRate; + } + }, defaultValueCreator: (bindable) => { - var instance = (Loading)bindable; - return instance.loadingStyle.FrameRate?.All ?? (int)(1000 / 16.6f); + Debug.Assert(((Loading)bindable).imageVisual != null); + return ((Loading)bindable).imageVisual.FrameDelay * 1000.0f; }); private AnimatedImageVisual imageVisual = null; - private LoadingStyle loadingStyle => ViewStyle as LoadingStyle; internal new class Property { @@ -117,7 +95,6 @@ namespace Tizen.NUI.Components /// 6 public Loading() : base() { - Initialize(); } /// @@ -127,7 +104,6 @@ namespace Tizen.NUI.Components /// 8 public Loading(string style) : base(style) { - Initialize(); } /// @@ -137,27 +113,16 @@ namespace Tizen.NUI.Components /// 8 public Loading(LoadingStyle loadingStyle) : base(loadingStyle) { - Initialize(); } /// - /// Get style of loading. - /// Return a copied Style instance of Loading + /// Return currently applied style. /// /// - /// It returns copied Style instance and changing it does not effect to the Loading. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// > + /// Modifying contents in style may cause unexpected behaviour. + /// /// 8 - public new LoadingStyle Style - { - get - { - var result = new LoadingStyle(loadingStyle); - result.CopyPropertiesFromView(this); - return result; - } - } + public LoadingStyle Style => (LoadingStyle)(ViewStyle as LoadingStyle)?.Clone(); /// /// Gets or sets loading image resource array. @@ -165,14 +130,8 @@ namespace Tizen.NUI.Components /// 6 public string[] ImageArray { - get - { - return (string[])GetValue(ImageArrayProperty); - } - set - { - SetValue(ImageArrayProperty, value); - } + get => (GetValue(ImageListProperty) as List).ToArray(); + set => SetValue(ImageListProperty, value == null ? new List() : new List((string[])value)); } /// @@ -219,6 +178,51 @@ namespace Tizen.NUI.Components } } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + + imageVisual = new AnimatedImageVisual() + { + URLS = new List(), + FrameDelay = 16.6f, + LoopCount = -1, + Position = new Vector2(0, 0), + Origin = Visual.AlignType.Center, + AnchorPoint = Visual.AlignType.Center, + SizePolicy = VisualTransformPolicyType.Relative, + Size = new Size2D(1, 1) + }; + + this.AddVisual("loadingImageVisual", imageVisual); + + AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Loading"); + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void ApplyStyle(ViewStyle viewStyle) + { + base.ApplyStyle(viewStyle); + + Debug.Assert(imageVisual != null); + + if (viewStyle is LoadingStyle loadingStyle) + { + if (loadingStyle.Images != null) + { + imageVisual.URLS = loadingStyle.ImageList as List; + } + + if (loadingStyle.LoadingSize != null) + { + Size = loadingStyle.LoadingSize; + } + } + } + /// /// Get Loading style. /// @@ -253,40 +257,6 @@ namespace Tizen.NUI.Components base.Dispose(type); } - private void Initialize() - { - imageVisual = new AnimatedImageVisual() - { - URLS = new List(), - FrameDelay = 16.6f, - LoopCount = -1, - Position = new Vector2(0, 0), - Origin = Visual.AlignType.Center, - AnchorPoint = Visual.AlignType.Center, - SizePolicy = VisualTransformPolicyType.Relative, - Size = new Size2D(1, 1) - }; - - UpdateVisual(); - - this.AddVisual("loadingImageVisual", imageVisual); - - AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Loading"); - } - - private void UpdateVisual() - { - if (null != loadingStyle.Images) - { - loadingStyle.ImageList = new List(loadingStyle.Images); - imageVisual.URLS = loadingStyle.ImageList as List; - } - if (null != loadingStyle.FrameRate?.All && 0 != loadingStyle.FrameRate.All.Value) - { - imageVisual.FrameDelay = 1000.0f / (float)loadingStyle.FrameRate.All.Value; - } - } - /// /// Play Loading Animation. /// diff --git a/src/Tizen.NUI.Components/Controls/Pagination.cs b/src/Tizen.NUI.Components/Controls/Pagination.cs index f42a2f4..b537fb8 100755 --- a/src/Tizen.NUI.Components/Controls/Pagination.cs +++ b/src/Tizen.NUI.Components/Controls/Pagination.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. @@ -14,10 +14,13 @@ * limitations under the License. * */ + using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using Tizen.NUI.BaseComponents; +using Tizen.NUI.Binding; namespace Tizen.NUI.Components { @@ -27,13 +30,57 @@ namespace Tizen.NUI.Components /// 8 public class Pagination : Control { - private VisualView container; + /// The IndicatorSize bindable property. + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty IndicatorSizeProperty = BindableProperty.Create(nameof(IndicatorSize), typeof(Size), typeof(Pagination), null, propertyChanged: (bindable, oldValue, newValue) => + { + if (newValue != null) + { + var pagination = (Pagination)bindable; + pagination.indicatorSize = new Size((Size)newValue); + pagination.UpdateVisual(); + pagination.UpdateContainer(); + } + }, + defaultValueCreator: (bindable) => + { + return ((Pagination)bindable).indicatorSize; + }); + /// The IndicatorImageUrlSelector bindable property. + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty IndicatorImageUrlProperty = BindableProperty.Create("IndicatorImageUrl", typeof(Selector), typeof(Pagination), null, propertyChanged: (bindable, oldValue, newValue) => + { + var pagination = (Pagination)bindable; + pagination.indicatorImageUrl = ((Selector)newValue)?.Clone(); + pagination.UpdateVisual(); + }, + defaultValueCreator: (bindable) => + { + return ((Pagination)bindable).indicatorImageUrl; + }); + + /// The IndicatorSpacing bindable property. + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty IndicatorSpacingProperty = BindableProperty.Create(nameof(IndicatorSpacing), typeof(int), typeof(Pagination), default(int), propertyChanged: (bindable, oldValue, newValue) => + { + var pagination = (Pagination)bindable; + pagination.indicatorSpacing = (int)newValue; + pagination.UpdateVisual(); + }, + defaultValueCreator: (bindable) => + { + return ((Pagination)bindable).indicatorSpacing; + }); + + private VisualView container; + private Size indicatorSize = new Size(10, 10); + private Selector indicatorImageUrl; + private int indicatorSpacing; private List indicatorList = new List(); private int indicatorCount = 0; - private int selectedIndex = -1; - private PaginationStyle paginationStyle => ViewStyle as PaginationStyle; + private int selectedIndex = 0; private Color indicatorColor; private Color selectedIndicatorColor; @@ -47,7 +94,6 @@ namespace Tizen.NUI.Components /// 8 public Pagination() : base() { - Initialize(); } /// @@ -57,7 +103,6 @@ namespace Tizen.NUI.Components /// 8 public Pagination(string style) : base(style) { - Initialize(); } /// @@ -67,23 +112,16 @@ namespace Tizen.NUI.Components /// 8 public Pagination(PaginationStyle paginationStyle) : base(paginationStyle) { - Initialize(); } /// - /// Get style of pagination. + /// Return currently applied style. /// - /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. + /// + /// Modifying contents in style may cause unexpected behaviour. + /// /// 8 - public new PaginationStyle Style - { - get - { - var result = new PaginationStyle(paginationStyle); - result.CopyPropertiesFromView(this); - return result; - } - } + public PaginationStyle Style => (PaginationStyle)(ViewStyle as PaginationStyle)?.Clone(); /// /// Gets or sets the size of the indicator. @@ -91,20 +129,8 @@ namespace Tizen.NUI.Components /// 8 public Size IndicatorSize { - get - { - return paginationStyle?.IndicatorSize; - } - set - { - if (value == null || paginationStyle == null) - { - return; - } - paginationStyle.IndicatorSize = value; - UpdateVisual(); - UpdateContainer(); - } + get => (Size)GetValue(IndicatorSizeProperty); + set => SetValue(IndicatorSizeProperty, value); } /// @@ -113,19 +139,8 @@ namespace Tizen.NUI.Components /// 8 public Selector IndicatorImageUrl { - get - { - return paginationStyle?.IndicatorImageUrl; - } - set - { - if (value == null || paginationStyle == null) - { - return; - } - paginationStyle.IndicatorImageUrl = value; - UpdateVisual(); - } + get => (Selector)GetValue(IndicatorImageUrlProperty); + set => SetValue(IndicatorImageUrlProperty, value); } /// @@ -152,18 +167,8 @@ namespace Tizen.NUI.Components /// 8 public int IndicatorSpacing { - get - { - return (int)paginationStyle?.IndicatorSpacing; - } - set - { - if (paginationStyle != null) - { - paginationStyle.IndicatorSpacing = value; - UpdateVisual(); - } - } + get => (int)GetValue(IndicatorSpacingProperty); + set => SetValue(IndicatorSpacingProperty, value); } @@ -179,7 +184,7 @@ namespace Tizen.NUI.Components } set { - if (indicatorCount == value || indicatorCount < 0) + if (indicatorCount == value || value < 0) { return; } @@ -191,7 +196,7 @@ namespace Tizen.NUI.Components prevLastIndex = LastIndicatorIndex; for (int i = indicatorCount; i < value; i++) { - CreateIndicator(); + CreateIndicator(i); } } else @@ -205,17 +210,21 @@ namespace Tizen.NUI.Components if (selectedIndex >= value) { - selectedIndex = 0; - SelectIn(indicatorList[selectedIndex]); + selectedIndex = Math.Max(0, value - 1); + + if (value > 0) + { + SelectIn(indicatorList[selectedIndex]); + } } } indicatorCount = value; - if (lastIndicatorImageUrl != null && paginationStyle != null && indicatorCount > 0) + if (lastIndicatorImageUrl != null && indicatorImageUrl != null && indicatorCount > 0) { - if (prevLastIndex >= 0 && paginationStyle.IndicatorImageUrl != null) + if (prevLastIndex >= 0) { - indicatorList[prevLastIndex].URL = prevLastIndex == selectedIndex ? paginationStyle.IndicatorImageUrl.Selected : paginationStyle.IndicatorImageUrl.Normal; + indicatorList[prevLastIndex].URL = prevLastIndex == selectedIndex ? indicatorImageUrl.Selected : indicatorImageUrl.Normal; } indicatorList[LastIndicatorIndex].URL = IsLastSelected ? lastIndicatorImageUrl.Selected : lastIndicatorImageUrl.Normal; } @@ -338,19 +347,21 @@ namespace Tizen.NUI.Components } set { - if (selectedIndex == value) + var refinedValue = Math.Max(0, Math.Min(value, indicatorCount - 1)); + + if (selectedIndex == refinedValue) { return; } - if (selectedIndex >= 0 && selectedIndex < indicatorCount) - { - SelectOut(indicatorList[selectedIndex]); - } - selectedIndex = value; - if (selectedIndex >= 0 && selectedIndex < indicatorCount) - { - SelectIn(indicatorList[selectedIndex]); - } + + Debug.Assert(refinedValue >= 0 && refinedValue < indicatorCount); + Debug.Assert(selectedIndex >= 0 && selectedIndex < indicatorCount); + + SelectOut(indicatorList[selectedIndex]); + + selectedIndex = refinedValue; + + SelectIn(indicatorList[selectedIndex]); } } @@ -369,6 +380,26 @@ namespace Tizen.NUI.Components return new Position(indicatorList[index].Position.X + container.PositionX, indicatorList[index].Position.Y + container.PositionY); } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + + container = new VisualView() + { + Name = "Container", + ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft, + PivotPoint = Tizen.NUI.PivotPoint.CenterLeft, + PositionUsesPivotPoint = true, + }; + this.Add(container); + + //TODO: Apply color properties from PaginationStyle class. + indicatorColor = new Color(1.0f, 1.0f, 1.0f, 0.5f); + selectedIndicatorColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); + } + /// /// You can override it to do your select out operation. /// @@ -377,7 +408,7 @@ namespace Tizen.NUI.Components protected virtual void SelectOut(VisualMap selectOutIndicator) { if (!(selectOutIndicator is ImageVisual visual)) return; - visual.URL = ((IsLastSelected && lastIndicatorImageUrl != null) ? lastIndicatorImageUrl : paginationStyle?.IndicatorImageUrl)?.Normal; + visual.URL = ((IsLastSelected && lastIndicatorImageUrl != null) ? lastIndicatorImageUrl : indicatorImageUrl)?.Normal; if (indicatorColor == null) { @@ -400,7 +431,7 @@ namespace Tizen.NUI.Components protected virtual void SelectIn(VisualMap selectInIndicator) { if (!(selectInIndicator is ImageVisual visual)) return; - visual.URL = ((IsLastSelected && lastIndicatorImageUrl != null) ? lastIndicatorImageUrl : paginationStyle?.IndicatorImageUrl)?.Selected; + visual.URL = ((IsLastSelected && lastIndicatorImageUrl != null) ? lastIndicatorImageUrl : indicatorImageUrl)?.Selected; if (selectedIndicatorColor == null) { @@ -450,75 +481,59 @@ namespace Tizen.NUI.Components base.Dispose(type); } - private void Initialize() + private void CreateIndicator(int index) { - container = new VisualView() - { - Name = "Container", - ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft, - PivotPoint = Tizen.NUI.PivotPoint.CenterLeft, - PositionUsesPivotPoint = true, - }; - this.Add(container); + Debug.Assert(indicatorSize != null); - //TODO: Apply color properties from PaginationStyle class. - indicatorColor = new Color(1.0f, 1.0f, 1.0f, 0.5f); - selectedIndicatorColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); - } - - private void CreateIndicator() - { - if (paginationStyle == null) - { - return; - } - if (paginationStyle.IndicatorSize == null) - { - paginationStyle.IndicatorSize = new Size(0, 0); - } ImageVisual indicator = new ImageVisual { - URL = paginationStyle.IndicatorImageUrl?.Normal, - Size = new Size2D((int)paginationStyle.IndicatorSize.Width, (int)paginationStyle.IndicatorSize.Height), + URL = indicatorImageUrl?.Normal, + Size = indicatorSize, //TODO: Apply color properties from PaginationStyle class. MixColor = (indicatorColor == null) ? new Color(1.0f, 1.0f, 1.0f, 0.5f) : indicatorColor, Opacity = (indicatorColor == null) ? 0.5f : indicatorColor.A }; - indicator.Position = new Vector2((int)(paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * indicatorList.Count, 0); + indicator.Position = new Vector2((int)(indicatorSize.Width + indicatorSpacing) * indicatorList.Count, 0); container.AddVisual("Indicator" + indicatorList.Count, indicator); indicatorList.Add(indicator); + + if (index == selectedIndex) + { + SelectIn(indicatorList[selectedIndex]); + } } private void UpdateContainer() { - if (paginationStyle == null) - { - return; - } + Debug.Assert(indicatorSize != null); + if (indicatorList.Count > 0) { - container.SizeWidth = (paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * indicatorList.Count - paginationStyle.IndicatorSpacing; + container.SizeWidth = (indicatorSize.Width + indicatorSpacing) * indicatorList.Count - indicatorSpacing; } else { container.SizeWidth = 0; } - container.SizeHeight = paginationStyle.IndicatorSize.Height; + container.SizeHeight = indicatorSize.Height; container.PositionX = (int)((this.SizeWidth - container.SizeWidth) / 2); } private void UpdateVisual() { - if (null == paginationStyle?.IndicatorSize) return; - if (null == paginationStyle?.IndicatorImageUrl) return; - if (indicatorCount < 0) return; + Debug.Assert(indicatorSize != null); + + if (indicatorImageUrl == null) + { + return; + } for (int i = 0; i < indicatorList.Count; i++) { ImageVisual indicator = indicatorList[i]; - indicator.URL = paginationStyle.IndicatorImageUrl?.Normal; - indicator.Size = new Size2D((int)paginationStyle.IndicatorSize.Width, (int)paginationStyle.IndicatorSize.Height); - indicator.Position = new Vector2((int)(paginationStyle.IndicatorSize.Width + paginationStyle.IndicatorSpacing) * i, 0); + indicator.URL = indicatorImageUrl?.Normal; + indicator.Size = indicatorSize; + indicator.Position = new Vector2((int)(indicatorSize.Width + indicatorSpacing) * i, 0); } if (lastIndicatorImageUrl != null && indicatorCount > 0) diff --git a/src/Tizen.NUI.Components/Controls/Popup.cs b/src/Tizen.NUI.Components/Controls/Popup.cs index e806c57..abe649c 100755 --- a/src/Tizen.NUI.Components/Controls/Popup.cs +++ b/src/Tizen.NUI.Components/Controls/Popup.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,17 +35,15 @@ namespace Tizen.NUI.Components public static readonly BindableProperty ButtonHeightProperty = BindableProperty.Create(nameof(ButtonHeight), typeof(int), typeof(Popup), default(int), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; - if (newValue != null && instance?.popupStyle?.Buttons?.Size != null) + if (newValue != null) { - instance.popupStyle.Buttons.SizeHeight = (int)newValue; instance.btGroup.Itemheight = (int)newValue; instance.UpdateView(); } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return (int)(instance.popupStyle?.Buttons?.Size?.Height ?? 0); + return (int)((Popup)bindable).btGroup.Itemheight; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -55,17 +53,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - if (instance.popupStyle?.Buttons?.Text != null) - { - instance.popupStyle.Buttons.Text.PointSize = (float)newValue; - } instance.btGroup.ItemPointSize = (float)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.Text?.PointSize?.All ?? 0; + return ((Popup)bindable).btGroup.ItemPointSize; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -75,14 +68,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - instance.popupStyle.Buttons.Text.FontFamily = (string)newValue; instance.btGroup.ItemFontFamily = (string)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.Text?.FontFamily.All; + return ((Popup)bindable).btGroup.ItemFontFamily; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -92,17 +83,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - if (instance.popupStyle?.Buttons?.Text != null) - { - instance.popupStyle.Buttons.Text.TextColor = (Color)newValue; - } instance.btGroup.ItemTextColor = (Color)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.Text?.TextColor?.All; + return ((Popup)bindable).btGroup.ItemTextColor; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -112,14 +98,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - instance.popupStyle.Buttons.Overlay.BackgroundColor = (Selector)newValue; instance.btGroup.OverLayBackgroundColorSelector = (Selector)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.Overlay?.BackgroundColor; + return ((Popup)bindable).btGroup.OverLayBackgroundColorSelector; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -129,14 +113,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - instance.popupStyle.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue; instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center; + return ((Popup)bindable).btGroup.ItemTextAlignment; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -146,19 +128,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - if (instance.popupStyle.Buttons.BackgroundImage == null) - { - instance.popupStyle.Buttons.BackgroundImage = new Selector(); - } - instance.popupStyle.Buttons.BackgroundColor = new Selector(); - instance.popupStyle.Buttons.BackgroundImage = (string)newValue; instance.btGroup.ItemBackgroundImageUrl = (string)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.BackgroundImage?.All; + return ((Popup)bindable).btGroup.ItemBackgroundImageUrl; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -168,18 +143,12 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; if (newValue != null) { - if (instance.popupStyle.Buttons.BackgroundImageBorder == null) - { - instance.popupStyle.Buttons.BackgroundImageBorder = new Selector(); - } - instance.popupStyle.Buttons.BackgroundImageBorder = (Rectangle)newValue; instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue; } }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.BackgroundImageBorder?.All; + return ((Popup)bindable).btGroup.ItemBackgroundBorder; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -189,20 +158,18 @@ namespace Tizen.NUI.Components var instance = (Popup)bindable; ImageShadow shadow = (ImageShadow)newValue; instance.btGroup.ItemImageShadow = new ImageShadow(shadow); - instance.popupStyle.Buttons.ImageShadow = new ImageShadow(shadow); }, defaultValueCreator: (bindable) => { - var instance = (Popup)bindable; - return instance.popupStyle?.Buttons?.ImageShadow?.All; + return ((Popup)bindable).btGroup.ItemImageShadow; }); - - private PopupStyle popupStyle => ViewStyle as PopupStyle; private TextLabel titleText; private ButtonGroup btGroup = null; private Window window = null; private Layer container = new Layer(); + private ButtonStyle buttonStyle = new ButtonStyle(); + static Popup() { } /// @@ -212,7 +179,6 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public Popup() : base() { - Initialize(); } /// @@ -222,7 +188,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Popup(string style) : base(style) { - Initialize(); } /// @@ -232,7 +197,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Popup(PopupStyle popupStyle) : base(popupStyle) { - Initialize(); } /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -268,14 +232,11 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public void AddButton(string buttonText) { - if (popupStyle.Buttons != null) - { - Button btn = new Button(popupStyle.Buttons); - btn.Text = buttonText; - btn.ClickEvent += ButtonClickEvent; - btGroup.AddItem(btn); - UpdateView(); - } + Button btn = new Button(buttonStyle); + btn.Text = buttonText; + btn.ClickEvent += ButtonClickEvent; + btGroup.AddItem(btn); + UpdateView(); } /// @@ -293,11 +254,11 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public void AddButton(string buttonText, ButtonStyle style) { - if (popupStyle.Buttons != null && style != null) - { - popupStyle.Buttons.CopyFrom(style); - AddButton(buttonText); - } + Button btn = new Button(style); + btn.Text = buttonText; + btn.ClickEvent += ButtonClickEvent; + btGroup.AddItem(btn); + UpdateView(); } /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -333,21 +294,6 @@ namespace Tizen.NUI.Components public event EventHandler PopupButtonClickEvent; /// - /// Get style of popup. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new PopupStyle Style - { - get - { - var result = new PopupStyle(popupStyle); - result.CopyPropertiesFromView(this); - result.Title.CopyPropertiesFromView(titleText); - return result; - } - } - - /// /// Popup Title. /// [EditorBrowsable(EditorBrowsableState.Never)] @@ -383,20 +329,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public string TitleText { - get - { - return popupStyle?.Title?.Text?.All; - } - set - { - if (value != null) - { - if (popupStyle?.Title != null) - { - popupStyle.Title.Text = value; - } - } - } + get => Title.Text; + set => Title.Text = value; } /// @@ -406,17 +340,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public float TitlePointSize { - get - { - return popupStyle?.Title?.PointSize?.All ?? 0; - } - set - { - if (popupStyle?.Title != null) - { - popupStyle.Title.PointSize = value; - } - } + get => Title.PointSize; + set => Title.PointSize = value; } /// @@ -426,17 +351,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public Color TitleTextColor { - get - { - return popupStyle?.Title?.TextColor?.All; - } - set - { - if (popupStyle?.Title != null) - { - popupStyle.Title.TextColor = value; - } - } + get => Title.TextColor; + set => Title.TextColor = value; } /// @@ -446,14 +362,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public HorizontalAlignment TitleTextHorizontalAlignment { - get - { - return popupStyle?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center; - } - set - { - popupStyle.Title.HorizontalAlignment = value; - } + get => Title.HorizontalAlignment; + set => Title.HorizontalAlignment = value; } /// @@ -463,14 +373,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public Position TitleTextPosition { - get - { - return popupStyle?.Title?.Position ?? new Position(0, 0, 0); - } - set - { - popupStyle.Title.Position = value; - } + get => Title.Position; + set => Title.Position = value; } /// @@ -480,17 +384,8 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public int TitleHeight { - get - { - return (int)(popupStyle?.Title?.Size?.Height ?? 0); - } - set - { - if (popupStyle?.Title?.Size != null) - { - popupStyle.Title.SizeHeight = value; - } - } + get => (int)Title.SizeHeight; + set => Title.SizeHeight = (int)value; } /// @@ -715,6 +610,8 @@ namespace Tizen.NUI.Components btGroup.Dispose(); btGroup = null; } + + buttonStyle?.Dispose(); } base.Dispose(type); @@ -753,20 +650,22 @@ namespace Tizen.NUI.Components if (viewStyle is PopupStyle ppStyle) { - if (ppStyle.Buttons == null) + if (ppStyle.Buttons?.SizeHeight != null) { - ppStyle.Buttons = new ButtonStyle(); + ButtonHeight = (int)ppStyle.Buttons.SizeHeight; } - if (ppStyle.Buttons.PositionUsesPivotPoint == null) ppStyle.Buttons.PositionUsesPivotPoint = true; - if (ppStyle.Buttons.ParentOrigin == null) ppStyle.Buttons.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft; - if (ppStyle.Buttons.PivotPoint == null) ppStyle.Buttons.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft; + buttonStyle = (ButtonStyle)ppStyle.Buttons?.Clone(); + if (buttonStyle.PositionUsesPivotPoint == null) buttonStyle.PositionUsesPivotPoint = true; + if (buttonStyle.ParentOrigin == null) buttonStyle.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft; + if (buttonStyle.PivotPoint == null) buttonStyle.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft; if (btGroup != null) { for (int i = 0; i < btGroup.Count; i++) { - GetButton(i)?.ApplyStyle(ppStyle.Buttons); + var button = GetButton(i); + button.ApplyStyle(buttonStyle); } } @@ -793,8 +692,16 @@ namespace Tizen.NUI.Components UpdateView(); } - private void Initialize() + /// + /// Initialize AT-SPI object. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() { + base.OnInitialize(); + SetAccessibilityConstructor(Role.Dialog); + AppendAccessibilityAttribute("sub-role", "Alert"); + container.Add(this); container.SetTouchConsumed(true); container.SetHoverConsumed(true); @@ -817,17 +724,6 @@ namespace Tizen.NUI.Components } /// - /// Initialize AT-SPI object. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override void OnInitialize() - { - base.OnInitialize(); - SetAccessibilityConstructor(Role.Dialog); - AppendAccessibilityAttribute("sub-role", "Alert"); - } - - /// /// Informs AT-SPI bridge about the set of AT-SPI states associated with this object. /// [EditorBrowsable(EditorBrowsableState.Never)] @@ -840,8 +736,7 @@ namespace Tizen.NUI.Components private void UpdateView() { - if (popupStyle == null) return; - btGroup.UpdateButton(popupStyle.Buttons); + btGroup.UpdateButton(buttonStyle); UpdateContentView(); UpdateTitle(); } @@ -867,7 +762,7 @@ namespace Tizen.NUI.Components { if (e.PropertyName.Equals("LayoutDirection")) { - btGroup.UpdateButton(popupStyle.Buttons); + btGroup.UpdateButton(buttonStyle); } } @@ -889,9 +784,9 @@ namespace Tizen.NUI.Components titleY = (int)Title.Position.Y; } - if (btGroup.Count != 0 && popupStyle?.Buttons?.Size != null) + if (btGroup.Count != 0) { - buttonH = (int)popupStyle.Buttons.Size.Height; + buttonH = ButtonHeight; } ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH); ContentView.Position = new Position(titleX, titleY + titleH); @@ -900,7 +795,7 @@ namespace Tizen.NUI.Components private void UpdateTitle() { - if (titleText != null && string.IsNullOrEmpty(popupStyle.Title.Text.All) && popupStyle.Title.Size != null) + if (titleText != null && string.IsNullOrEmpty(Title.Text) && Title.Size != null) { titleText.RaiseToTop(); } diff --git a/src/Tizen.NUI.Components/Controls/Progress.cs b/src/Tizen.NUI.Components/Controls/Progress.cs index 5b18b4a..8c044b2 100755 --- a/src/Tizen.NUI.Components/Controls/Progress.cs +++ b/src/Tizen.NUI.Components/Controls/Progress.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. @@ -17,6 +17,7 @@ using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using System.ComponentModel; +using System.Diagnostics; namespace Tizen.NUI.Components { @@ -130,7 +131,6 @@ namespace Tizen.NUI.Components private float minValue = 0; private float currentValue = 0; private float bufferValue = 0; - private ProgressStyle progressStyle => ViewStyle as ProgressStyle; static Progress() { } /// @@ -139,7 +139,6 @@ namespace Tizen.NUI.Components /// 6 public Progress() : base() { - Initialize(); } /// @@ -149,7 +148,6 @@ namespace Tizen.NUI.Components /// 8 public Progress(string style) : base(style) { - Initialize(); } /// @@ -159,7 +157,6 @@ namespace Tizen.NUI.Components /// 8 public Progress(ProgressStyle progressStyle) : base(progressStyle) { - Initialize(); } /// @@ -188,21 +185,13 @@ namespace Tizen.NUI.Components } /// - /// Get style of progress. + /// Return currently applied style. /// + /// + /// Modifying contents in style may cause unexpected behaviour. + /// /// 8 - public new ProgressStyle Style - { - get - { - var result = new ProgressStyle(progressStyle); - result.CopyPropertiesFromView(this); - result.Track.CopyPropertiesFromView(trackImage); - result.Progress.CopyPropertiesFromView(progressImage); - result.Buffer.CopyPropertiesFromView(bufferImage); - return result; - } - } + public ProgressStyle Style => (ProgressStyle)(ViewStyle as ProgressStyle)?.Clone(); /// /// The property to get/set Track image object URL of the Progress. @@ -210,17 +199,8 @@ namespace Tizen.NUI.Components /// 6 public string TrackImageURL { - get - { - return progressStyle?.Track?.ResourceUrl?.All; - } - set - { - if (null != progressStyle?.Track) - { - progressStyle.Track.ResourceUrl = value; - } - } + get => trackImage.ResourceUrl; + set => trackImage.ResourceUrl = value; } /// @@ -229,17 +209,8 @@ namespace Tizen.NUI.Components /// 6 public string ProgressImageURL { - get - { - return progressStyle?.Progress?.ResourceUrl?.All; - } - set - { - if (null != progressStyle?.Progress) - { - progressStyle.Progress.ResourceUrl = value; - } - } + get => progressImage.ResourceUrl; + set => progressImage.ResourceUrl = value; } /// @@ -248,18 +219,8 @@ namespace Tizen.NUI.Components /// 6 public string BufferImageURL { - get - { - return progressStyle?.Buffer?.ResourceUrl?.All; - } - set - { - if (null != progressStyle?.Buffer) - { - progressStyle.Buffer.ResourceUrl = value; - RelayoutRequest(); - } - } + get => bufferImage.ResourceUrl; + set => bufferImage.ResourceUrl = value; } /// @@ -268,17 +229,8 @@ namespace Tizen.NUI.Components /// 6 public Color TrackColor { - get - { - return progressStyle?.Track?.BackgroundColor?.All; - } - set - { - if (null != progressStyle?.Track) - { - progressStyle.Track.BackgroundColor = value; - } - } + get => trackImage.BackgroundColor; + set => trackImage.BackgroundColor = value; } /// @@ -287,17 +239,8 @@ namespace Tizen.NUI.Components /// 6 public Color ProgressColor { - get - { - return progressStyle?.Progress?.BackgroundColor?.All; - } - set - { - if (null != progressStyle?.Progress) - { - progressStyle.Progress.BackgroundColor = value; - } - } + get => progressImage.BackgroundColor; + set => progressImage.BackgroundColor = value; } /// @@ -306,17 +249,8 @@ namespace Tizen.NUI.Components /// 6 public Color BufferColor { - get - { - return progressStyle?.Buffer?.BackgroundColor?.All; - } - set - { - if (null != progressStyle?.Buffer) - { - progressStyle.Buffer.BackgroundColor = value; - } - } + get => bufferImage.BackgroundColor; + set => bufferImage.BackgroundColor = value; } /// @@ -399,6 +333,35 @@ namespace Tizen.NUI.Components } } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + // create necessary components + InitializeTrack(); + InitializeBuffer(); + InitializeProgress(); + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void ApplyStyle(ViewStyle style) + { + base.ApplyStyle(style); + + if (style is ProgressStyle progressStyle) + { + Debug.Assert(trackImage != null); + Debug.Assert(progressImage != null); + Debug.Assert(bufferImage != null); + + trackImage.ApplyStyle(progressStyle.Track); + progressImage.ApplyStyle(progressStyle.Progress); + bufferImage.ApplyStyle(progressStyle.Buffer); + } + } + /// /// Dispose Progress and all children on it. /// @@ -507,14 +470,6 @@ namespace Tizen.NUI.Components } } - private void Initialize() - { - // create necessary components - InitializeTrack(); - InitializeBuffer(); - InitializeProgress(); - } - private void InitializeTrack() { if (null == trackImage) @@ -528,7 +483,6 @@ namespace Tizen.NUI.Components PivotPoint = NUI.PivotPoint.TopLeft }; Add(trackImage); - trackImage.ApplyStyle(progressStyle.Track); } } @@ -545,7 +499,6 @@ namespace Tizen.NUI.Components PivotPoint = Tizen.NUI.PivotPoint.TopLeft }; Add(progressImage); - progressImage.ApplyStyle(progressStyle.Progress); } } @@ -562,7 +515,6 @@ namespace Tizen.NUI.Components PivotPoint = Tizen.NUI.PivotPoint.TopLeft }; Add(bufferImage); - bufferImage.ApplyStyle(progressStyle.Buffer); } } } diff --git a/src/Tizen.NUI.Components/Controls/RadioButton.cs b/src/Tizen.NUI.Components/Controls/RadioButton.cs index 41cd43d..5aacfd1 100755 --- a/src/Tizen.NUI.Components/Controls/RadioButton.cs +++ b/src/Tizen.NUI.Components/Controls/RadioButton.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. @@ -84,21 +84,6 @@ namespace Tizen.NUI.Components /// [EditorBrowsable(EditorBrowsableState.Never)] - public override void ApplyStyle(ViewStyle viewStyle) - { - if (viewStyle is ButtonStyle buttonStyle) - { - if (buttonStyle.IsSelectable == null) - { - buttonStyle.IsSelectable = true; - } - - base.ApplyStyle(buttonStyle); - } - } - - /// - [EditorBrowsable(EditorBrowsableState.Never)] protected override ImageView CreateIcon() { return new ImageView diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultGridItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultGridItem.cs index 72a29b3..e2d75a9 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultGridItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultGridItem.cs @@ -37,28 +37,6 @@ namespace Tizen.NUI.Components private DefaultGridItemStyle ItemStyle => ViewStyle as DefaultGridItemStyle; - /// - /// Return a copied Style instance of DefaultLinearItem - /// - /// - /// It returns copied Style instance and changing it does not effect to the DefaultLinearItem. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new DefaultGridItemStyle Style - { - get - { - var result = new DefaultGridItemStyle(ItemStyle); - result.CopyPropertiesFromView(this); - if (itemCaption) result.Caption.CopyPropertiesFromView(itemCaption); - if (itemImage) result.Image.CopyPropertiesFromView(itemImage); - if (itemBadge) result.Badge.CopyPropertiesFromView(itemBadge); - - return result; - } - } - static DefaultGridItem() { } /// diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultLinearItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultLinearItem.cs index 6fbb8d2..0c38475 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultLinearItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultLinearItem.cs @@ -38,30 +38,6 @@ namespace Tizen.NUI.Components private Size prevSize; private DefaultLinearItemStyle ItemStyle => ViewStyle as DefaultLinearItemStyle; - /// - /// Return a copied Style instance of DefaultLinearItem - /// - /// - /// It returns copied Style instance and changing it does not effect to the DefaultLinearItem. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new DefaultLinearItemStyle Style - { - get - { - var result = new DefaultLinearItemStyle(ItemStyle); - result.CopyPropertiesFromView(this); - if (itemLabel) result.Label.CopyPropertiesFromView(itemLabel); - if (itemSubLabel) result.SubLabel.CopyPropertiesFromView(itemSubLabel); - if (itemIcon) result.Icon.CopyPropertiesFromView(itemIcon); - if (itemExtra) result.Extra.CopyPropertiesFromView(itemExtra); - if (itemSeperator) result.Seperator.CopyPropertiesFromView(itemSeperator); - - return result; - } - } - static DefaultLinearItem() { } /// diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultTitleItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultTitleItem.cs index b57da30..8979aa2 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultTitleItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/DefaultTitleItem.cs @@ -36,28 +36,6 @@ namespace Tizen.NUI.Components private Size prevSize; private DefaultTitleItemStyle ItemStyle => ViewStyle as DefaultTitleItemStyle; - /// - /// Return a copied Style instance of DefaultTitleItem - /// - /// - /// It returns copied Style instance and changing it does not effect to the DefaultTitleItem. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new DefaultTitleItemStyle Style - { - get - { - var result = new DefaultTitleItemStyle(ItemStyle); - result.CopyPropertiesFromView(this); - if (itemLabel) result.Label.CopyPropertiesFromView(itemLabel); - if (itemIcon) result.Icon.CopyPropertiesFromView(itemIcon); - if (itemSeperator) result.Seperator.CopyPropertiesFromView(itemSeperator); - - return result; - } - } - static DefaultTitleItem() { } /// diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs index ac8245a..9112b5d 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/Item/RecyclerViewItem.cs @@ -41,10 +41,6 @@ namespace Tizen.NUI.Components if (instance.isEnabled != newEnabled) { instance.isEnabled = newEnabled; - if (instance.ItemStyle != null) - { - instance.ItemStyle.IsEnabled = newEnabled; - } instance.UpdateState(); } } @@ -65,11 +61,6 @@ namespace Tizen.NUI.Components { instance.isSelected = newSelected; - if (instance.ItemStyle != null) - { - instance.ItemStyle.IsSelected = newSelected; - } - if (instance.isSelectable) { instance.UpdateState(); @@ -96,12 +87,6 @@ namespace Tizen.NUI.Components if (instance.isSelectable != newSelectable) { instance.isSelectable = newSelectable; - - if (instance.ItemStyle != null) - { - instance.ItemStyle.IsSelectable = newSelectable; - } - instance.UpdateState(); } } @@ -113,24 +98,6 @@ namespace Tizen.NUI.Components private bool isEnabled = true; private RecyclerViewItemStyle ItemStyle => ViewStyle as RecyclerViewItemStyle; - /// - /// Return a copied Style instance of Toast - /// - /// - /// It returns copied Style instance and changing it does not effect to the Toast. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new RecyclerViewItemStyle Style - { - get - { - var result = new RecyclerViewItemStyle(ItemStyle); - result.CopyPropertiesFromView(this); - return result; - } - } - static RecyclerViewItem() { } /// diff --git a/src/Tizen.NUI.Components/Controls/Scrollbar.cs b/src/Tizen.NUI.Components/Controls/Scrollbar.cs index 2480bf2..ebfd084 100755 --- a/src/Tizen.NUI.Components/Controls/Scrollbar.cs +++ b/src/Tizen.NUI.Components/Controls/Scrollbar.cs @@ -16,6 +16,7 @@ */ using System; using System.ComponentModel; +using System.Diagnostics; using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; @@ -34,78 +35,38 @@ namespace Tizen.NUI.Components /// Bindable property of TrackThickness [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(float), typeof(Scrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) => - { - var instance = ((Scrollbar)bindable); - var thickness = (float?)newValue; - - instance.scrollbarStyle.TrackThickness = thickness; - instance.UpdateTrackThickness(thickness ?? 0); - }, - defaultValueCreator: (bindable) => - { - return ((Scrollbar)bindable).scrollbarStyle.TrackThickness ?? 0; - }); + public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(float), typeof(Scrollbar), default(float), + propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateTrackThickness((float?)newValue ?? 0), + defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackThickness + ); /// Bindable property of ThumbThickness [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ThumbThicknessProperty = BindableProperty.Create(nameof(ThumbThickness), typeof(float), typeof(Scrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) => - { - var instance = ((Scrollbar)bindable); - var thickness = (float?)newValue; - - instance.scrollbarStyle.ThumbThickness = thickness; - instance.UpdateThumbThickness(thickness ?? 0); - }, - defaultValueCreator: (bindable) => - { - return ((Scrollbar)bindable).scrollbarStyle.ThumbThickness ?? 0; - }); + public static readonly BindableProperty ThumbThicknessProperty = BindableProperty.Create(nameof(ThumbThickness), typeof(float), typeof(Scrollbar), default(float), + propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbThickness((float?)newValue ?? 0), + defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbThickness + ); /// Bindable property of TrackColor [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) => - { - var instance = ((Scrollbar)bindable); - var color = (Color)newValue; - - instance.scrollbarStyle.TrackColor = color; - instance.UpdateTrackColor(color); - }, - defaultValueCreator: (bindable) => - { - return ((Scrollbar)bindable).scrollbarStyle.TrackColor; - }); + public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(Scrollbar), null, + propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateTrackColor((Color)newValue), + defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackVisual.MixColor + ); /// Bindable property of ThumbColor [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) => - { - var instance = ((Scrollbar)bindable); - var color = (Color)newValue; - - instance.scrollbarStyle.ThumbColor = color; - instance.UpdateThumbColor(color); - }, - defaultValueCreator: (bindable) => - { - return ((Scrollbar)bindable).scrollbarStyle.ThumbColor; - }); + public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Scrollbar), null, + propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbColor((Color)newValue), + defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbVisual.MixColor + ); /// Bindable property of TrackPadding [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(Scrollbar), null, propertyChanged: (bindable, oldValue, newValue) => - { - var instance = ((Scrollbar)bindable); - var trackPadding = (Extents)newValue; - - instance.scrollbarStyle.TrackPadding = trackPadding; - instance.UpdateTrackPadding(trackPadding); - }, - defaultValueCreator: (bindable) => - { - return ((Scrollbar)bindable).scrollbarStyle.TrackPadding; - }); + public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(Scrollbar), null, + propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateTrackPadding((Extents)newValue), + defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackPadding + ); private ColorVisual trackVisual; private ColorVisual thumbVisual; @@ -113,9 +74,11 @@ namespace Tizen.NUI.Components private Animation thumbSizeAnimation; private Calculator calculator; private Size containerSize = new Size(0, 0); - private ScrollbarStyle scrollbarStyle => ViewStyle as ScrollbarStyle; private bool mScrollEnabled = true; private float previousPosition; + private float trackThickness; + private float thumbThickness; + private PaddingType trackPadding; #endregion Fields @@ -221,6 +184,29 @@ namespace Tizen.NUI.Components /// [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + + trackVisual = new ColorVisual + { + SuppressUpdateVisual = true, + SizePolicy = VisualTransformPolicyType.Absolute, + MixColor = Color.Transparent, + }; + AddVisual("Track", trackVisual); + + thumbVisual = new ColorVisual + { + SuppressUpdateVisual = true, + SizePolicy = VisualTransformPolicyType.Absolute, + MixColor = Color.Transparent, + }; + AddVisual("Thumb", thumbVisual); + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] public override void Initialize(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false) { if (isHorizontal) @@ -238,38 +224,27 @@ namespace Tizen.NUI.Components thumbSizeAnimation?.Stop(); thumbSizeAnimation = null; - PaddingType ensuredPadding = EnsurePadding(TrackPadding); - Size trackSize = calculator.CalculateTrackSize(TrackThickness, containerSize, ensuredPadding); - Vector2 trackPosition = calculator.CalculateTrackPosition(ensuredPadding); + Size trackSize = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding); + Vector2 trackPosition = calculator.CalculateTrackPosition(trackPadding); Size thumbSize = calculator.CalculateThumbSize(ThumbThickness, trackSize); - Vector2 thumbPosition = calculator.CalculateThumbPosition(trackSize, thumbSize, ensuredPadding); - - trackVisual = new ColorVisual - { - SuppressUpdateVisual = true, - MixColor = TrackColor, - SizePolicy = VisualTransformPolicyType.Absolute, - Origin = calculator.CalculatorTrackAlign(), - AnchorPoint = calculator.CalculatorTrackAlign(), - Size = trackSize, - Position = trackPosition, - }; + Vector2 thumbPosition = calculator.CalculateThumbPosition(trackSize, thumbSize, trackPadding); - AddVisual("Track", trackVisual); + Debug.Assert(trackVisual != null && thumbVisual != null); - thumbVisual = new ColorVisual - { - SuppressUpdateVisual = true, - MixColor = ThumbColor, - SizePolicy = VisualTransformPolicyType.Absolute, - Origin = calculator.CalculatorThumbAlign(), - AnchorPoint = calculator.CalculatorThumbAlign(), - Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f, - Size = thumbSize, - Position = thumbPosition, - }; + trackVisual.MixColor = TrackColor; + trackVisual.Origin = calculator.CalculatorTrackAlign(); + trackVisual.AnchorPoint = calculator.CalculatorTrackAlign(); + trackVisual.Size = trackSize; + trackVisual.Position = trackPosition; + trackVisual.UpdateVisual(true); - AddVisual("Thumb", thumbVisual); + thumbVisual.MixColor = ThumbColor; + thumbVisual.Origin = calculator.CalculatorThumbAlign(); + thumbVisual.AnchorPoint = calculator.CalculatorThumbAlign(); + thumbVisual.Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f; + thumbVisual.Size = thumbSize; + thumbVisual.Position = thumbPosition; + thumbVisual.UpdateVisual(true); } /// @@ -287,7 +262,7 @@ namespace Tizen.NUI.Components calculator.currentPosition = position; thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size); - thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, EnsurePadding(TrackPadding)); + thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, trackPadding); thumbVisual.Opacity = calculator.CalculateThumbVisibility() ? 1.0f : 0.0f; if (durationMs == 0) @@ -326,7 +301,7 @@ namespace Tizen.NUI.Components previousPosition = calculator.currentPosition; calculator.currentPosition = position; - thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, EnsurePadding(TrackPadding)); + thumbVisual.Position = calculator.CalculateThumbScrollPosition(trackVisual.Size, thumbVisual.Position, trackPadding); if (durationMs == 0) { @@ -361,11 +336,10 @@ namespace Tizen.NUI.Components return; } - PaddingType ensuredPadding = EnsurePadding(TrackPadding); - trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, ensuredPadding); - trackVisual.Position = calculator.CalculateTrackPosition(ensuredPadding); + trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding); + trackVisual.Position = calculator.CalculateTrackPosition(trackPadding); thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size); - thumbVisual.Position = calculator.CalculateThumbPosition(trackVisual.Size, thumbVisual.Size, ensuredPadding); + thumbVisual.Position = calculator.CalculateThumbPosition(trackVisual.Size, thumbVisual.Size, trackPadding); trackVisual.UpdateVisual(true); thumbVisual.UpdateVisual(true); @@ -404,12 +378,14 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void UpdateTrackThickness(float thickness) { - if (trackVisual == null) + trackThickness = thickness; + + if (calculator == null) { return; } - trackVisual.Size = calculator.CalculateTrackSize(thickness, containerSize, EnsurePadding(TrackPadding)); + trackVisual.Size = calculator.CalculateTrackSize(thickness, containerSize, trackPadding); trackVisual.UpdateVisual(true); } @@ -420,7 +396,9 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void UpdateThumbThickness(float thickness) { - if (thumbVisual == null) + thumbThickness = thickness; + + if (calculator == null) { return; } @@ -464,19 +442,20 @@ namespace Tizen.NUI.Components /// /// Update TrackPadding property of the scrollbar. /// - /// The padding of the track. - protected virtual void UpdateTrackPadding(Extents trackPadding) + /// The padding of the track. + protected virtual void UpdateTrackPadding(Extents padding) { + trackPadding = padding == null ? new PaddingType(0, 0, 0, 0) : new PaddingType(padding.Start, padding.End, padding.Top, padding.Bottom); + if (calculator == null) { return; } - PaddingType ensuredPadding = EnsurePadding(trackPadding); - trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, ensuredPadding); - trackVisual.Position = calculator.CalculateTrackPosition(ensuredPadding); + trackVisual.Size = calculator.CalculateTrackSize(TrackThickness, containerSize, trackPadding); + trackVisual.Position = calculator.CalculateTrackPosition(trackPadding); thumbVisual.Size = calculator.CalculateThumbSize(ThumbThickness, trackVisual.Size); - thumbVisual.Position = calculator.CalculateThumbPaddingPosition(trackVisual.Size, thumbVisual.Size, thumbVisual.Position, ensuredPadding); + thumbVisual.Position = calculator.CalculateThumbPaddingPosition(trackVisual.Size, thumbVisual.Size, thumbVisual.Position, trackPadding); trackVisual.UpdateVisual(true); thumbVisual.UpdateVisual(true); @@ -555,7 +534,7 @@ namespace Tizen.NUI.Components } } - private PaddingType EnsurePadding(Extents padding) => padding == null ? new PaddingType(0, 0, 0, 0) : new PaddingType(padding.Start, padding.End, padding.Top, padding.Bottom); + // private PaddingType EnsurePadding(Extents padding) => padding == null ? new PaddingType(0, 0, 0, 0) : new PaddingType(padding.Start, padding.End, padding.Top, padding.Bottom); #endregion Methods diff --git a/src/Tizen.NUI.Components/Controls/SelectButton.cs b/src/Tizen.NUI.Components/Controls/SelectButton.cs index faca838..f9204f3 100755 --- a/src/Tizen.NUI.Components/Controls/SelectButton.cs +++ b/src/Tizen.NUI.Components/Controls/SelectButton.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. @@ -52,7 +52,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public SelectButton() : base() { - Initialize(); } /// @@ -64,7 +63,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public SelectButton(string style) : base(style) { - Initialize(); } /// @@ -76,7 +74,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public SelectButton(ButtonStyle buttonStyle) : base(buttonStyle) { - Initialize(); } /// @@ -116,6 +113,14 @@ namespace Tizen.NUI.Components } } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + IsSelectable = true; + } + /// /// Dispose SelectButton and all children on it. /// @@ -213,11 +218,6 @@ namespace Tizen.NUI.Components { } - private void Initialize() - { - IsSelectable = true; - } - /// [EditorBrowsable(EditorBrowsableState.Never)] protected override void OnControlStateChanged(ControlStateChangedEventArgs info) diff --git a/src/Tizen.NUI.Components/Controls/Slider.Internal.cs b/src/Tizen.NUI.Components/Controls/Slider.Internal.cs index d0a3aaf..d6be5de 100755 --- a/src/Tizen.NUI.Components/Controls/Slider.Internal.cs +++ b/src/Tizen.NUI.Components/Controls/Slider.Internal.cs @@ -582,11 +582,11 @@ namespace Tizen.NUI.Components { if (lowIndicatorImage != null && lowIndicatorImage != null && lowIndicatorImage.Size != null) { - lowIndicatorImage.Size = sliderStyle.LowIndicatorImage.Size; + lowIndicatorImage.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicatorImage.Size; } if (lowIndicatorText != null && lowIndicatorText != null && lowIndicatorText.Size != null) { - lowIndicatorText.Size = sliderStyle.LowIndicator.Size; + lowIndicatorText.Size = lowIndicatorSize ?? (ViewStyle as SliderStyle)?.LowIndicator.Size; } } } @@ -748,7 +748,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.TrackThickness != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackThickness != null) { curTrackThickness = sliderStyle.TrackThickness.Value; } @@ -765,7 +765,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.TrackPadding != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.TrackPadding != null) { curSpace = sliderStyle.TrackPadding.Start; } @@ -797,7 +797,7 @@ namespace Tizen.NUI.Components private IndicatorType CurrentIndicatorType() { IndicatorType type = IndicatorType.None; - if (sliderStyle != null) + if (ViewStyle is SliderStyle sliderStyle) { type = (IndicatorType)sliderStyle.IndicatorType; } @@ -813,7 +813,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicatorImage != null && sliderStyle.LowIndicatorImage.Size != null) { size = sliderStyle.LowIndicatorImage.Size; } @@ -830,7 +830,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicatorImage != null && sliderStyle.HighIndicatorImage.Size != null) { size = sliderStyle.HighIndicatorImage.Size; } @@ -847,7 +847,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.LowIndicator != null && sliderStyle.LowIndicator.Size != null) { size = sliderStyle.LowIndicator.Size; } @@ -864,7 +864,7 @@ namespace Tizen.NUI.Components } else { - if (sliderStyle != null && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null) + if (ViewStyle is SliderStyle sliderStyle && sliderStyle.HighIndicator != null && sliderStyle.HighIndicator.Size != null) { size = sliderStyle.HighIndicator.Size; } diff --git a/src/Tizen.NUI.Components/Controls/Slider.cs b/src/Tizen.NUI.Components/Controls/Slider.cs index ea8fe35..bbdd0ad 100755 --- a/src/Tizen.NUI.Components/Controls/Slider.cs +++ b/src/Tizen.NUI.Components/Controls/Slider.cs @@ -153,10 +153,6 @@ namespace Tizen.NUI.Components { string newText = (string)newValue; instance.valueIndicatorText.Text = newText; - if (instance.sliderStyle != null) - { - instance.sliderStyle.ValueIndicatorText.Text = newText; - } } }, defaultValueCreator: (bindable) => @@ -334,36 +330,13 @@ namespace Tizen.NUI.Components } /// - /// Return a copied Style instance of Slider + /// Return currently applied style. /// /// - /// It returns copied Style instance and changing it does not effect to the Slider. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) + /// Modifying contents in style may cause unexpected behaviour. /// /// 8 - public new SliderStyle Style - { - get - { - var result = new SliderStyle(sliderStyle); - result.CopyPropertiesFromView(this); - result.Track.CopyPropertiesFromView(bgTrackImage); - result.Progress.CopyPropertiesFromView(slidedTrackImage); - result.Thumb.CopyPropertiesFromView(thumbImage); - result.LowIndicatorImage.CopyPropertiesFromView(lowIndicatorImage); - result.HighIndicatorImage.CopyPropertiesFromView(highIndicatorImage); - result.LowIndicator.CopyPropertiesFromView(lowIndicatorText); - result.HighIndicator.CopyPropertiesFromView(highIndicatorText); - result.ValueIndicatorText.CopyPropertiesFromView(valueIndicatorText); - result.ValueIndicatorImage.CopyPropertiesFromView(valueIndicatorImage); - return result; - } - } - - /// - /// Return a copied Style instance of Slider - /// - private SliderStyle sliderStyle => ViewStyle as SliderStyle; + public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone(); /// /// Gets or sets the direction type of slider. @@ -477,7 +450,6 @@ namespace Tizen.NUI.Components { thumbImage.Size = value; thumbSize = value; - sliderStyle.Thumb.Size = value; } } } @@ -500,7 +472,6 @@ namespace Tizen.NUI.Components { thumbImage.ResourceUrl = value; thumbImageUrl = value; - sliderStyle.Thumb.ResourceUrl = value; } } } @@ -580,7 +551,6 @@ namespace Tizen.NUI.Components { thumbImage.BackgroundColor = value; thumbColor = value; - sliderStyle.Thumb.BackgroundColor = value; } } } @@ -600,7 +570,6 @@ namespace Tizen.NUI.Components if (null != bgTrackImage) { bgTrackImage.BackgroundColor = value; - sliderStyle.Track.BackgroundColor = value; } } } @@ -620,7 +589,6 @@ namespace Tizen.NUI.Components if (null != slidedTrackImage) { slidedTrackImage.BackgroundColor = value; - sliderStyle.Progress.BackgroundColor = value; } } } @@ -675,7 +643,6 @@ namespace Tizen.NUI.Components if (null != warningTrackImage) { warningTrackImage.BackgroundColor = value; - sliderStyle.WarningTrack.BackgroundColor = value; } } } @@ -696,7 +663,6 @@ namespace Tizen.NUI.Components if (null != warningSlidedTrackImage) { warningSlidedTrackImage.BackgroundColor = value; - sliderStyle.WarningProgress.BackgroundColor = value; } } } @@ -774,7 +740,6 @@ namespace Tizen.NUI.Components { if (null == lowIndicatorImage) lowIndicatorImage = new ImageView(); lowIndicatorImage.ResourceUrl = value; - sliderStyle.LowIndicatorImage.ResourceUrl = value; } } @@ -792,7 +757,6 @@ namespace Tizen.NUI.Components { if (null == highIndicatorImage) highIndicatorImage = new ImageView(); highIndicatorImage.ResourceUrl = value; - sliderStyle.HighIndicatorImage.ResourceUrl = value; } } @@ -811,7 +775,6 @@ namespace Tizen.NUI.Components if (null != lowIndicatorText) { lowIndicatorText.Text = value; - sliderStyle.LowIndicator.Text = value; } } } @@ -831,7 +794,6 @@ namespace Tizen.NUI.Components if (null != highIndicatorText) { highIndicatorText.Text = value; - sliderStyle.HighIndicator.Text = value; } } } @@ -871,7 +833,6 @@ namespace Tizen.NUI.Components if (null != highIndicatorText) { highIndicatorText.Size = value; - sliderStyle.HighIndicator.Size = value; } } } @@ -942,7 +903,6 @@ namespace Tizen.NUI.Components if (null != valueIndicatorImage) { valueIndicatorImage.Size = value; - sliderStyle.ValueIndicatorImage.Size = value; } } } @@ -963,7 +923,6 @@ namespace Tizen.NUI.Components if (null != valueIndicatorImage) { valueIndicatorImage.ResourceUrl = value; - sliderStyle.ValueIndicatorImage.ResourceUrl = value; } } } diff --git a/src/Tizen.NUI.Components/Controls/Switch.cs b/src/Tizen.NUI.Components/Controls/Switch.cs index c8fedd6..42995fb 100755 --- a/src/Tizen.NUI.Components/Controls/Switch.cs +++ b/src/Tizen.NUI.Components/Controls/Switch.cs @@ -39,7 +39,6 @@ namespace Tizen.NUI.Components /// 6 public Switch() : base() { - Initialize(); } /// @@ -49,7 +48,6 @@ namespace Tizen.NUI.Components /// 8 public Switch(string style) : base(style) { - Initialize(); } /// @@ -59,7 +57,6 @@ namespace Tizen.NUI.Components /// 8 public Switch(SwitchStyle switchStyle) : base(switchStyle) { - Initialize(); } /// @@ -70,6 +67,10 @@ namespace Tizen.NUI.Components { base.OnInitialize(); SetAccessibilityConstructor(Role.ToggleButton); + IsSelectable = true; +#if PROFILE_MOBILE + Feedback = true; +#endif } /// @@ -97,24 +98,13 @@ namespace Tizen.NUI.Components public event EventHandler SelectedChanged; /// - /// Return a copied Style instance of Switch + /// Return currently applied style. /// /// - /// It returns copied Style instance and changing it does not effect to the Switch. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) + /// Modifying contents in style may cause unexpected behaviour. /// /// 8 - public new SwitchStyle Style - { - get - { - var result = new SwitchStyle(ViewStyle as SwitchStyle); - result.CopyPropertiesFromView(this); - result.Track.CopyPropertiesFromView(Track); - result.Thumb.CopyPropertiesFromView(Thumb); - return result; - } - } + public new SwitchStyle Style => (SwitchStyle)(ViewStyle as SwitchStyle)?.Clone(); /// /// Apply style to switch. @@ -123,8 +113,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public override void ApplyStyle(ViewStyle viewStyle) { - base.ApplyStyle(viewStyle); - SwitchStyle swStyle = viewStyle as SwitchStyle; if (null != swStyle) @@ -139,6 +127,8 @@ namespace Tizen.NUI.Components Thumb.ApplyStyle(swStyle.Thumb); } } + + base.ApplyStyle(viewStyle); } /// @@ -335,14 +325,6 @@ namespace Tizen.NUI.Components } } - private void Initialize() - { - IsSelectable = true; -#if PROFILE_MOBILE - Feedback = true; -#endif - } - private void OnSelect() { if (IsHighlighted) diff --git a/src/Tizen.NUI.Components/Controls/Tab.cs b/src/Tizen.NUI.Components/Controls/Tab.cs index e461639..aa596ef 100755 --- a/src/Tizen.NUI.Components/Controls/Tab.cs +++ b/src/Tizen.NUI.Components/Controls/Tab.cs @@ -78,23 +78,13 @@ namespace Tizen.NUI.Components public event EventHandler ItemChangedEvent; /// - /// Return a copied Style instance of Tab + /// Return currently applied style. /// /// - /// It returns copied Style instance and changing it does not effect to the Tab. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) + /// Modifying contents in style may cause unexpected behaviour. /// /// 8 - public new TabStyle Style - { - get - { - var result = new TabStyle(tabStyle); - result.CopyPropertiesFromView(this); - result.UnderLine.CopyPropertiesFromView(underline); - return result; - } - } + public TabStyle Style => (TabStyle)(ViewStyle as TabStyle)?.Clone(); /// /// Get underline of Tab. diff --git a/src/Tizen.NUI.Components/Controls/Toast.cs b/src/Tizen.NUI.Components/Controls/Toast.cs index bf221aa..061f135 100755 --- a/src/Tizen.NUI.Components/Controls/Toast.cs +++ b/src/Tizen.NUI.Components/Controls/Toast.cs @@ -58,7 +58,6 @@ namespace Tizen.NUI.Components var instance = (Toast)bindable; if (newValue != null) { - instance.toastStyle.Duration = (uint)newValue; if (instance.timer == null) { instance.timer = new Timer(instance.duration); @@ -69,7 +68,7 @@ namespace Tizen.NUI.Components defaultValueCreator: (bindable) => { var instance = (Toast)bindable; - return instance.toastStyle.Duration ?? instance.duration; + return instance.timer == null ? instance.duration : instance.timer.Interval; }); /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -89,26 +88,7 @@ namespace Tizen.NUI.Components private string strText = null; private Timer timer = null; private readonly uint duration = 3000; - private ToastStyle toastStyle => ViewStyle as ToastStyle; - /// - /// Return a copied Style instance of Toast - /// - /// - /// It returns copied Style instance and changing it does not effect to the Toast. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new ToastStyle Style - { - get - { - var result = new ToastStyle(toastStyle); - result.CopyPropertiesFromView(this); - result.Text.CopyPropertiesFromView(textLabel); - return result; - } - } static Toast() { } /// @@ -118,7 +98,6 @@ namespace Tizen.NUI.Components [Obsolete("Deprecated in API8; Will be removed in API10")] public Toast() : base() { - Initialize(); } /// @@ -128,7 +107,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Toast(ToastStyle toastStyle) : base(toastStyle) { - Initialize(); } /// @@ -138,7 +116,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Toast(string style) : base(style) { - Initialize(); } /// @@ -314,6 +291,33 @@ namespace Tizen.NUI.Components } } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnInitialize() + { + base.OnInitialize(); + + WidthResizePolicy = ResizePolicyType.FitToChildren; + HeightResizePolicy = ResizePolicyType.FitToChildren; + + textLabel = new TextLabel() + { + PositionUsesPivotPoint = true, + ParentOrigin = Tizen.NUI.ParentOrigin.Center, + PivotPoint = Tizen.NUI.PivotPoint.Center, + WidthResizePolicy = ResizePolicyType.UseNaturalSize, + HeightResizePolicy = ResizePolicyType.UseNaturalSize, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = Color.White, + }; + this.Add(textLabel); + + this.VisibilityChanged += OnVisibilityChanged; + timer = new Timer(duration); + timer.Tick += OnTick; + } + /// /// Apply style to toast. /// @@ -321,30 +325,10 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public override void ApplyStyle(ViewStyle viewStyle) { - WidthResizePolicy = ResizePolicyType.FitToChildren; - HeightResizePolicy = ResizePolicyType.FitToChildren; - base.ApplyStyle(viewStyle); - ToastStyle toastStyle = viewStyle as ToastStyle; - - if (null != toastStyle) + if (viewStyle is ToastStyle toastStyle) { - if (null == textLabel) - { - textLabel = new TextLabel() - { - PositionUsesPivotPoint = true, - ParentOrigin = Tizen.NUI.ParentOrigin.Center, - PivotPoint = Tizen.NUI.PivotPoint.Center, - WidthResizePolicy = ResizePolicyType.UseNaturalSize, - HeightResizePolicy = ResizePolicyType.UseNaturalSize, - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - TextColor = Color.White, - }; - this.Add(textLabel); - } textLabel.ApplyStyle(toastStyle.Text); } } @@ -393,29 +377,6 @@ namespace Tizen.NUI.Components return new ToastStyle(); } - private void Initialize() - { - if (null == textLabel) - { - textLabel = new TextLabel() - { - PositionUsesPivotPoint = true, - ParentOrigin = Tizen.NUI.ParentOrigin.Center, - PivotPoint = Tizen.NUI.PivotPoint.Center, - WidthResizePolicy = ResizePolicyType.UseNaturalSize, - HeightResizePolicy = ResizePolicyType.UseNaturalSize, - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - TextColor = Color.White, - }; - this.Add(textLabel); - } - - this.VisibilityChanged += OnVisibilityChanged; - timer = new Timer(toastStyle.Duration ?? duration); - timer.Tick += OnTick; - } - private bool OnTick(object sender, EventArgs e) { Hide(); diff --git a/src/Tizen.NUI.Components/Style/PaginationStyle.cs b/src/Tizen.NUI.Components/Style/PaginationStyle.cs index 403daab..216fafa 100755 --- a/src/Tizen.NUI.Components/Style/PaginationStyle.cs +++ b/src/Tizen.NUI.Components/Style/PaginationStyle.cs @@ -39,9 +39,9 @@ namespace Tizen.NUI.Components /// The IndicatorImageUrlSelector bindable property. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty IndicatorImageUrlSelectorProperty = BindableProperty.Create("IndicatorImageUrlSelector", typeof(Selector), typeof(PaginationStyle), null, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty IndicatorImageUrlSelectorProperty = BindableProperty.Create("IndicatorImageUrl", typeof(Selector), typeof(PaginationStyle), null, propertyChanged: (bindable, oldValue, newValue) => { - ((PaginationStyle)bindable).indicatorImageUrl = ((Selector)newValue)?.Clone(); + ((PaginationStyle)bindable).indicatorImageUrl = (Selector)newValue; }, defaultValueCreator: (bindable) => { diff --git a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs index ce27093..ddda07e 100755 --- a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs @@ -250,7 +250,9 @@ namespace Tizen.NUI.Components { Normal = FrameworkInformation.ResourcePath + "nui_component_default_pagination_normal_dot.png", Selected = FrameworkInformation.ResourcePath + "nui_component_default_pagination_focus_dot.png", - } + }, + IndicatorSize = new Size(10, 10), + IndicatorSpacing = 10, }); theme.AddStyleWithoutClone("Tizen.NUI.Components.Scrollbar", new ScrollbarStyle() diff --git a/src/Tizen.NUI.Wearable/src/public/CircularPagination.cs b/src/Tizen.NUI.Wearable/src/public/CircularPagination.cs index 68c0038..d8018dd 100755 --- a/src/Tizen.NUI.Wearable/src/public/CircularPagination.cs +++ b/src/Tizen.NUI.Wearable/src/public/CircularPagination.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. @@ -616,7 +616,7 @@ namespace Tizen.NUI.Wearable private void Initialize() { - circularPaginationStyle = Style as CircularPaginationStyle; + circularPaginationStyle = ViewStyle as CircularPaginationStyle; if (circularPaginationStyle == null) { throw new Exception("CircularPagination style is null."); diff --git a/src/Tizen.NUI.Wearable/src/public/CircularProgress.cs b/src/Tizen.NUI.Wearable/src/public/CircularProgress.cs index f8e1d87..f996e47 100755 --- a/src/Tizen.NUI.Wearable/src/public/CircularProgress.cs +++ b/src/Tizen.NUI.Wearable/src/public/CircularProgress.cs @@ -201,24 +201,6 @@ namespace Tizen.NUI.Wearable #region Properties /// - /// Return a copied Style instance of CircularProgress - /// - /// - /// It returns copied Style instance and changing it does not effect to the CircularProgress. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new CircularProgressStyle Style - { - get - { - var result = new CircularProgressStyle(ViewStyle as CircularProgressStyle); - result.CopyPropertiesFromView(this); - return result; - } - } - - /// /// The thickness of the track and progress. /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs b/src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs index fafcd7b..368e9c8 100755 --- a/src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs +++ b/src/Tizen.NUI.Wearable/src/public/CircularScrollbar.cs @@ -146,24 +146,6 @@ namespace Tizen.NUI.Wearable #region Properties /// - /// Return a copied Style instance of CircularScrollbar - /// - /// - /// It returns copied Style instance and changing it does not effect to the CircularScrollbar. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public CircularScrollbarStyle Style - { - get - { - var result = new CircularScrollbarStyle(ViewStyle as CircularScrollbarStyle); - result.CopyPropertiesFromView(this); - return result; - } - } - - /// /// The thickness of the scrollbar and track. /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI.Wearable/src/public/CircularSlider.cs b/src/Tizen.NUI.Wearable/src/public/CircularSlider.cs index 4f2dfa4..eeb5eeb 100755 --- a/src/Tizen.NUI.Wearable/src/public/CircularSlider.cs +++ b/src/Tizen.NUI.Wearable/src/public/CircularSlider.cs @@ -252,24 +252,6 @@ namespace Tizen.NUI.Wearable #region Properties /// - /// Return a copied Style instance of CircularSlider - /// - /// - /// It returns copied Style instance and changing it does not effect to the CircularSlider. - /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle) - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new CircularSliderStyle Style - { - get - { - var result = new CircularSliderStyle(ViewStyle as CircularSliderStyle); - result.CopyPropertiesFromView(this); - return result; - } - } - - /// /// The thickness of the track and progress. /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI.Wearable/src/public/Title.cs b/src/Tizen.NUI.Wearable/src/public/Title.cs index c03dbbb..660198b 100755 --- a/src/Tizen.NUI.Wearable/src/public/Title.cs +++ b/src/Tizen.NUI.Wearable/src/public/Title.cs @@ -79,16 +79,6 @@ namespace Tizen.NUI.Components } /// - /// Return a copied Style instance of the Title. - /// - /// - /// It returns copied style instance so that changing it does not effect to the view. - /// Style setting is possible by using constructor or the function of . - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public new TextLabelStyle Style => ViewStyle as TextLabelStyle; - - /// /// The constructor of the Title class with specific Style. /// /// Construct Style diff --git a/src/Tizen.NUI/src/public/BaseComponents/CustomView.cs b/src/Tizen.NUI/src/public/BaseComponents/CustomView.cs index 92677b0..dabf1b9 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/CustomView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/CustomView.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. @@ -65,9 +65,9 @@ namespace Tizen.NUI.BaseComponents /// CustomView Behaviour /// CustomView ViewStyle [EditorBrowsable(EditorBrowsableState.Never)] - public CustomView(string typeName, CustomViewBehaviour behaviour, ViewStyle viewStyle) : base(typeName, new ViewWrapperImpl(behaviour), viewStyle) + public CustomView(string typeName, CustomViewBehaviour behaviour, ViewStyle viewStyle) : this(typeName, behaviour) { - Initialize(); + InitializeStyle(viewStyle); } /// @@ -138,7 +138,8 @@ namespace Tizen.NUI.BaseComponents } /// - /// This method is called after the control has been initialized.
+ /// This method is called after the CustomView has been initialized.
+ /// After OnInitialize, the view will apply the style if it exists in the theme or it was given from constructor.
/// Derived classes should do any second phase initialization by overriding this method.
///
/// 3 @@ -916,13 +917,12 @@ namespace Tizen.NUI.BaseComponents viewWrapperImpl.OnTap = new ViewWrapperImpl.OnTapDelegate(OnTap); viewWrapperImpl.OnLongPress = new ViewWrapperImpl.OnLongPressDelegate(OnLongPress); - // Make sure CustomView is initialized. - OnInitialize(); - // Set the StyleName the name of the View // We have to do this because the StyleManager on Native side can't workout it out // This will also ensure that the style of views/visuals initialized above are applied by the style manager. SetStyleName(this.GetType().Name); + + OnInitialize(); } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs index 0467fd3..707100d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs @@ -346,6 +346,62 @@ namespace Tizen.NUI.BaseComponents } } + private bool EqualsItem(T a, T b) + { + return Object.ReferenceEquals(a, b) || (a != null && a.Equals(b)); + } + + /// + /// Determines whether the specified object is equal to the current object. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(System.Object other) + { + var x = other as Selector; + + if (x == null || x.SelectorItems.Count != SelectorItems.Count) + { + return false; + } + + if (!EqualsItem(All, x.All)) + { + return false; + } + + foreach (var item in SelectorItems) + { + var found = SelectorItems.Find(i => i.State == item.State); + + if (found == null || !EqualsItem(item.Value, found.Value)) + { + return false; + } + } + + return true; + } + + /// + /// Serves as the default hash function. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() + { + int hash = 17; + hash = (hash * 23) + (All == null ? 0 : All.GetHashCode()); + hash = (hash * 23) + SelectorItems.Count; + + // Order of items should not effect to the result value. + int itemSum = 0; + foreach (var item in SelectorItems) + { + itemSum += item.State.GetHashCode() + (item.Value == null ? 0 : item.Value.GetHashCode()); + } + + return (hash * 23) + itemSum; + } + internal bool HasMultiValue() { return SelectorItems.Count > 1; diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index 176520c..98eb2de 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -434,13 +434,6 @@ namespace Tizen.NUI.BaseComponents return cloned; } - /// Create a cloned ViewStyle. - [EditorBrowsable(EditorBrowsableState.Never)] - public void Merge(ViewStyle other) - { - CopyFrom(other); - } - /// /// Release instance. /// @@ -535,5 +528,29 @@ namespace Tizen.NUI.BaseComponents { return (ViewStyle)Activator.CreateInstance(GetType()); } + + /// Merge other style into the current style without creating new one. + [EditorBrowsable(EditorBrowsableState.Never)] + internal void MergeDirectly(ViewStyle other) + { + CopyFrom(other); + } + } + + /// Extension methods for ViewStyle class. + [EditorBrowsable(EditorBrowsableState.Never)] + public static class ViewStyleExtension + { + /// Merge two styles into the new one. + /// Thrown when failed because of an invalid parameter. + [EditorBrowsable(EditorBrowsableState.Never)] + public static TOut Merge(this TOut value, TOut other) where TOut : Tizen.NUI.BaseComponents.ViewStyle + { + var newStyle = value.Clone() as TOut; + + newStyle.CopyFrom(other); + + return newStyle; + } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index e3fc7f9..0867448 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.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. @@ -152,9 +152,13 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static bool LayoutingDisabled { get; set; } = true; - /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + /// + /// The style instance applied to this view. + /// Note that please do not modify the ViewStyle. + /// Modifying ViewStyle will affect other views with same ViewStyle. + /// [EditorBrowsable(EditorBrowsableState.Never)] - public ViewStyle ViewStyle + protected ViewStyle ViewStyle { get { @@ -2673,11 +2677,29 @@ namespace Tizen.NUI.BaseComponents UpdateStyle(); } - /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + private bool IsViewPropertyDirty(BindableProperty styleProperty) + { + if (dirtyPropertySet.Count == 0) + { + 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); + } + + /// + /// Apply style instance to the view. + /// Basically it sets the bindable property to the value of the bindable property with same name in the style. + /// [EditorBrowsable(EditorBrowsableState.Never)] public virtual void ApplyStyle(ViewStyle viewStyle) { - if (null == viewStyle || this.viewStyle == viewStyle) return; + if (viewStyle == null || this.viewStyle == viewStyle) return; this.viewStyle = viewStyle; @@ -2687,6 +2709,11 @@ namespace Tizen.NUI.BaseComponents return; } + if (dirtyPropertySet == null) + { + dirtyPropertySet = new HashSet(); + } + BindableProperty.GetBindablePropertysOfType(GetType(), out var bindablePropertyOfView); if (bindablePropertyOfView == null) @@ -2694,11 +2721,17 @@ namespace Tizen.NUI.BaseComponents return; } - var dirtyProperties = new BindableProperty[viewStyle.DirtyProperties.Count]; - viewStyle.DirtyProperties.CopyTo(dirtyProperties); + var dirtyStyleProperties = new BindableProperty[viewStyle.DirtyProperties.Count]; + viewStyle.DirtyProperties.CopyTo(dirtyStyleProperties); - foreach (var sourceProperty in dirtyProperties) + foreach (var sourceProperty in dirtyStyleProperties) { + if (blockSetDirty && IsViewPropertyDirty(sourceProperty)) + { + // Skip applying theme style for a property set by user. + continue; + } + var sourceValue = viewStyle.GetValue(sourceProperty); if (sourceValue == null) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 95ab940..9df410d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -16,7 +16,9 @@ */ using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Runtime.CompilerServices; namespace Tizen.NUI.BaseComponents { @@ -26,7 +28,9 @@ namespace Tizen.NUI.BaseComponents /// 3 public partial class View { + private static bool blockSetDirty = false; private ViewSelectorData selectorData; + private HashSet dirtyPropertySet; internal string styleName; @@ -1077,15 +1081,6 @@ namespace Tizen.NUI.BaseComponents shadow.Dispose(); } - internal void UpdateStyle() - { - ViewStyle newStyle; - if (styleName == null) newStyle = ThemeManager.GetStyle(GetType()); - else newStyle = ThemeManager.GetStyle(styleName); - - if (newStyle != null && (viewStyle == null || viewStyle.GetType() == newStyle.GetType())) ApplyStyle(newStyle); - } - /// /// Get selector value from the triggerable selector or related property. /// @@ -1178,6 +1173,21 @@ namespace Tizen.NUI.BaseComponents return false; } + /// + /// Call this method from a child class to notify that a change happened on a property. + /// + /// The name of the property that changed. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + base.OnPropertyChanged(propertyName); + + if (!blockSetDirty) + { + dirtyPropertySet?.Add(propertyName); + } + } + private void DisConnectFromSignals() { // Save current CPtr. @@ -1316,6 +1326,16 @@ namespace Tizen.NUI.BaseComponents SwigCPtr = currentCPtr; } + /// + /// Apply initial style to the view. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected void InitializeStyle(ViewStyle style = null) + { + if (style != null) ApplyStyle(style); // Use given style + else UpdateStyle(); // Use style in the current theme + } + private View ConvertIdToView(uint id) { View view = GetParent()?.FindCurrentChildById(id); @@ -1393,10 +1413,18 @@ namespace Tizen.NUI.BaseComponents return false; } - private void InitializeStyle(ViewStyle style) + private void UpdateStyle() { - if (style != null) ApplyStyle(style.Clone()); // Use given style - else if (ThemeManager.ThemeApplied) UpdateStyle(); // Use style in the current theme + ViewStyle newStyle; + if (string.IsNullOrEmpty(styleName)) newStyle = ThemeManager.GetStyleWithoutClone(GetType()); + else newStyle = ThemeManager.GetStyleWithoutClone(styleName); + + if (newStyle != null) + { + blockSetDirty = true; + ApplyStyle(newStyle); + blockSetDirty = false; + } } private ViewSelectorData EnsureSelectorData() => selectorData ?? (selectorData = new ViewSelectorData()); diff --git a/src/Tizen.NUI/src/public/CustomView/ViewWrapper.cs b/src/Tizen.NUI/src/public/CustomView/ViewWrapper.cs index 500f05a..5192c67 100755 --- a/src/Tizen.NUI/src/public/CustomView/ViewWrapper.cs +++ b/src/Tizen.NUI/src/public/CustomView/ViewWrapper.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -27,7 +27,7 @@ namespace Tizen.NUI { internal ViewWrapperImpl viewWrapperImpl; - internal ViewWrapper(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn, null) + internal ViewWrapper(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } @@ -37,12 +37,6 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal ViewWrapper(string typeName, ViewWrapperImpl implementation, ViewStyle viewStyle) : base(Interop.ViewWrapper.New(typeName, ViewWrapperImpl.getCPtr(implementation)), true, viewStyle) - { - viewWrapperImpl = implementation; - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) diff --git a/src/Tizen.NUI/src/public/Theme/Theme.cs b/src/Tizen.NUI/src/public/Theme/Theme.cs index d5e866d..ca667fa 100755 --- a/src/Tizen.NUI/src/public/Theme/Theme.cs +++ b/src/Tizen.NUI/src/public/Theme/Theme.cs @@ -121,7 +121,7 @@ namespace Tizen.NUI var baseStyle = item.Value?.Clone(); if (map.ContainsKey(item.Key)) { - baseStyle.Merge(map[item.Key]); + baseStyle.MergeDirectly(map[item.Key]); } map[item.Key] = baseStyle; } @@ -181,7 +181,7 @@ namespace Tizen.NUI if (map.TryGetValue(styleName, out ViewStyle style) && style != null && style.GetType() == value.GetType()) { - style.Merge(value); + style.MergeDirectly(value); } else { @@ -311,7 +311,7 @@ namespace Tizen.NUI } else if (map.ContainsKey(item.Key) && !item.Value.SolidNull) { - map[item.Key].Merge(item.Value); + map[item.Key].MergeDirectly(item.Value); } else { @@ -343,7 +343,7 @@ namespace Tizen.NUI } else if (map.ContainsKey(item.Key) && !item.Value.SolidNull) { - map[item.Key].Merge(item.Value); + map[item.Key].MergeDirectly(item.Value); } else { diff --git a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs index 5480b67..b1e229e 100755 --- a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs +++ b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs @@ -75,7 +75,7 @@ namespace Tizen.NUI } } - internal static bool ThemeApplied => defaultTheme.Count > 0 || (currentTheme != null && currentTheme.Count > 0); + private static bool ThemeApplied => defaultTheme.Count > 0 || (currentTheme != null && currentTheme.Count > 0); /// /// Apply theme to the NUI. @@ -114,7 +114,8 @@ namespace Tizen.NUI if (theme != null) { - CurrentTheme = theme; + defaultTheme = theme; + NotifyThemeChanged(); return true; } @@ -133,10 +134,7 @@ namespace Tizen.NUI public static ViewStyle GetStyle(string styleName) { if (styleName == null) throw new ArgumentNullException(nameof(styleName)); - - if (!ThemeApplied) return null; - - return (currentTheme?.GetStyle(styleName) ?? defaultTheme.GetStyle(styleName))?.Clone(); + return GetStyleWithoutClone(styleName)?.Clone(); } /// @@ -148,10 +146,31 @@ namespace Tizen.NUI public static ViewStyle GetStyle(Type viewType) { if (viewType == null) throw new ArgumentNullException(nameof(viewType)); + return GetStyleWithoutClone(viewType)?.Clone(); + } + /// + /// Load a style with style name in the current theme. + /// + /// The style name. + [EditorBrowsable(EditorBrowsableState.Never)] + internal static ViewStyle GetStyleWithoutClone(string styleName) + { + if (!ThemeApplied) return null; + + return currentTheme?.GetStyle(styleName) ?? defaultTheme.GetStyle(styleName); + } + + /// + /// Load a style with View type in the current theme. + /// + /// The type of View. + [EditorBrowsable(EditorBrowsableState.Never)] + internal static ViewStyle GetStyleWithoutClone(Type viewType) + { if (!ThemeApplied) return null; - return (currentTheme?.GetStyle(viewType) ?? defaultTheme.GetStyle(viewType))?.Clone(); + return currentTheme?.GetStyle(viewType) ?? defaultTheme.GetStyle(viewType); } /// -- 2.7.4