-using Tizen.NUI;
+using System.Collections.Generic;
+using System.Text;
+using Tizen.NUI;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Components;
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");
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();
}
}
}