[NUI] Add Button ItemHorizontalAlignment and ItemVerticalAlignment
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 24 Mar 2022 02:15:30 +0000 (11:15 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 29 Mar 2022 03:10:12 +0000 (12:10 +0900)
LinearLayout.LinearAlignment is deprecated, and HorizontalAlignment and
VerticalAlignment are added.

To replace Button.ItemAlignment, whose type is LinearAlignment,
ItemHorizontalAlignment and ItemVerticalAlignment are added.

src/Tizen.NUI.Components/Controls/Button.Internal.cs
src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI.Components/Style/ButtonStyle.cs
src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs

index 9e861ae..70fe232 100644 (file)
@@ -352,7 +352,8 @@ namespace Tizen.NUI.Components
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Horizontal,
-                    LinearAlignment = itemAlignment,
+                    HorizontalAlignment = itemHorizontalAlignment,
+                    VerticalAlignment = itemVerticalAlignment,
                     CellPadding = cellPadding
                 };
 
@@ -364,7 +365,8 @@ namespace Tizen.NUI.Components
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Horizontal,
-                    LinearAlignment = itemAlignment,
+                    HorizontalAlignment = itemHorizontalAlignment,
+                    VerticalAlignment = itemVerticalAlignment,
                     CellPadding = cellPadding
                 };
 
@@ -376,7 +378,8 @@ namespace Tizen.NUI.Components
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Vertical,
-                    LinearAlignment = itemAlignment,
+                    HorizontalAlignment = itemHorizontalAlignment,
+                    VerticalAlignment = itemVerticalAlignment,
                     CellPadding = cellPadding
                 };
 
@@ -388,7 +391,8 @@ namespace Tizen.NUI.Components
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Vertical,
-                    LinearAlignment = itemAlignment,
+                    HorizontalAlignment = itemHorizontalAlignment,
+                    VerticalAlignment = itemVerticalAlignment,
                     CellPadding = cellPadding
                 };
 
index 5f9153e..3496661 100755 (executable)
@@ -146,11 +146,70 @@ namespace Tizen.NUI.Components
             if (instance.itemAlignment != newAlignment)
             {
                 instance.itemAlignment = newAlignment;
+
+                switch (newAlignment)
+                {
+                    case LinearLayout.Alignment.Begin:
+                        instance.itemHorizontalAlignment = HorizontalAlignment.Begin;
+                        break;
+                    case LinearLayout.Alignment.End:
+                        instance.itemHorizontalAlignment = HorizontalAlignment.End;
+                        break;
+                    case LinearLayout.Alignment.CenterHorizontal:
+                        instance.itemHorizontalAlignment = HorizontalAlignment.Center;
+                        break;
+                    case LinearLayout.Alignment.Top:
+                        instance.itemVerticalAlignment = VerticalAlignment.Top;
+                        break;
+                    case LinearLayout.Alignment.Bottom:
+                        instance.itemVerticalAlignment = VerticalAlignment.Bottom;
+                        break;
+                    case LinearLayout.Alignment.CenterVertical:
+                        instance.itemVerticalAlignment = VerticalAlignment.Center;
+                        break;
+                    case LinearLayout.Alignment.Center:
+                        instance.itemHorizontalAlignment = HorizontalAlignment.Center;
+                        instance.itemVerticalAlignment = VerticalAlignment.Center;
+                        break;
+                    default:
+                        break;
+                }
+
                 instance.LayoutItems();
             }
         },
         defaultValueCreator: (bindable) => ((Button)bindable).itemAlignment);
 
+        /// <summary> The bindable property of ItemHorizontalAlignment. </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal static readonly BindableProperty ItemHorizontalAlignmentProperty = BindableProperty.Create(nameof(ItemHorizontalAlignment), typeof(HorizontalAlignment), typeof(Button), HorizontalAlignment.Center, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (Button)bindable;
+            var newHorizontalAlignment = (HorizontalAlignment)newValue;
+
+            if (instance.itemHorizontalAlignment != newHorizontalAlignment)
+            {
+                instance.itemHorizontalAlignment = newHorizontalAlignment;
+                instance.LayoutItems();
+            }
+        },
+        defaultValueCreator: (bindable) => ((Button)bindable).itemHorizontalAlignment);
+
+        /// <summary> The bindable property of ItemVerticalAlignment. </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal static readonly BindableProperty ItemVerticalAlignmentProperty = BindableProperty.Create(nameof(ItemVerticalAlignment), typeof(VerticalAlignment), typeof(Button), VerticalAlignment.Center, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (Button)bindable;
+            var newVerticalAlignment = (VerticalAlignment)newValue;
+
+            if (instance.itemVerticalAlignment != newVerticalAlignment)
+            {
+                instance.itemVerticalAlignment = newVerticalAlignment;
+                instance.LayoutItems();
+            }
+        },
+        defaultValueCreator: (bindable) => ((Button)bindable).itemVerticalAlignment);
+
         /// <summary> The bindable property of ItemSpacing. </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
@@ -166,6 +225,8 @@ namespace Tizen.NUI.Components
         private bool isSelectable = false;
         private Size2D itemSpacing;
         private LinearLayout.Alignment itemAlignment = LinearLayout.Alignment.Center;
+        private HorizontalAlignment itemHorizontalAlignment = HorizontalAlignment.Center;
+        private VerticalAlignment itemVerticalAlignment = VerticalAlignment.Center;
 
         static Button() { }
 
@@ -820,6 +881,26 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// The item (text or icon or both) horizontal alignment.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public HorizontalAlignment ItemHorizontalAlignment
+        {
+            get => (HorizontalAlignment)GetValue(ItemHorizontalAlignmentProperty);
+            set => SetValue(ItemHorizontalAlignmentProperty, value);
+        }
+
+        /// <summary>
+        /// The item (text or icon or both) vertical alignment.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public VerticalAlignment ItemVerticalAlignment
+        {
+            get => (VerticalAlignment)GetValue(ItemVerticalAlignmentProperty);
+            set => SetValue(ItemVerticalAlignmentProperty, value);
+        }
+
+        /// <summary>
         /// The space between icon and text.
         /// The value is applied when there exist icon and text both.
         /// The width value is used when the items are arranged horizontally. Otherwise, the height value is used.
index d514697..a8dca51 100755 (executable)
@@ -91,9 +91,53 @@ namespace Tizen.NUI.Components
         internal static readonly BindableProperty ItemAlignmentProperty = BindableProperty.Create(nameof(ItemAlignment), typeof(LinearLayout.Alignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
         {
             ((ButtonStyle)bindable).itemAlignment = (LinearLayout.Alignment?)newValue;
+
+            switch (newValue)
+            {
+                case LinearLayout.Alignment.Begin:
+                    ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Begin;
+                    break;
+                case LinearLayout.Alignment.End:
+                    ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.End;
+                    break;
+                case LinearLayout.Alignment.CenterHorizontal:
+                    ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
+                    break;
+                case LinearLayout.Alignment.Top:
+                    ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Top;
+                    break;
+                case LinearLayout.Alignment.Bottom:
+                    ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Bottom;
+                    break;
+                case LinearLayout.Alignment.CenterVertical:
+                    ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
+                    break;
+                case LinearLayout.Alignment.Center:
+                    ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
+                    ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
+                    break;
+                default:
+                    break;
+            }
         },
         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemAlignment);
 
+        /// <summary> The bindable property of ItemHorizontalAlignment. </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal static readonly BindableProperty ItemHorizontalAlignmentProperty = BindableProperty.Create(nameof(ItemHorizontalAlignment), typeof(HorizontalAlignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            ((ButtonStyle)bindable).itemHorizontalAlignment = (HorizontalAlignment?)newValue;
+        },
+        defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemHorizontalAlignment);
+
+        /// <summary> The bindable property of ItemVerticalAlignment. </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal static readonly BindableProperty ItemVerticalAlignmentProperty = BindableProperty.Create(nameof(ItemVerticalAlignment), typeof(VerticalAlignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            ((ButtonStyle)bindable).itemVerticalAlignment = (VerticalAlignment?)newValue;
+        },
+        defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemVerticalAlignment);
+
         /// <summary> The bindable property of ItemSpacing. </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
@@ -109,6 +153,8 @@ namespace Tizen.NUI.Components
         private Extents textPadding;
         private Size2D itemSpacing;
         private LinearLayout.Alignment? itemAlignment;
+        private HorizontalAlignment? itemHorizontalAlignment;
+        private VerticalAlignment? itemVerticalAlignment;
 
         static ButtonStyle() { }
 
@@ -223,6 +269,26 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// The item (text or icon or both) horizontal alignment.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public HorizontalAlignment? ItemHorizontalAlignment
+        {
+            get => (HorizontalAlignment?)GetValue(ItemHorizontalAlignmentProperty);
+            set => SetValue(ItemHorizontalAlignmentProperty, value);
+        }
+
+        /// <summary>
+        /// The item (text or icon or both) vertical alignment.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public VerticalAlignment? ItemVerticalAlignment
+        {
+            get => (VerticalAlignment?)GetValue(ItemVerticalAlignmentProperty);
+            set => SetValue(ItemVerticalAlignmentProperty, value);
+        }
+
+        /// <summary>
         /// The space between icon and text.
         /// The value is applied when there exist icon and text both.
         /// The width value is used when the items are arranged horizontally. Otherwise, the height value is used.
index 3d9a7f0..7f20990 100755 (executable)
@@ -41,7 +41,8 @@ namespace Tizen.NUI.Components
             {
                 Size = new Size(339, 96),
                 CornerRadius = 28.0f,
-                ItemAlignment = LinearLayout.Alignment.Center,
+                ItemHorizontalAlignment = HorizontalAlignment.Center,
+                ItemVerticalAlignment = VerticalAlignment.Center,
                 BackgroundColor = new Selector<Color>()
                 {
                     Normal = new Color(0.039f, 0.055f, 0.29f, 1),
@@ -60,7 +61,8 @@ namespace Tizen.NUI.Components
             theme.AddStyleWithoutClone("Tizen.NUI.Components.CheckBox", new ButtonStyle()
             {
                 ItemSpacing = new Size2D(32, 32),
-                ItemAlignment = LinearLayout.Alignment.CenterVertical,
+                ItemHorizontalAlignment = HorizontalAlignment.Begin,
+                ItemVerticalAlignment = VerticalAlignment.Center,
                 Icon = new ImageViewStyle()
                 {
                     Size = new Size(36, 36),
@@ -152,7 +154,8 @@ namespace Tizen.NUI.Components
             theme.AddStyleWithoutClone("Tizen.NUI.Components.RadioButton", new ButtonStyle()
             {
                 ItemSpacing = new Size2D(32, 32),
-                ItemAlignment = LinearLayout.Alignment.CenterVertical,
+                ItemHorizontalAlignment = HorizontalAlignment.Begin,
+                ItemVerticalAlignment = VerticalAlignment.Center,
                 Icon = new ImageViewStyle()
                 {
                     Size = new Size(36, 36),
@@ -222,7 +225,8 @@ namespace Tizen.NUI.Components
             theme.AddStyleWithoutClone("Tizen.NUI.Components.Switch", new SwitchStyle()
             {
                 ItemSpacing = new Size2D(32, 32),
-                ItemAlignment = LinearLayout.Alignment.CenterVertical,
+                ItemHorizontalAlignment = HorizontalAlignment.Begin,
+                ItemVerticalAlignment = VerticalAlignment.Center,
                 Track = new ImageViewStyle()
                 {
                     Size = new Size(80, 40),