From afdc4bd9e9847484a5991bdc04a5779877115fd4 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Thu, 28 Oct 2021 19:19:47 +0900 Subject: [PATCH] [NUI] Ignore ResizePolicy when View size is calculated by Layout View size is calculated based on Width/HeightSpecification if View's Layout is set. However, if View's ResizePolicy is not UseNaturalSize (default value), then View's ResizePolicy also affects View size calculation in DALi although View's Layout is set. To ignore ResizePolicy when View size is calculated by View's Layout, ResizePolicy is set with FIXED when View's Layout is set. ResizePolicy is stored when Layout is set and it is ignored when View size is calculated. ResizePolicy is restored when Layout is unset and it is considered when View size is calculated. --- src/Tizen.NUI/src/public/BaseComponents/View.cs | 13 ++++++ .../src/public/BaseComponents/ViewInternal.cs | 48 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 6746df1..1829836 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -1856,6 +1856,9 @@ namespace Tizen.NUI.BaseComponents } set { + // Store ResizePolicy to restore it when Layout is unset. + widthResizePolicy = value; + SetValue(WidthResizePolicyProperty, value); NotifyPropertyChanged(); } @@ -1873,6 +1876,9 @@ namespace Tizen.NUI.BaseComponents } set { + // Store ResizePolicy to restore it when Layout is unset. + heightResizePolicy = value; + SetValue(HeightResizePolicyProperty, value); NotifyPropertyChanged(); } @@ -2549,6 +2555,13 @@ namespace Tizen.NUI.BaseComponents } set { + // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated. + // SetValue(LayoutProperty, value) sets InternalLayout only if layout is not null. + if (value == null) + { + RestoreResizePolicy(); + } + SetValue(LayoutProperty, value); } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 4905a60..0c6c021 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -31,6 +31,14 @@ namespace Tizen.NUI.BaseComponents public partial class View { private MergedStyle mergedStyle = null; + + // Ignore WidthResizePolicy and HeightResizePolicy when Layout is set. + // Restore WidthResizePolicy and HeightResizePolicy when Layout is unset. + // See also IgnoreResizePolicy() and RestoreResizePolicy(). + private ResizePolicyType widthResizePolicy = ResizePolicyType.Fixed; + private ResizePolicyType heightResizePolicy = ResizePolicyType.Fixed; + private bool isIgnoredResizePolicy = false; + internal string styleName; internal MergedStyle MergedStyle @@ -189,6 +197,17 @@ namespace Tizen.NUI.BaseComponents internal void SetLayout(LayoutItem layout) { + // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated. + if (layout == null) + { + RestoreResizePolicy(); + } + // ResizePolicy is stored when Layout is set and it is ignored when View size is calculated. + else + { + IgnoreResizePolicy(); + } + Window.Instance.LayoutController.CreateProcessCallback(); this.layout = layout; this.layout?.AttachToOwner(this); @@ -1010,6 +1029,8 @@ namespace Tizen.NUI.BaseComponents /// internal void ResetLayout() { + // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated. + RestoreResizePolicy(); layout = null; } @@ -1464,5 +1485,32 @@ namespace Tizen.NUI.BaseComponents return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData()); } + + // ResizePolicy is stored when Layout is set and it is ignored when View size is calculated. + private void IgnoreResizePolicy() + { + if (isIgnoredResizePolicy) return; + isIgnoredResizePolicy = true; + + widthResizePolicy = WidthResizePolicy; + heightResizePolicy = HeightResizePolicy; + + // Set bindable property directly not to store width/heightResizePolicy duplicately. + SetValue(WidthResizePolicyProperty, ResizePolicyType.Fixed); + SetValue(HeightResizePolicyProperty, ResizePolicyType.Fixed); + NotifyPropertyChanged(); + } + + // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated. + private void RestoreResizePolicy() + { + if (!isIgnoredResizePolicy) return; + isIgnoredResizePolicy = false; + + // Set bindable property directly not to store width/heightResizePolicy duplicately. + SetValue(WidthResizePolicyProperty, widthResizePolicy); + SetValue(HeightResizePolicyProperty, heightResizePolicy); + NotifyPropertyChanged(); + } } } -- 2.7.4