Fixed arrow icon state changing.
authorAndrzej Krawczyk <a.krawczyk@samsung.com>
Fri, 13 Aug 2021 09:22:38 +0000 (11:22 +0200)
committerPiotr Czaja <p.czaja@samsung.com>
Tue, 14 Sep 2021 11:01:34 +0000 (13:01 +0200)
Fitness/Views/Styles/DirectionButtonStyle.cs
Fitness/res/styles/button/12_icon_back_arrow_active.png [deleted file]
Fitness/res/styles/button/12_icon_back_arrow_active_reverse.png [deleted file]
Fitness/res/styles/button/icon_arrow_next_active.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_next_disabled.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_next_focused.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_next_pressed.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_prev_active.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_prev_disabled.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_prev_focused.png [new file with mode: 0644]
Fitness/res/styles/button/icon_arrow_prev_pressed.png [new file with mode: 0644]

index 10b3bd9..e6f0f2c 100644 (file)
@@ -1,4 +1,6 @@
-using Tizen.NUI;
+using System.Collections.Generic;
+using System.Text;
+using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
 
@@ -12,6 +14,25 @@ namespace Fitness.Views.Styles
 
     public class DirectionButtonStyle : LightButtonStyle
     {
+        private const string ArrowIconPathStart = "styles/button/icon_arrow_";
+        private const string ArrowIconPathEnd = ".png";
+        private const char ArrowIconNameConnector = '_';
+        private static readonly string Resources = NUIApplication.Current.DirectoryInfo.Resource;
+
+        private static readonly Dictionary<Direction, string> ArrowIconDirectionNames = new Dictionary<Direction, string>
+        {
+            { Direction.Previous, "prev" },
+            { Direction.Next, "next" },
+        };
+
+        private static readonly Dictionary<State, string> ArrowIconStateNames = new Dictionary<State, string>
+        {
+            { State.Normal, "active" },
+            { State.Focused, "focused" },
+            { State.Pressed, "pressed" },
+            { State.Disabled, "disabled" },
+        };
+
         public DirectionButtonStyle(Direction direction)
         {
             Text.TextColor.Disabled = new Color("#C3CAD2");
@@ -20,29 +41,62 @@ namespace Fitness.Views.Styles
             NinePatchBackgroundColor.Disabled = NinePatchBackgroundColor.Normal;
             NinePatchFrameColor.Disabled = NinePatchFrameColor.Normal;
 
-            if (direction == Direction.Previous)
+            switch (direction)
             {
-                Text.HorizontalAlignment = HorizontalAlignment.Begin;
-                TextPadding = new Extents(20, 0, 0, 0);
-                IconRelativeOrientation = Button.IconOrientation.Left;
-
-                Icon = new ImageViewStyle
-                {
-                    ResourceUrl = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/12_icon_back_arrow_active.png",
-                };
+                case Direction.Previous:
+                    Text.HorizontalAlignment = HorizontalAlignment.Begin;
+                    TextPadding = new Extents(20, 0, 0, 0);
+                    IconRelativeOrientation = Button.IconOrientation.Left;
+                    break;
+
+                case Direction.Next:
+                    Text.HorizontalAlignment = HorizontalAlignment.End;
+                    IconPadding = new Extents(20, 0, 0, 0);
+
+                    // TODO: Temporarily commented due to NUI error.
+                    // IconRelativeOrientation = Button.IconOrientation.Right;
+                    break;
+
+                default:
+                    throw new System.Exception($"Unsupported direction: {direction}");
             }
-            else
+
+            Icon = new ImageViewStyle
             {
-                Text.HorizontalAlignment = HorizontalAlignment.End;
-                IconPadding = new Extents(20, 0, 0, 0);
-
-                // TODO: Temporarily commented due to NUI error.
-                // IconRelativeOrientation = Button.IconOrientation.Right;
-                Icon = new ImageViewStyle
-                {
-                    ResourceUrl = NUIApplication.Current.DirectoryInfo.Resource + "styles/button/12_icon_back_arrow_active_reverse.png",
-                };
-            }
+                ResourceUrl = GetArrowIconPaths(direction),
+            };
+        }
+
+        private enum State
+        {
+            Normal,
+            Focused,
+            Pressed,
+            Disabled,
+        }
+
+        private static Selector<string> GetArrowIconPaths(Direction direction)
+        {
+            return new Selector<string>
+            {
+                Normal = GetArrowIconPath(direction, State.Normal),
+                Focused = GetArrowIconPath(direction, State.Focused),
+                Pressed = GetArrowIconPath(direction, State.Pressed),
+                Disabled = GetArrowIconPath(direction, State.Disabled),
+            };
+        }
+
+        private static string GetArrowIconPath(Direction direction, State state)
+        {
+            StringBuilder path = new StringBuilder(Resources);
+
+            path.Append(ArrowIconPathStart);
+            path.Append(ArrowIconDirectionNames[direction]);
+            path.Append(ArrowIconNameConnector);
+            path.Append(ArrowIconStateNames[state]);
+            path.Append(ArrowIconPathEnd);
+
+            return path.ToString();
         }
     }
 }
diff --git a/Fitness/res/styles/button/12_icon_back_arrow_active.png b/Fitness/res/styles/button/12_icon_back_arrow_active.png
deleted file mode 100644 (file)
index 7441530..0000000
Binary files a/Fitness/res/styles/button/12_icon_back_arrow_active.png and /dev/null differ
diff --git a/Fitness/res/styles/button/12_icon_back_arrow_active_reverse.png b/Fitness/res/styles/button/12_icon_back_arrow_active_reverse.png
deleted file mode 100644 (file)
index 6ef9b9d..0000000
Binary files a/Fitness/res/styles/button/12_icon_back_arrow_active_reverse.png and /dev/null differ
diff --git a/Fitness/res/styles/button/icon_arrow_next_active.png b/Fitness/res/styles/button/icon_arrow_next_active.png
new file mode 100644 (file)
index 0000000..7db49db
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_next_active.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_next_disabled.png b/Fitness/res/styles/button/icon_arrow_next_disabled.png
new file mode 100644 (file)
index 0000000..3bad544
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_next_disabled.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_next_focused.png b/Fitness/res/styles/button/icon_arrow_next_focused.png
new file mode 100644 (file)
index 0000000..44523c2
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_next_focused.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_next_pressed.png b/Fitness/res/styles/button/icon_arrow_next_pressed.png
new file mode 100644 (file)
index 0000000..647c9b1
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_next_pressed.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_prev_active.png b/Fitness/res/styles/button/icon_arrow_prev_active.png
new file mode 100644 (file)
index 0000000..49c98a5
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_prev_active.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_prev_disabled.png b/Fitness/res/styles/button/icon_arrow_prev_disabled.png
new file mode 100644 (file)
index 0000000..8958d3f
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_prev_disabled.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_prev_focused.png b/Fitness/res/styles/button/icon_arrow_prev_focused.png
new file mode 100644 (file)
index 0000000..886cbc0
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_prev_focused.png differ
diff --git a/Fitness/res/styles/button/icon_arrow_prev_pressed.png b/Fitness/res/styles/button/icon_arrow_prev_pressed.png
new file mode 100644 (file)
index 0000000..9ca9174
Binary files /dev/null and b/Fitness/res/styles/button/icon_arrow_prev_pressed.png differ