From: Jiyun Yang Date: Wed, 15 Feb 2023 02:36:52 +0000 (+0900) Subject: [NUI] Fix Switch thumb positioning X-Git-Tag: submit/tizen/20230221.111427~1^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=838083d17a959187a8fcdba310d43503cccf11a2;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix Switch thumb positioning When the size of thumb or track changes, the it should update the position of the thumb properly. And to prevent unnecessary switch state updating while applying style, upgrade styleApplying flag to int type. Signed-off-by: Jiyun Yang --- diff --git a/src/Tizen.NUI.Components/Controls/Button.Internal.cs b/src/Tizen.NUI.Components/Controls/Button.Internal.cs index b4815a2f9..071f7f2ce 100644 --- a/src/Tizen.NUI.Components/Controls/Button.Internal.cs +++ b/src/Tizen.NUI.Components/Controls/Button.Internal.cs @@ -34,7 +34,7 @@ namespace Tizen.NUI.Components private EventHandler stateChangeHandler; private bool isPressed = false; - private bool styleApplying = false; + internal int styleApplying = 0; /// /// Gets accessibility name. @@ -193,7 +193,7 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] protected void UpdateState() { - if (styleApplying) return; + if (styleApplying > 0) return; ControlState sourceState = ControlState; ControlState targetState; diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index cc4bd78fe..033867a7f 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.cs @@ -1005,7 +1005,7 @@ namespace Tizen.NUI.Components { Debug.Assert(buttonIcon != null && buttonText != null); - styleApplying = true; + styleApplying++; base.ApplyStyle(viewStyle); @@ -1041,7 +1041,8 @@ namespace Tizen.NUI.Components } } - styleApplying = false; + styleApplying--; + UpdateState(); } diff --git a/src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs b/src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs index b52ba0e67..b431584b7 100755 --- a/src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs +++ b/src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs @@ -82,6 +82,26 @@ namespace Tizen.NUI.Components.Extension } } + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override ImageView OnCreateTrack(Switch switchButton, ImageView track) + { + base.OnCreateTrack(switchButton, track); + track.Relayout += (s, e) => { + switchButton.Thumb.PositionX = switchButton.IsSelected ? switchButton.Track.Size.Width - switchButton.Thumb.Size.Width : 0; + }; + return track; + } + + /// + public override ImageView OnCreateThumb(Switch switchButton, ImageView thumb) + { + base.OnCreateThumb(switchButton, thumb); + thumb.Relayout += (s, e) => { + thumb.PositionX = switchButton.IsSelected ? switchButton.Track.Size.Width - thumb.Size.Width : 0; + }; + return thumb; + } [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void Dispose(bool disposing) diff --git a/src/Tizen.NUI.Components/Controls/Switch.cs b/src/Tizen.NUI.Components/Controls/Switch.cs index 1c1c885bd..9e4e69f28 100755 --- a/src/Tizen.NUI.Components/Controls/Switch.cs +++ b/src/Tizen.NUI.Components/Controls/Switch.cs @@ -115,6 +115,10 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public override void ApplyStyle(ViewStyle viewStyle) { + styleApplying++; + + base.ApplyStyle(viewStyle); + if (viewStyle is SwitchStyle switchStyle) { if (Extension is SwitchExtension extension) @@ -137,8 +141,9 @@ namespace Tizen.NUI.Components Thumb.ApplyStyle(switchStyle.Thumb); } } + styleApplying--; - base.ApplyStyle(viewStyle); + UpdateState(); } ///