/*
* Copyright(c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.ComponentModel;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
using Tizen.NUI.Components.Extension;
namespace Tizen.NUI.Components
{
///
/// ButtonStyle is a class which saves Button's ux data.
///
/// 8
public class ButtonStyle : ControlStyle
{
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var buttonStyle = (ButtonStyle)bindable;
buttonStyle.isSelectable = (bool?)newValue;
},
defaultValueCreator: (bindable) =>
{
var buttonStyle = (ButtonStyle)bindable;
return buttonStyle.isSelectable;
});
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var buttonStyle = (ButtonStyle)bindable;
buttonStyle.isSelected = (bool?)newValue;
},
defaultValueCreator: (bindable) =>
{
var buttonStyle = (ButtonStyle)bindable;
return buttonStyle.isSelected;
});
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(Button.IconOrientation?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var buttonStyle = (ButtonStyle)bindable;
buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
},
defaultValueCreator: (bindable) =>
{
var buttonStyle = (ButtonStyle)bindable;
return buttonStyle.iconRelativeOrientation;
});
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
((ButtonStyle)bindable).iconPadding = null == newValue ? null : new Extents((Extents)newValue);
},
defaultValueCreator: (bindable) =>
{
var buttonStyle = (ButtonStyle)bindable;
return buttonStyle.iconPadding;
});
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
((ButtonStyle)bindable).textPadding = null == newValue ? null : new Extents((Extents)newValue);
},
defaultValueCreator: (bindable) =>
{
var buttonStyle = (ButtonStyle)bindable;
return buttonStyle.textPadding;
});
/// The bindable property of ItemAlignment.
[EditorBrowsable(EditorBrowsableState.Never)]
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);
/// The bindable property of ItemHorizontalAlignment.
[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);
/// The bindable property of ItemVerticalAlignment.
[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);
/// The bindable property of ItemSpacing.
[EditorBrowsable(EditorBrowsableState.Never)]
internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
{
((ButtonStyle)bindable).itemSpacing = (Size2D)newValue;
},
defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemSpacing);
private bool? isSelectable;
private bool? isSelected;
private Button.IconOrientation? iconRelativeOrientation;
private Extents iconPadding;
private Extents textPadding;
private Size2D itemSpacing;
private LinearLayout.Alignment? itemAlignment;
private HorizontalAlignment? itemHorizontalAlignment;
private VerticalAlignment? itemVerticalAlignment;
static ButtonStyle() { }
///
/// Creates a new instance of a ButtonStyle.
///
/// 8
public ButtonStyle() : base()
{
}
///
/// Creates a new instance of a ButtonStyle with style.
///
/// Create ButtonStyle by style customized by user.
/// 8
public ButtonStyle(ButtonStyle style) : base(style)
{
}
///
/// Overlay image's Style.
///
/// 8
public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
///
/// Text's Style.
///
/// 8
public TextLabelStyle Text { get; set; } = new TextLabelStyle();
///
/// Icon's Style.
///
/// 8
public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
///
/// Flag to decide Button can be selected or not.
///
/// 8
public bool? IsSelectable
{
get => (bool?)GetValue(IsSelectableProperty);
set => SetValue(IsSelectableProperty, value);
}
///
/// Flag to decide selected state in Button.
///
/// 8
public bool? IsSelected
{
get => (bool?)GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, value);
}
///
/// Flag to decide button can be selected or not.
///
/// 8
public new bool? IsEnabled
{
get => (bool?)base.IsEnabled;
set
{
base.IsEnabled = value;
}
}
///
/// Icon relative orientation.
///
/// 8
public Button.IconOrientation? IconRelativeOrientation
{
get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
set => SetValue(IconRelativeOrientationProperty, value);
}
///
/// Icon padding in Button. It is shortcut of Icon.Padding.
///
/// 8
public Extents IconPadding
{
// TODO Fixme
// When there are icon and text, the linear layout does not count padding.
get => ((Extents)GetValue(IconPaddingProperty)) ?? (iconPadding = new Extents());
set => SetValue(IconPaddingProperty, value);
}
///
/// Text padding in Button. It is shortcut of Text.Padding.
///
/// 8
public Extents TextPadding
{
get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
set => SetValue(TextPaddingProperty, value);
}
///
/// The item (text or icon or both) alignment.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public LinearLayout.Alignment? ItemAlignment
{
get => (LinearLayout.Alignment?)GetValue(ItemAlignmentProperty);
set => SetValue(ItemAlignmentProperty, value);
}
///
/// The item (text or icon or both) horizontal alignment.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public HorizontalAlignment? ItemHorizontalAlignment
{
get => (HorizontalAlignment?)GetValue(ItemHorizontalAlignmentProperty);
set => SetValue(ItemHorizontalAlignmentProperty, value);
}
///
/// The item (text or icon or both) vertical alignment.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public VerticalAlignment? ItemVerticalAlignment
{
get => (VerticalAlignment?)GetValue(ItemVerticalAlignmentProperty);
set => SetValue(ItemVerticalAlignmentProperty, value);
}
///
/// 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.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public Size2D ItemSpacing
{
get => (Size2D)GetValue(ItemSpacingProperty);
set => SetValue(ItemSpacingProperty, value);
}
///
/// 8
public override void CopyFrom(BindableObject bindableObject)
{
base.CopyFrom(bindableObject);
if (bindableObject is ButtonStyle buttonStyle)
{
Overlay.CopyFrom(buttonStyle.Overlay);
Text.CopyFrom(buttonStyle.Text);
Icon.CopyFrom(buttonStyle.Icon);
}
}
///
/// Create corresponding ButtonExtension.
/// This is to be called by a Button.
/// You may override this function to customize button's behavior.
///
/// The new ButtonExtension instance.
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ButtonExtension CreateExtension()
{
return null;
}
///
/// Dispose ButtonStyle and all children on it.
///
/// true in order to free managed objects
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void Dispose(bool disposing)
{
if (disposing)
{
iconPadding?.Dispose();
textPadding?.Dispose();
}
base.Dispose(disposing);
}
}
}