/*
- * Copyright(c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2020 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.
using System;
using System.ComponentModel;
using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Components.Extension;
+using Tizen.NUI.Accessibility;
namespace Tizen.NUI.Components
{
/// <summary>
+ /// ClickedEventArgs is a class to record button click event arguments which will sent to user.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class ClickedEventArgs : EventArgs
+ {
+ }
+
+ /// <summary>
+ /// SelectedChangedEventArgs is a class to record item selected arguments which will sent to user.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class SelectedChangedEventArgs : EventArgs
+ {
+ /// <summary> Selected state </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public bool IsSelected { get; set; }
+ }
+
+ /// <summary>
/// Button is one kind of common component, a button clearly describes what action will occur when the user selects it.
/// Button may contain text or an icon.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public class Button : Control
+ public partial class Button : Control
{
- private ImageView backgroundImage;
- private ImageView shadowImage;
- private ImageView overlayImage;
+ /// 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(IconOrientation?), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ var newIconOrientation = (IconOrientation?)newValue;
+ if (instance.iconRelativeOrientation != newIconOrientation)
+ {
+ instance.iconRelativeOrientation = newIconOrientation;
+ instance.UpdateUIContent();
+ }
+ },
+ defaultValueCreator: (bindable) => ((Button)bindable).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 IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ if (newValue != null)
+ {
+ bool newEnabled = (bool)newValue;
+ if (instance.isEnabled != newEnabled)
+ {
+ instance.isEnabled = newEnabled;
+
+ if (instance.buttonStyle != null)
+ {
+ instance.buttonStyle.IsEnabled = newEnabled;
+ }
+
+ instance.UpdateState();
+ }
+ }
+ },
+ defaultValueCreator: (bindable) => ((Button)bindable).isEnabled);
+ /// 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(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ if (newValue != null)
+ {
+ bool newSelected = (bool)newValue;
+ if (instance.isSelected != newSelected)
+ {
+ instance.isSelected = newSelected;
+
+ if (instance.buttonStyle != null)
+ {
+ instance.buttonStyle.IsSelected = newSelected;
+ }
- private TextLabel buttonText;
- private ImageView buttonIcon;
+ if (instance.isSelectable)
+ {
+ instance.UpdateState();
+ }
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (Button)bindable;
+ return instance.isSelectable && instance.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 IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ if (newValue != null)
+ {
+ bool newSelectable = (bool)newValue;
+ if (instance.isSelectable != newSelectable)
+ {
+ instance.isSelectable = newSelectable;
+
+ if (instance.buttonStyle != null)
+ {
+ instance.buttonStyle.IsSelectable = newSelectable;
+ }
+
+ instance.UpdateState();
+ }
+ }
+ },
+ defaultValueCreator: (bindable) => ((Button)bindable).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 IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ instance.iconPadding = (Extents)((Extents)newValue).Clone();
+ instance.UpdateUIContent();
+ },
+ defaultValueCreator: (bindable) => ((Button)bindable).iconPadding);
- private ButtonAttributes buttonAttributes;
- private EventHandler<StateChangeEventArgs> stateChangeHander;
+ /// 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(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Button)bindable;
+ instance.textPadding = (Extents)((Extents)newValue).Clone();
+ instance.UpdateUIContent();
+ },
+ defaultValueCreator: (bindable) => ((Button)bindable).textPadding);
+ private IconOrientation? iconRelativeOrientation;
private bool isSelected = false;
+ private bool isSelectable = false;
private bool isEnabled = true;
- private bool isPressed = false;
+ private Extents iconPadding;
+ private Extents textPadding;
+
+ static Button() { }
+
/// <summary>
/// Creates a new instance of a Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public Button() : base()
{
Initialize();
}
+
/// <summary>
/// Creates a new instance of a Button with style.
/// </summary>
/// <param name="style">Create Button by special style defined in UX.</param>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <since_tizen> 8 </since_tizen>
public Button(string style) : base(style)
{
Initialize();
}
+
/// <summary>
- /// Creates a new instance of a Button with attributes.
+ /// Creates a new instance of a Button with style.
/// </summary>
- /// <param name="attributes">Create Button by attributes customized by user.</param>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Button(ButtonAttributes attributes) : base(attributes)
+ /// <param name="buttonStyle">Create Button by style customized by user.</param>
+ /// <since_tizen> 8 </since_tizen>
+ public Button(ButtonStyle buttonStyle) : base(buttonStyle)
{
Initialize();
}
+
/// <summary>
/// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use Clicked event instead.")]
public event EventHandler<ClickEventArgs> ClickEvent;
+
+ /// <summary>
+ /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public event EventHandler<ClickedEventArgs> Clicked;
+
/// <summary>
/// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler<StateChangeEventArgs> StateChangedEvent
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
+ public event EventHandler<StateChangedEventArgs> StateChangedEvent
{
add
{
- stateChangeHander += value;
+ stateChangeHandler += value;
}
remove
{
- stateChangeHander -= value;
+ stateChangeHandler -= value;
}
}
+
/// <summary>
/// Icon orientation.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public enum IconOrientation
{
/// <summary>
/// Top.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
Top,
/// <summary>
/// Bottom.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
Bottom,
/// <summary>
/// Left.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
Left,
/// <summary>
/// Right.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
Right,
}
+
/// <summary>
- /// Flag to decide Button can be selected or not.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsSelectable
- {
- get
- {
- return buttonAttributes?.IsSelectable ?? false;
- }
- set
- {
- buttonAttributes.IsSelectable = value;
- }
- }
- /// <summary>
- /// Background image's resource url in Button.
+ /// Button's icon part.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string BackgroundImageURL
+ /// <since_tizen> 8 </since_tizen>
+ public ImageView Icon
{
get
{
- return buttonAttributes?.BackgroundImageAttributes?.ResourceURL?.All;
- }
- set
- {
- if (value != null)
+ if (null == buttonIcon)
{
- CreateBackgroundAttributes();
- if (buttonAttributes.BackgroundImageAttributes.ResourceURL == null)
+ buttonIcon = CreateIcon();
+ if (null != Extension)
{
- buttonAttributes.BackgroundImageAttributes.ResourceURL = new StringSelector();
+ buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
}
- buttonAttributes.BackgroundImageAttributes.ResourceURL.All = value;
- RelayoutRequest();
- }
- }
- }
- /// <summary>
- /// Background image's border in Button.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Rectangle BackgroundImageBorder
- {
- get
- {
- return buttonAttributes?.BackgroundImageAttributes?.Border?.All;
- }
- set
- {
- if (value != null)
- {
- CreateBackgroundAttributes();
- if (buttonAttributes.BackgroundImageAttributes.Border == null)
+ if (null != buttonIcon)
{
- buttonAttributes.BackgroundImageAttributes.Border = new RectangleSelector();
+ Add(buttonIcon);
+ buttonIcon.Relayout += OnIconRelayout;
}
- buttonAttributes.BackgroundImageAttributes.Border.All = value;
- RelayoutRequest();
}
+ return buttonIcon;
+ }
+ internal set
+ {
+ buttonIcon = value;
}
}
+
/// <summary>
- /// Shadow image's resource url in Button.
+ /// Button's overlay image part.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string ShadowImageURL
+ /// <since_tizen> 8 </since_tizen>
+ public ImageView OverlayImage
{
get
{
- return buttonAttributes?.ShadowImageAttributes?.ResourceURL?.All;
- }
- set
- {
- if (value != null)
+ if (null == overlayImage)
{
- CreateShadowAttributes();
- if (buttonAttributes.ShadowImageAttributes.ResourceURL == null)
+ overlayImage = CreateOverlayImage();
+ if (null != Extension)
+ {
+ overlayImage = Extension.OnCreateOverlayImage(this, overlayImage);
+ }
+ if (null != overlayImage)
{
- buttonAttributes.ShadowImageAttributes.ResourceURL = new StringSelector();
+ Add(overlayImage);
}
- buttonAttributes.ShadowImageAttributes.ResourceURL.All = value;
- RelayoutRequest();
}
+ return overlayImage;
+ }
+ internal set
+ {
+ overlayImage = value;
}
}
+
/// <summary>
- /// Shadow image's border in Button.
+ /// Button's text part.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Rectangle ShadowImageBorder
+ /// <since_tizen> 8 </since_tizen>
+ public TextLabel TextLabel
{
get
{
- return buttonAttributes?.ShadowImageAttributes?.Border?.All;
- }
- set
- {
- if (value != null)
+ if (null == buttonText)
{
- CreateShadowAttributes();
- if (buttonAttributes.ShadowImageAttributes.Border == null)
+ buttonText = CreateText();
+ if (null != Extension)
+ {
+ buttonText = Extension.OnCreateText(this, buttonText);
+ }
+ if (null != buttonText)
{
- buttonAttributes.ShadowImageAttributes.Border = new RectangleSelector();
+ Add(buttonText);
}
- buttonAttributes.ShadowImageAttributes.Border.All = value;
- RelayoutRequest();
}
+ return buttonText;
+ }
+ internal set
+ {
+ buttonText = value;
+ AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Label, buttonText.Text);
}
}
+
/// <summary>
- /// Overlay image's resource url in Button.
+ /// Return a copied Style instance of Button
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string OverlayImageURL
+ /// <remarks>
+ /// It returns copied Style instance and changing it does not effect to the Button.
+ /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
+ /// </remarks>
+ /// <since_tizen> 8 </since_tizen>
+ public new ButtonStyle Style
{
get
{
- return buttonAttributes?.OverlayImageAttributes?.ResourceURL?.All;
- }
- set
- {
- if (value != null)
- {
- CreateOverlayAttributes();
- if (buttonAttributes.OverlayImageAttributes.ResourceURL == null)
- {
- buttonAttributes.OverlayImageAttributes.ResourceURL = new StringSelector();
- }
- buttonAttributes.OverlayImageAttributes.ResourceURL.All = value;
- RelayoutRequest();
- }
+ var result = (ButtonStyle)ViewStyle.Clone();
+ result.CopyPropertiesFromView(this);
+ result.Text.CopyPropertiesFromView(TextLabel);
+ result.Icon.CopyPropertiesFromView(Icon);
+ result.Overlay.CopyPropertiesFromView(OverlayImage);
+ return result;
}
}
+
/// <summary>
- /// Overlay image's border in Button.
+ /// The text of Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Rectangle OverlayImageBorder
+ public string Text
{
get
{
- return buttonAttributes?.OverlayImageAttributes?.Border?.All;
+ return TextLabel.Text;
}
set
{
- if (value != null)
- {
- CreateOverlayAttributes();
- if (buttonAttributes.OverlayImageAttributes.Border == null)
- {
- buttonAttributes.OverlayImageAttributes.Border = new RectangleSelector();
- }
- buttonAttributes.OverlayImageAttributes.Border.All = value;
- RelayoutRequest();
- }
+ TextLabel.Text = value;
}
}
+
/// <summary>
- /// Text string in Button.
+ /// Flag to decide Button can be selected or not.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string Text
+ public bool IsSelectable
{
get
{
- return buttonAttributes?.TextAttributes?.Text?.All;
+ return (bool)GetValue(IsSelectableProperty);
}
set
{
- if (value != null)
- {
- CreateTextAttributes();
- if(buttonAttributes.TextAttributes.Text == null)
- {
- buttonAttributes.TextAttributes.Text = new StringSelector();
- }
- buttonAttributes.TextAttributes.Text.All = value;
-
- RelayoutRequest();
- }
+ SetValue(IsSelectableProperty, value);
}
}
+
/// <summary>
/// Translate text string in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public string TranslatableText
{
get
{
- return buttonAttributes?.TextAttributes?.TranslatableText?.All;
+ return TextLabel.TranslatableText;
}
set
{
- if (value != null)
- {
- CreateTextAttributes();
- if (buttonAttributes.TextAttributes.TranslatableText == null)
- {
- buttonAttributes.TextAttributes.TranslatableText = new StringSelector();
- }
- buttonAttributes.TextAttributes.TranslatableText.All = value;
-
- RelayoutRequest();
- }
+ TextLabel.TranslatableText = value;
}
}
+
/// <summary>
/// Text point size in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public float PointSize
{
get
{
- return buttonAttributes?.TextAttributes?.PointSize?.All ?? 0;
+ return TextLabel.PointSize;
}
set
{
- CreateTextAttributes();
- if (buttonAttributes.TextAttributes.PointSize == null)
- {
- buttonAttributes.TextAttributes.PointSize = new FloatSelector();
- }
- buttonAttributes.TextAttributes.PointSize.All = value;
- RelayoutRequest();
+ TextLabel.PointSize = value;
}
}
+
/// <summary>
/// Text font family in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public string FontFamily
{
get
{
- return buttonAttributes?.TextAttributes?.FontFamily;
+ return TextLabel.FontFamily;
}
set
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.FontFamily = value;
- RelayoutRequest();
+ TextLabel.FontFamily = value;
}
}
+
/// <summary>
/// Text color in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public Color TextColor
{
get
{
- return buttonAttributes?.TextAttributes?.TextColor?.All;
+ return TextLabel.TextColor;
}
set
{
- CreateTextAttributes();
- if (buttonAttributes.TextAttributes.TextColor == null)
- {
- buttonAttributes.TextAttributes.TextColor = new ColorSelector();
- }
- buttonAttributes.TextAttributes.TextColor.All = value;
- RelayoutRequest();
+ TextLabel.TextColor = value;
}
}
+
/// <summary>
/// Text horizontal alignment in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public HorizontalAlignment TextAlignment
{
get
{
- return buttonAttributes?.TextAttributes?.HorizontalAlignment ?? HorizontalAlignment.Center;
+ return TextLabel.HorizontalAlignment;
}
set
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.HorizontalAlignment = value;
- RelayoutRequest();
+ TextLabel.HorizontalAlignment = value;
}
}
+
/// <summary>
/// Icon image's resource url in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public string IconURL
{
get
{
- return buttonAttributes?.IconAttributes?.ResourceURL?.All;
+ return Icon.ResourceUrl;
}
set
{
- if (value != null)
- {
- CreateIconAttributes();
- if (buttonAttributes.IconAttributes.ResourceURL == null)
- {
- buttonAttributes.IconAttributes.ResourceURL = new StringSelector();
- }
- buttonAttributes.IconAttributes.ResourceURL.All = value;
- RelayoutRequest();
- }
+ Icon.ResourceUrl = value;
}
}
+
/// <summary>
/// Text string selector in Button.
+ /// Getter returns copied selector value if exist, null otherwise.
+ /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public StringSelector TextSelector
{
- get
- {
- return buttonAttributes?.TextAttributes?.Text;
- }
+ get => buttonText == null ? null : new StringSelector((Selector<string>)buttonText.GetValue(TextLabel.TextSelectorProperty));
set
{
- if (value != null)
+ if (value == null || buttonText == null)
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.Text = value.Clone() as StringSelector;
- RelayoutRequest();
+ throw new NullReferenceException("Button.TextSelector is null");
+ }
+ else
+ {
+ buttonText.SetValue(TextLabel.TextSelectorProperty, value);
}
}
}
+
/// <summary>
/// Translateable text string selector in Button.
+ /// Getter returns copied selector value if exist, null otherwise.
/// </summary>
+ /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public StringSelector TranslatableTextSelector
{
- get
- {
- return buttonAttributes?.TextAttributes?.TranslatableText;
- }
+ get => buttonText == null ? null : new StringSelector((Selector<string>)buttonText.GetValue(TextLabel.TranslatableTextSelectorProperty));
set
{
- if (value != null)
+ if (value == null || buttonText == null)
+ {
+ throw new NullReferenceException("Button.TranslatableTextSelector is null");
+ }
+ else
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.TranslatableText = value.Clone() as StringSelector;
- RelayoutRequest();
+ buttonText.SetValue(TextLabel.TranslatableTextSelectorProperty, value);
}
}
}
+
/// <summary>
/// Text color selector in Button.
+ /// Getter returns copied selector value if exist, null otherwise.
/// </summary>
+ /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public ColorSelector TextColorSelector
{
- get
- {
- return buttonAttributes?.TextAttributes?.TextColor;
- }
+ get => buttonText == null ? null : new ColorSelector((Selector<Color>)buttonText.GetValue(TextLabel.TextColorSelectorProperty));
set
{
- if(value != null)
+ if (value == null || buttonText == null)
+ {
+ throw new NullReferenceException("Button.TextColorSelectorProperty is null");
+ }
+ else
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.TextColor = value.Clone() as ColorSelector;
- RelayoutRequest();
+ buttonText.SetValue(TextLabel.TextColorSelectorProperty, value);
}
}
}
+
/// <summary>
/// Text font size selector in Button.
+ /// Getter returns copied selector value if exist, null otherwise.
/// </summary>
+ /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public FloatSelector PointSizeSelector
{
- get
- {
- return buttonAttributes?.TextAttributes?.PointSize;
- }
+ get => buttonText == null ? null : new FloatSelector((Selector<float?>)buttonText.GetValue(TextLabel.PointSizeSelectorProperty));
set
{
- if (value != null)
+ if (value == null || buttonText == null)
+ {
+ throw new NullReferenceException("Button.PointSizeSelector is null");
+ }
+ else
{
- CreateTextAttributes();
- buttonAttributes.TextAttributes.PointSize = value.Clone() as FloatSelector;
- RelayoutRequest();
+ buttonText.SetValue(TextLabel.PointSizeSelectorProperty, value);
}
}
}
+
/// <summary>
/// Icon image's resource url selector in Button.
+ /// Getter returns copied selector value if exist, null otherwise.
/// </summary>
+ /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public StringSelector IconURLSelector
{
- get
- {
- return buttonAttributes?.IconAttributes?.ResourceURL;
- }
+ get => buttonIcon == null ? null : new StringSelector((Selector<string>)buttonIcon.GetValue(ImageView.ResourceUrlSelectorProperty));
set
{
- if (value != null)
+ if (value == null || buttonIcon == null)
{
- CreateIconAttributes();
- buttonAttributes.IconAttributes.ResourceURL = value.Clone() as StringSelector;
- RelayoutRequest();
+ throw new NullReferenceException("Button.IconURLSelector is null");
+ }
+ else
+ {
+ buttonIcon.SetValue(ImageView.ResourceUrlSelectorProperty, value);
}
}
}
+
/// <summary>
- /// Background image's resource url selector in Button.
+ /// Flag to decide selected state in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public StringSelector BackgroundImageURLSelector
+ public bool IsSelected
{
get
{
- return buttonAttributes?.BackgroundImageAttributes?.ResourceURL;
+ return (bool)GetValue(IsSelectedProperty);
}
set
{
- if (value != null)
- {
- CreateBackgroundAttributes();
- buttonAttributes.BackgroundImageAttributes.ResourceURL = value.Clone() as StringSelector;
- RelayoutRequest();
- }
+ SetValue(IsSelectedProperty, value);
}
}
+
/// <summary>
- /// Background image's border selector in Button.
+ /// Flag to decide enable or disable in Button.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public RectangleSelector BackgroundImageBorderSelector
+ public bool IsEnabled
{
get
{
- return buttonAttributes?.BackgroundImageAttributes?.Border;
+ return (bool)GetValue(IsEnabledProperty);
}
set
{
- if (value != null)
- {
- CreateBackgroundAttributes();
- buttonAttributes.BackgroundImageAttributes.Border = value.Clone() as RectangleSelector;
- RelayoutRequest();
- }
+ SetValue(IsEnabledProperty, value);
}
}
+
/// <summary>
- /// Shadow image's resource url selector in Button.
+ /// Icon relative orientation in Button, work only when show icon and text.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public StringSelector ShadowImageURLSelector
+ /// <since_tizen> 8 </since_tizen>
+ public IconOrientation? IconRelativeOrientation
{
get
{
- return buttonAttributes?.ShadowImageAttributes?.ResourceURL;
+ return (IconOrientation?)GetValue(IconRelativeOrientationProperty) ?? IconOrientation.Left;
}
set
{
- if (value != null)
- {
- CreateShadowAttributes();
- buttonAttributes.ShadowImageAttributes.ResourceURL = value.Clone() as StringSelector;
- RelayoutRequest();
- }
+ SetValue(IconRelativeOrientationProperty, value);
}
}
+
/// <summary>
- /// Shadow image's border selector in Button.
+ /// Icon padding in Button, work only when show icon and text.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public RectangleSelector ShadowImageBorderSelector
+ public Extents IconPadding
{
- get
- {
- return buttonAttributes?.ShadowImageAttributes?.Border;
- }
- set
- {
- if (value != null)
- {
- CreateShadowAttributes();
- buttonAttributes.ShadowImageAttributes.Border = value.Clone() as RectangleSelector;
- RelayoutRequest();
- }
- }
+ get => (Extents)GetValue(IconPaddingProperty) ?? new Extents();
+ set => SetValue(IconPaddingProperty, value);
}
+
/// <summary>
- /// Overlay image's resource url selector in Button.
+ /// Text padding in Button, work only when show icon and text.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public StringSelector OverlayImageURLSelector
+ public Extents TextPadding
{
- get
- {
- return buttonAttributes?.OverlayImageAttributes?.ResourceURL;
- }
- set
- {
- if (value != null)
- {
- CreateOverlayAttributes();
- buttonAttributes.OverlayImageAttributes.ResourceURL = value.Clone() as StringSelector;
- RelayoutRequest();
- }
- }
+ get => (Extents)GetValue(TextPaddingProperty) ?? new Extents();
+ set => SetValue(TextPaddingProperty, value);
}
+
+ private ButtonStyle buttonStyle => ViewStyle as ButtonStyle;
+
/// <summary>
- /// Overlay image's border selector in Button.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public RectangleSelector OverlayImageBorderSelector
- {
- get
- {
- return buttonAttributes?.OverlayImageAttributes?.Border;
- }
- set
- {
- if (value != null)
- {
- CreateOverlayAttributes();
- buttonAttributes.OverlayImageAttributes.Border = value.Clone() as RectangleSelector;
- RelayoutRequest();
- }
- }
- }
- /// <summary>
- /// Flag to decide selected state in Button.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsSelected
- {
- get
- {
- return isSelected;
- }
- set
- {
- isSelected = value;
- UpdateState();
- }
- }
- /// <summary>
- /// Flag to decide enable or disable in Button.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEnabled
- {
- get
- {
- return isEnabled;
- }
- set
- {
- isEnabled = value;
- UpdateState();
- }
- }
-
- /// <summary>
- /// Icon relative orientation in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IconOrientation? IconRelativeOrientation
- {
- get
- {
- return buttonAttributes?.IconRelativeOrientation;
- }
- set
- {
- if(buttonAttributes != null && buttonAttributes.IconRelativeOrientation != value)
- {
- buttonAttributes.IconRelativeOrientation = value;
- RelayoutRequest();
- }
- }
- }
-
- /// <summary>
- /// Icon left padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int IconPaddingLeft
- {
- get
- {
- return buttonAttributes?.IconAttributes?.PaddingLeft ?? 0;
- }
- set
- {
- CreateIconAttributes();
- buttonAttributes.IconAttributes.PaddingLeft = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Icon right padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int IconPaddingRight
- {
- get
- {
- return buttonAttributes?.IconAttributes?.PaddingRight ?? 0;
- }
- set
- {
- CreateIconAttributes();
- buttonAttributes.IconAttributes.PaddingRight = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Icon top padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int IconPaddingTop
- {
- get
- {
- return buttonAttributes?.IconAttributes?.PaddingTop ?? 0;
- }
- set
- {
- CreateIconAttributes();
- buttonAttributes.IconAttributes.PaddingTop = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Icon bottom padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int IconPaddingBottom
- {
- get
- {
- return buttonAttributes?.IconAttributes?.PaddingBottom ?? 0;
- }
- set
- {
- CreateIconAttributes();
- buttonAttributes.IconAttributes.PaddingBottom = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Text left padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int TextPaddingLeft
- {
- get
- {
- return buttonAttributes?.TextAttributes?.PaddingLeft ?? 0;
- }
- set
- {
- CreateTextAttributes();
- buttonAttributes.TextAttributes.PaddingLeft = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Text right padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int TextPaddingRight
- {
- get
- {
- return buttonAttributes?.TextAttributes?.PaddingRight ?? 0;
- }
- set
- {
- CreateTextAttributes();
- buttonAttributes.TextAttributes.PaddingRight = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Text top padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int TextPaddingTop
- {
- get
- {
- return buttonAttributes?.TextAttributes?.PaddingTop ?? 0;
- }
- set
- {
- CreateTextAttributes();
- buttonAttributes.TextAttributes.PaddingTop = value;
- RelayoutRequest();
- }
- }
-
- /// <summary>
- /// Text bottom padding in Button, work only when show icon and text.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int TextPaddingBottom
- {
- get
- {
- return buttonAttributes?.TextAttributes?.PaddingBottom ?? 0;
- }
- set
- {
- CreateTextAttributes();
- buttonAttributes.TextAttributes.PaddingBottom = value;
- RelayoutRequest();
- }
- }
- /// <summary>
- /// Dispose Button and all children on it.
- /// </summary>
- /// <param name="type">Dispose type.</param>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override void Dispose(DisposeTypes type)
- {
- if (disposed)
- {
- return;
- }
-
- if (type == DisposeTypes.Explicit)
- {
- if (buttonIcon != null)
- {
- buttonIcon.Relayout -= OnIconRelayout;
- Utility.Dispose(buttonIcon);
- }
- if (buttonText != null)
- {
- Utility.Dispose(buttonText);
- }
- if (overlayImage != null)
- {
- Utility.Dispose(overlayImage);
- }
- if (backgroundImage != null)
- {
- Utility.Dispose(backgroundImage);
- }
- if (shadowImage != null)
- {
- Utility.Dispose(shadowImage);
- }
- }
-
- base.Dispose(type);
- }
- /// <summary>
- /// Called after a key event is received by the view that has had its focus set.
+ /// Called after a key event is received by the view that has had its focus set.
/// </summary>
/// <param name="key">The key event.</param>
/// <returns>True if the key event should be consumed.</returns>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
public override bool OnKey(Key key)
{
+ if (!IsEnabled || null == key)
+ {
+ return false;
+ }
+
if (key.State == Key.StateType.Down)
{
if (key.KeyPressedName == "Return")
{
isPressed = true;
UpdateState();
- if(isEnabled)
- {
- ClickEventArgs eventArgs = new ClickEventArgs();
- OnClick(eventArgs);
- }
}
}
else if (key.State == Key.StateType.Up)
{
if (key.KeyPressedName == "Return")
{
+ bool clicked = isPressed && IsEnabled;
+
isPressed = false;
- if (buttonAttributes.IsSelectable != null && buttonAttributes.IsSelectable == true)
+
+ if (IsSelectable)
{
- isSelected = !isSelected;
+ IsSelected = !IsSelected;
+ }
+ else
+ {
+ UpdateState();
+ }
+
+ if (clicked)
+ {
+ ClickedEventArgs eventArgs = new ClickedEventArgs();
+ OnClickedInternal(eventArgs);
}
- UpdateState();
}
}
return base.OnKey(key);
}
+
/// <summary>
/// Called when the control gain key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is gained.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <since_tizen> 8 </since_tizen>
public override void OnFocusGained()
{
base.OnFocusGained();
UpdateState();
}
+
/// <summary>
/// Called when the control loses key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is lost.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <since_tizen> 8 </since_tizen>
public override void OnFocusLost()
{
base.OnFocusLost();
UpdateState();
}
- /// <summary>
- /// Tap gesture event callback.
- /// </summary>
- /// <param name="source">Source which recieved touch event.</param>
- /// <param name="e">Tap gesture event argument.</param>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e)
- {
- if (isEnabled)
- {
- ClickEventArgs eventArgs = new ClickEventArgs();
- OnClick(eventArgs);
- base.OnTapGestureDetected(source, e);
- }
- }
/// <summary>
/// Called after a touch event is received by the owning view.<br />
/// </summary>
/// <param name="touch">The touch event.</param>
/// <returns>True if the event should be consumed.</returns>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <since_tizen> 8 </since_tizen>
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use OnClicked instead.")]
+#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
public override bool OnTouch(Touch touch)
+#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
{
- PointStateType state = touch.GetState(0);
-
- switch(state)
- {
- case PointStateType.Down:
- isPressed = true;
- UpdateState();
- return true;
- case PointStateType.Interrupted:
- isPressed = false;
- UpdateState();
- return true;
- case PointStateType.Up:
- isPressed = false;
- if (buttonAttributes.IsSelectable != null && buttonAttributes.IsSelectable == true)
- {
- isSelected = !isSelected;
- }
- UpdateState();
- return true;
- default:
- break;
- }
return base.OnTouch(touch);
}
+
/// <summary>
- /// Get Button attribues.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override Attributes GetAttributes()
- {
- return new ButtonAttributes();
- }
- /// <summary>
- /// Update Button by attributes.
+ /// Apply style to button.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override void OnUpdate()
+ /// <param name="viewStyle">The style to apply.</param>
+ /// <since_tizen> 8 </since_tizen>
+ public override void ApplyStyle(ViewStyle viewStyle)
{
- if (buttonAttributes.ShadowImageAttributes != null)
- {
- if(shadowImage == null)
- {
- shadowImage = new ImageView()
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- this.Add(shadowImage);
- }
- ApplyAttributes(shadowImage, buttonAttributes.ShadowImageAttributes);
- }
+ styleApplied = false;
- if (buttonAttributes.BackgroundImageAttributes != null)
- {
- if(backgroundImage == null)
- {
- backgroundImage = new ImageView()
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- this.Add(backgroundImage);
- }
- ApplyAttributes(backgroundImage, buttonAttributes.BackgroundImageAttributes);
- }
+ base.ApplyStyle(viewStyle);
- if (buttonAttributes.OverlayImageAttributes != null)
+ if (null != buttonStyle)
{
- if(overlayImage == null)
+ Extension = buttonStyle.CreateExtension();
+ if (buttonStyle.Overlay != null)
{
- overlayImage = new ImageView()
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- this.Add(overlayImage);
+ OverlayImage?.ApplyStyle(buttonStyle.Overlay);
}
- ApplyAttributes(overlayImage, buttonAttributes.OverlayImageAttributes);
- }
- if (buttonAttributes.TextAttributes != null)
- {
- if(buttonText == null)
+ if (buttonStyle.Text != null)
{
- buttonText = new TextLabel();
- this.Add(buttonText);
+ TextLabel?.ApplyStyle(buttonStyle.Text);
}
- ApplyAttributes(buttonText, buttonAttributes.TextAttributes);
- }
- if (buttonAttributes.IconAttributes != null)
- {
- if(buttonIcon == null)
+ if (buttonStyle.Icon != null)
{
- buttonIcon = new ImageView();
- buttonIcon.Relayout += OnIconRelayout;
- this.Add(buttonIcon);
+ Icon?.ApplyStyle(buttonStyle.Icon);
}
- ApplyAttributes(buttonIcon, buttonAttributes.IconAttributes);
- }
-
- MeasureText();
- LayoutChild();
-
- Sensitive = isEnabled ? true : false;
- }
-
- /// <summary>
- /// Update Button State.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected void UpdateState()
- {
- ControlStates sourceState = State;
- ControlStates targetState;
-
- if(isEnabled)
- {
- targetState = isPressed ? ControlStates.Pressed : (IsFocused ? (IsSelected ? ControlStates.SelectedFocused : ControlStates.Focused) : (IsSelected ? ControlStates.Selected : ControlStates.Normal));
- }
- else
- {
- targetState = IsSelected ? ControlStates.DisabledSelected : (IsFocused ? ControlStates.DisabledFocused : ControlStates.Disabled);
- }
- if(sourceState != targetState)
- {
- State = targetState;
-
- OnUpdate();
-
- StateChangeEventArgs e = new StateChangeEventArgs
- {
- PreviousState = sourceState,
- CurrentState = targetState
- };
- stateChangeHander?.Invoke(this, e);
- }
- }
- /// <summary>
- /// It is hijack by using protected, attributes copy problem when class inherited from Button.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- private void Initialize()
- {
- buttonAttributes = attributes as ButtonAttributes;
- if (buttonAttributes == null)
- {
- throw new Exception("Button attribute parse error.");
- }
-
- ApplyAttributes(this, buttonAttributes);
- LayoutDirectionChanged += OnLayoutDirectionChanged;
- }
-
- /// <summary>
- /// Measure text, it can be override.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected virtual void MeasureText()
- {
- if (buttonAttributes.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
- {
- return;
}
- buttonText.WidthResizePolicy = ResizePolicyType.Fixed;
- buttonText.HeightResizePolicy = ResizePolicyType.Fixed;
- int textPaddingLeft = buttonAttributes.TextAttributes.PaddingLeft;
- int textPaddingRight = buttonAttributes.TextAttributes.PaddingRight;
- int textPaddingTop = buttonAttributes.TextAttributes.PaddingTop;
- int textPaddingBottom = buttonAttributes.TextAttributes.PaddingBottom;
-
- int iconPaddingLeft = buttonAttributes.IconAttributes.PaddingLeft;
- int iconPaddingRight = buttonAttributes.IconAttributes.PaddingRight;
- int iconPaddingTop = buttonAttributes.IconAttributes.PaddingTop;
- int iconPaddingBottom = buttonAttributes.IconAttributes.PaddingBottom;
- if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
- {
- buttonText.SizeWidth = SizeWidth - textPaddingLeft - textPaddingRight;
- buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - buttonIcon.SizeHeight;
- }
- else
- {
- buttonText.SizeWidth = SizeWidth - textPaddingLeft - textPaddingRight - iconPaddingLeft - iconPaddingRight - buttonIcon.SizeWidth;
- buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
- }
+ styleApplied = true;
}
- /// <summary>
- /// Layout child, it can be override.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected virtual void LayoutChild()
- {
- if (buttonAttributes.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
- {
- return;
- }
-
- int textPaddingLeft = buttonAttributes.TextAttributes.PaddingLeft;
- int textPaddingRight = buttonAttributes.TextAttributes.PaddingRight;
- int textPaddingTop = buttonAttributes.TextAttributes.PaddingTop;
- int textPaddingBottom = buttonAttributes.TextAttributes.PaddingBottom;
-
- int iconPaddingLeft = buttonAttributes.IconAttributes.PaddingLeft;
- int iconPaddingRight = buttonAttributes.IconAttributes.PaddingRight;
- int iconPaddingTop = buttonAttributes.IconAttributes.PaddingTop;
- int iconPaddingBottom = buttonAttributes.IconAttributes.PaddingBottom;
-
- switch (IconRelativeOrientation)
- {
- case IconOrientation.Top:
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.TopCenter;
- buttonIcon.PivotPoint = NUI.PivotPoint.TopCenter;
- buttonIcon.Position2D = new Position2D(0, iconPaddingTop);
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
- buttonText.PivotPoint = NUI.PivotPoint.BottomCenter;
- buttonText.Position2D = new Position2D(0, -textPaddingBottom);
- break;
- case IconOrientation.Bottom:
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.BottomCenter;
- buttonIcon.PivotPoint = NUI.PivotPoint.BottomCenter;
- buttonIcon.Position2D = new Position2D(0, -iconPaddingBottom);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.TopCenter;
- buttonText.PivotPoint = NUI.PivotPoint.TopCenter;
- buttonText.Position2D = new Position2D(0, textPaddingTop);
- break;
- case IconOrientation.Left:
- if (LayoutDirection == ViewLayoutDirectionType.LTR)
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonIcon.Position2D = new Position2D(iconPaddingLeft, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonText.Position2D = new Position2D(-textPaddingRight, 0);
- }
- else
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonIcon.Position2D = new Position2D(-iconPaddingLeft, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonText.Position2D = new Position2D(textPaddingRight, 0);
- }
-
- break;
- case IconOrientation.Right:
- if (LayoutDirection == ViewLayoutDirectionType.RTL)
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonIcon.Position2D = new Position2D(iconPaddingRight, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonText.Position2D = new Position2D(-textPaddingLeft, 0);
- }
- else
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonIcon.Position2D = new Position2D(-iconPaddingRight, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonText.Position2D = new Position2D(textPaddingLeft, 0);
- }
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// Theme change callback when theme is changed, this callback will be trigger.
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
- {
- ButtonAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as ButtonAttributes;
- if(tempAttributes != null)
- {
- attributes = buttonAttributes = tempAttributes;
- RelayoutRequest();
- }
- }
-
- private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
- {
- MeasureText();
- LayoutChild();
- }
-
- private void OnClick(ClickEventArgs eventArgs)
- {
- ClickEvent?.Invoke(this, eventArgs);
- }
-
- private void OnIconRelayout(object sender, EventArgs e)
- {
- MeasureText();
- LayoutChild();
- }
-
- private void CreateBackgroundAttributes()
- {
- if (buttonAttributes.BackgroundImageAttributes == null)
- {
- buttonAttributes.BackgroundImageAttributes = new ImageAttributes()
- {
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.Center,
- PivotPoint = Tizen.NUI.PivotPoint.Center,
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- }
- }
-
- private void CreateShadowAttributes()
- {
- if (buttonAttributes.ShadowImageAttributes == null)
- {
- buttonAttributes.ShadowImageAttributes = new ImageAttributes()
- {
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.Center,
- PivotPoint = Tizen.NUI.PivotPoint.Center,
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- }
- }
-
- private void CreateOverlayAttributes()
- {
- if (buttonAttributes.OverlayImageAttributes == null)
- {
- buttonAttributes.OverlayImageAttributes = new ImageAttributes()
- {
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.Center,
- PivotPoint = Tizen.NUI.PivotPoint.Center,
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- }
- }
-
- private void CreateTextAttributes()
- {
- if (buttonAttributes.TextAttributes == null)
- {
- buttonAttributes.TextAttributes = new TextAttributes()
- {
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.Center,
- PivotPoint = Tizen.NUI.PivotPoint.Center,
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center
- };
- }
- }
-
- private void CreateIconAttributes()
- {
- if (buttonAttributes.IconAttributes == null)
- {
- buttonAttributes.IconAttributes = new ImageAttributes()
- {
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.Center,
- PivotPoint = Tizen.NUI.PivotPoint.Center,
- WidthResizePolicy = ResizePolicyType.UseNaturalSize,
- HeightResizePolicy = ResizePolicyType.UseNaturalSize,
- };
- }
- }
/// <summary>
/// ClickEventArgs is a class to record button click event arguments which will sent to user.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use ClickedEventArgs instead.")]
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
public class ClickEventArgs : EventArgs
{
}
+
/// <summary>
/// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public class StateChangeEventArgs : EventArgs
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
+ public class StateChangedEventArgs : EventArgs
{
/// <summary> previous state of Button </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// It will be removed in API10
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
+ [Obsolete("Deprecated in API8; Will be removed in API10")]
public ControlStates PreviousState;
/// <summary> current state of Button </summary>
/// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// It will be removed in API10
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
+ [Obsolete("Deprecated in API8; Will be removed in API10")]
public ControlStates CurrentState;
}
-
}
}