[NUI] Fix Switch thumb positioning
authorJiyun Yang <ji.yang@samsung.com>
Wed, 15 Feb 2023 02:36:52 +0000 (11:36 +0900)
committerEunki Hong <h.pichulia@gmail.com>
Tue, 21 Feb 2023 11:04:00 +0000 (20:04 +0900)
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 <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/Button.Internal.cs
src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs
src/Tizen.NUI.Components/Controls/Switch.cs

index b4815a2f91484c0f13cf491d499188da47e0f5a1..071f7f2ce6afa3c2cdf3b74a26ff606142f2041d 100644 (file)
@@ -34,7 +34,7 @@ namespace Tizen.NUI.Components
         private EventHandler<StateChangedEventArgs> stateChangeHandler;
 
         private bool isPressed = false;
-        private bool styleApplying = false;
+        internal int styleApplying = 0;
 
         /// <summary>
         /// 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;
index cc4bd78fe534aff7dd13b38f2ddd147e9393e66a..033867a7f5e125125871c9575afb5eca3ec39115 100755 (executable)
@@ -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();
         }
 
index b52ba0e678e78530c8e14a5ccf84f479b9dea9b4..b431584b70467f580e25083ad6a0763fdcb469c1 100755 (executable)
@@ -82,6 +82,26 @@ namespace Tizen.NUI.Components.Extension
             }
         }
 
+        /// <inheritdoc/>
+        [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;
+        }
+
+        /// <inheritdoc/>
+        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)
index 1c1c885bdfa67c37943395e5a18caffeb0c18213..9e4e69f287d283ef1aa9d6ee515c8e2cf9d8ab81 100755 (executable)
@@ -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();
         }
 
         /// <summary>