/*
- * 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.ComponentModel;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
+using Tizen.NUI.Components.Extension;
namespace Tizen.NUI.Components
{
/// Button may contain text or an icon.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- public class Button : Control
+ public partial class Button : Control
{
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
var instance = (Button)bindable;
if (newValue != null)
{
- instance.privateIconRelativeOrientation = (IconOrientation?)newValue;
+ if (instance.Style != null && instance.Style.IconRelativeOrientation != (IconOrientation?)newValue)
+ {
+ instance.Style.IconRelativeOrientation = (IconOrientation?)newValue;
+ instance.UpdateUIContent();
+ }
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Button)bindable;
- return instance.privateIconRelativeOrientation;
+ return instance.Style?.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)]
var instance = (Button)bindable;
if (newValue != null)
{
- instance.privateIsEnabled = (bool)newValue;
+ instance.isEnabled = (bool)newValue;
+ instance.UpdateState();
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Button)bindable;
- return instance.privateIsEnabled;
+ return instance.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)]
var instance = (Button)bindable;
if (newValue != null)
{
- instance.privateIsSelected = (bool)newValue;
+ instance.isSelected = (bool)newValue;
+ instance.UpdateState();
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Button)bindable;
- return instance.privateIsSelected;
+ return 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)]
var instance = (Button)bindable;
if (newValue != null)
{
- instance.privateIsSelectable = (bool)newValue;
+ instance.Style.IsSelectable = (bool)newValue;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Button)bindable;
- return instance.privateIsSelectable;
+ return instance.Style?.IsSelectable ?? false;
});
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
return instance.Style?.TextPadding;
});
- private ImageView overlayImage;
-
- private TextLabel buttonText;
- private ImageControl buttonIcon;
-
- private EventHandler<StateChangedEventArgs> stateChangeHander;
-
- private bool isSelected = false;
- private bool isEnabled = true;
- private bool isPressed = false;
-
static Button() { }
/// <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="controlStyle">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(ButtonStyle controlStyle) : base(controlStyle)
+ /// <param name="buttonStyle">Create Button by style customized by user.</param>
+ /// <since_tizen> 8 </since_tizen>
+ public Button(ButtonStyle buttonStyle) : base(buttonStyle)
{
Initialize();
}
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<ClickEventArgs> ClickEvent;
+
/// <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>
+ [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>
Right,
}
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <summary>
+ /// Button's icon part.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public ImageView Icon
+ {
+ get
+ {
+ if (null == buttonIcon)
+ {
+ buttonIcon = CreateIcon();
+ if (null != Extension)
+ {
+ buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
+ }
+ Add(buttonIcon);
+ buttonIcon.Relayout += OnIconRelayout;
+ }
+ return buttonIcon;
+ }
+ internal set
+ {
+ buttonIcon = value;
+ }
+ }
+
+ /// <summary>
+ /// Button's overlay image part.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public ImageView OverlayImage
+ {
+ get
+ {
+ if (null == overlayImage)
+ {
+ overlayImage = CreateOverlayImage();
+ if (null != Extension)
+ {
+ overlayImage = Extension.OnCreateOverlayImage(this, overlayImage);
+ }
+ overlayImage.WidthResizePolicy = ResizePolicyType.FillToParent;
+ overlayImage.HeightResizePolicy = ResizePolicyType.FillToParent;
+ Add(overlayImage);
+ }
+ return overlayImage;
+ }
+ internal set
+ {
+ overlayImage = value;
+ }
+ }
+
+ /// <summary>
+ /// Button's text part.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public TextLabel TextLabel
+ {
+ get
+ {
+ if (null == buttonText)
+ {
+ buttonText = CreateText();
+ if (null != Extension)
+ {
+ buttonText = Extension.OnCreateText(this, buttonText);
+ }
+ buttonText.HorizontalAlignment = HorizontalAlignment.Center;
+ buttonText.VerticalAlignment = VerticalAlignment.Center;
+ Add(buttonText);
+ }
+ return buttonText;
+ }
+ internal set
+ {
+ buttonText = value;
+ }
+ }
+
+ /// <summary>
+ /// Return a copied Style instance of Button
+ /// </summary>
+ /// <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 => ViewStyle as ButtonStyle;
/// <summary>
}
}
- private bool privateIsSelectable
- {
- get
- {
- return Style?.IsSelectable ?? false;
- }
- set
- {
- Style.IsSelectable = value;
- }
- }
-
/// <summary>
/// Translate text string in Button.
/// </summary>
}
}
}
+
/// <summary>
/// Text color in Button.
/// </summary>
}
}
}
+
/// <summary>
/// Text horizontal alignment in Button.
/// </summary>
}
}
}
+
/// <summary>
/// Icon image's resource url in Button.
/// </summary>
}
}
- private StringSelector textSelector = new StringSelector();
/// <summary>
/// Text string selector in Button.
/// </summary>
}
set
{
- textSelector.Clone(value);
+ if (value == null || textSelector == null)
+ {
+ Tizen.Log.Fatal("NUI", "[Exception] Button.TextSelector is null");
+ throw new NullReferenceException("Button.TextSelector is null");
+ }
+ else
+ {
+ textSelector.Clone(value);
+ }
}
}
- private StringSelector translatableTextSelector = new StringSelector();
/// <summary>
/// Translateable text string selector in Button.
/// </summary>
}
set
{
- translatableTextSelector.Clone(value);
+ if (value == null || translatableTextSelector == null)
+ {
+ Tizen.Log.Fatal("NUI", "[Exception] Button.TranslatableTextSelector is null");
+ throw new NullReferenceException("Button.TranslatableTextSelector is null");
+ }
+ else
+ {
+ translatableTextSelector.Clone(value);
+ }
}
}
- private ColorSelector textColorSelector = new ColorSelector();
/// <summary>
/// Text color selector in Button.
/// </summary>
}
set
{
- textColorSelector.Clone(value);
+ if (value == null || textColorSelector == null)
+ {
+ Tizen.Log.Fatal("NUI", "[Exception] Button.textColorSelector is null");
+ throw new NullReferenceException("Button.textColorSelector is null");
+ }
+ else
+ {
+ textColorSelector.Clone(value);
+ }
}
}
- private FloatSelector pointSizeSelector = new FloatSelector();
/// <summary>
/// Text font size selector in Button.
/// </summary>
}
set
{
- pointSizeSelector.Clone(value);
+ if (value == null || pointSizeSelector == null)
+ {
+ Tizen.Log.Fatal("NUI", "[Exception] Button.pointSizeSelector is null");
+ throw new NullReferenceException("Button.pointSizeSelector is null");
+ }
+ else
+ {
+ pointSizeSelector.Clone(value);
+ }
}
}
- private StringSelector iconURLSelector = new StringSelector();
/// <summary>
/// Icon image's resource url selector in Button.
/// </summary>
}
set
{
- iconURLSelector.Clone(value);
+ if (value == null || iconURLSelector == null)
+ {
+ Tizen.Log.Fatal("NUI", "[Exception] Button.iconURLSelector is null");
+ throw new NullReferenceException("Button.iconURLSelector is null");
+ }
+ else
+ {
+ iconURLSelector.Clone(value);
+ }
}
}
SetValue(IsSelectedProperty, value);
}
}
- private bool privateIsSelected
- {
- get
- {
- return isSelected;
- }
- set
- {
- isSelected = value;
- UpdateState();
- }
- }
+
/// <summary>
/// Flag to decide enable or disable in Button.
/// </summary>
SetValue(IsEnabledProperty, value);
}
}
- private bool privateIsEnabled
- {
- 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)]
+ /// <since_tizen> 8 </since_tizen>
public IconOrientation? IconRelativeOrientation
{
get
SetValue(IconRelativeOrientationProperty, value);
}
}
- private IconOrientation? privateIconRelativeOrientation
- {
- get
- {
- return Style?.IconRelativeOrientation;
- }
- set
- {
- if(Style != null && Style.IconRelativeOrientation != value)
- {
- Style.IconRelativeOrientation = value;
- UpdateUIContent();
- }
- }
- }
/// <summary>
/// Icon padding in Button, work only when show icon and text.
/// <since_tizen> 6 </since_tizen>
public Extents TextPadding
{
- get => (Extents) GetValue(TextPaddingProperty);
+ get => (Extents)GetValue(TextPaddingProperty);
set => SetValue(TextPaddingProperty, value);
}
/// <summary>
- /// Dispose Button and all children on it.
- /// </summary>
- /// <param name="type">Dispose type.</param>
- /// <since_tizen> 6 </since_tizen>
- protected override void Dispose(DisposeTypes type)
- {
- if (disposed)
- {
- return;
- }
-
- if (type == DisposeTypes.Explicit)
- {
- if (buttonIcon != null)
- {
- Utility.Dispose(buttonIcon);
- }
- if (buttonText != null)
- {
- Utility.Dispose(buttonText);
- }
- if (overlayImage != null)
- {
- Utility.Dispose(overlayImage);
- }
- }
-
- base.Dispose(type);
- }
- /// <summary>
/// Called after a key event is received by the view that has had its focus set.
/// </summary>
/// <param name="key">The key event.</param>
/// <since_tizen> 6 </since_tizen>
public override bool OnKey(Key key)
{
- if (null == key) return false;
+ 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 (Style.IsSelectable != null && Style.IsSelectable == true)
{
- isSelected = !isSelected;
+ IsSelected = !IsSelected;
+ }
+ else
+ {
+ UpdateState();
+ }
+
+ if (clicked)
+ {
+ ClickEventArgs eventArgs = new ClickEventArgs();
+ OnClickInternal(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();
/// <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();
}
/// <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 />
/// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<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>
public override bool OnTouch(Touch touch)
{
- if (null == touch) return false;
+ if (!IsEnabled || null == touch)
+ {
+ return false;
+ }
+
PointStateType state = touch.GetState(0);
- switch(state)
+ switch (state)
{
case PointStateType.Down:
isPressed = true;
+ Extension?.SetTouchInfo(touch);
UpdateState();
return true;
case PointStateType.Interrupted:
UpdateState();
return true;
case PointStateType.Up:
- isPressed = false;
- if (Style.IsSelectable != null && Style.IsSelectable == true)
{
- isSelected = !isSelected;
+ bool clicked = isPressed && isEnabled;
+
+ isPressed = false;
+
+ if (Style.IsSelectable != null && Style.IsSelectable == true)
+ {
+ Extension?.SetTouchInfo(touch);
+ IsSelected = !IsSelected;
+ }
+ else
+ {
+ Extension?.SetTouchInfo(touch);
+ UpdateState();
+ }
+
+ if (clicked)
+ {
+ ClickEventArgs eventArgs = new ClickEventArgs();
+ OnClickInternal(eventArgs);
+ }
+
+ return true;
}
- UpdateState();
- return true;
default:
break;
}
return base.OnTouch(touch);
}
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
+ /// <summary>
+ /// Apply style to button.
+ /// </summary>
+ /// <param name="viewStyle">The style to apply.</param>
+ /// <since_tizen> 8 </since_tizen>
public override void ApplyStyle(ViewStyle viewStyle)
{
base.ApplyStyle(viewStyle);
ButtonStyle buttonStyle = viewStyle as ButtonStyle;
-
if (null != buttonStyle)
{
- if (null == overlayImage)
+ Extension = buttonStyle.CreateExtension();
+ if (buttonStyle.Overlay != null)
{
- overlayImage = new ImageView()
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent
- };
- this.Add(overlayImage);
+ OverlayImage?.ApplyStyle(buttonStyle.Overlay);
}
- if (null == buttonText)
+ if (buttonStyle.Text != null)
{
- buttonText = new TextLabel();
- this.Add(buttonText);
+ TextLabel?.ApplyStyle(buttonStyle.Text);
}
- if (null == buttonIcon)
+ if (buttonStyle.Icon != null)
{
- buttonIcon = new ImageControl();
- this.Add(buttonIcon);
+ Icon?.ApplyStyle(buttonStyle.Icon);
}
-
- overlayImage.ApplyStyle(buttonStyle.Overlay);
- buttonText.ApplyStyle(buttonStyle.Text);
- buttonIcon.ApplyStyle(buttonStyle.Icon);
}
}
/// <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 ViewStyle GetViewStyle()
- {
- return new ButtonStyle();
- }
-
- /// 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()
- {
- base.OnUpdate();
- UpdateUIContent();
- }
-
- /// <summary>
- /// Update Button State.
+ /// 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)]
- protected void UpdateState()
+ public class ClickEventArgs : EventArgs
{
- ControlStates sourceState = ControlState;
- 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)
- {
- ControlState = targetState;
-
- OnUpdate();
-
- StateChangedEventArgs e = new StateChangedEventArgs
- {
- PreviousState = sourceState,
- CurrentState = targetState
- };
- stateChangeHander?.Invoke(this, e);
- }
}
/// <summary>
- /// It is hijack by using protected, attributes copy problem when class inherited from Button.
+ /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
/// </summary>
/// <since_tizen> 6 </since_tizen>
- private void Initialize()
+ [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
+ public class StateChangedEventArgs : EventArgs
{
- if (null == Style.IconRelativeOrientation) Style.IconRelativeOrientation = IconOrientation.Left;
- UpdateState();
- LayoutDirectionChanged += OnLayoutDirectionChanged;
+ /// <summary> previous state of Button </summary>
+ /// <since_tizen> 6 </since_tizen>
+ [Obsolete("Deprecated in API8; Will be removed in API10")]
+ public ControlStates PreviousState;
+ /// <summary> current state of Button </summary>
+ /// <since_tizen> 6 </since_tizen>
+ [Obsolete("Deprecated in API8; Will be removed in API10")]
+ public ControlStates CurrentState;
}
/// <summary>
- /// Measure text, it can be override.
+ /// Get current text part to the attached ButtonExtension.
/// </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.
+ /// <remarks>
+ /// It returns null if the passed extension is invalid.
+ /// </remarks>
+ /// <param name="extension">The extension instance that is currently attached to this Button.</param>
+ /// <return>The button's text part.</return>
[EditorBrowsable(EditorBrowsableState.Never)]
- protected virtual void MeasureText()
+ public TextLabel GetCurrentText(ButtonExtension extension)
{
- if (Style.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
- {
- return;
- }
- buttonText.WidthResizePolicy = ResizePolicyType.Fixed;
- buttonText.HeightResizePolicy = ResizePolicyType.Fixed;
- int textPaddingStart = Style.TextPadding.Start;
- int textPaddingEnd = Style.TextPadding.End;
- int textPaddingTop = Style.TextPadding.Top;
- int textPaddingBottom = Style.TextPadding.Bottom;
-
- int iconPaddingStart = Style.IconPadding.Start;
- int iconPaddingEnd = Style.IconPadding.End;
- int iconPaddingTop = Style.IconPadding.Top;
- int iconPaddingBottom = Style.IconPadding.Bottom;
-
- if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
- {
- buttonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd;
- buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - buttonIcon.SizeHeight;
- }
- else
- {
- buttonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd - iconPaddingStart - iconPaddingEnd - buttonIcon.SizeWidth;
- buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
- }
+ return (extension == Extension) ? TextLabel : null;
}
- /// <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 (Style.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
- {
- return;
- }
-
- int textPaddingStart = Style.TextPadding.Start;
- int textPaddingEnd = Style.TextPadding.End;
- int textPaddingTop = Style.TextPadding.Top;
- int textPaddingBottom = Style.TextPadding.Bottom;
-
- int iconPaddingStart = Style.IconPadding.Start;
- int iconPaddingEnd = Style.IconPadding.End;
- int iconPaddingTop = Style.IconPadding.Top;
- int iconPaddingBottom = Style.IconPadding.Bottom;
-
- 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(iconPaddingStart, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonText.Position2D = new Position2D(-textPaddingEnd, 0);
- }
- else
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonIcon.Position2D = new Position2D(-iconPaddingStart, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonText.Position2D = new Position2D(textPaddingEnd, 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(iconPaddingEnd, 0);
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonText.Position2D = new Position2D(-textPaddingStart, 0);
- }
- else
- {
- buttonIcon.PositionUsesPivotPoint = true;
- buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
- buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
- buttonIcon.Position2D = new Position2D(-iconPaddingEnd, 0);
-
- buttonText.PositionUsesPivotPoint = true;
- buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
- buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
- buttonText.Position2D = new Position2D(textPaddingStart, 0);
- }
- break;
- default:
- break;
- }
- if (string.IsNullOrEmpty(buttonText.Text))
- {
- buttonIcon.ParentOrigin = NUI.ParentOrigin.Center;
- buttonIcon.PivotPoint = NUI.PivotPoint.Center;
- }
- }
/// <summary>
- /// Theme change callback when theme is changed, this callback will be trigger.
+ /// Get current icon part to the attached ButtonExtension.
/// </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.
+ /// <remarks>
+ /// It returns null if the passed extension is invalid.
+ /// </remarks>
+ /// <param name="extension">The extension instance that is currently attached to this Button.</param>
+ /// <return>The button's icon part.</return>
[EditorBrowsable(EditorBrowsableState.Never)]
- protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
- {
- ButtonStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as ButtonStyle;
- if (tempAttributes != null)
- {
- Style.CopyFrom(tempAttributes);
- UpdateUIContent();
- }
- }
-
- private void UpdateUIContent()
- {
- MeasureText();
- LayoutChild();
-
- Sensitive = isEnabled;
- }
-
- 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)
+ public ImageView GetCurrentIcon(ButtonExtension extension)
{
- MeasureText();
- LayoutChild();
+ return (extension == Extension) ? Icon : null;
}
/// <summary>
- /// ClickEventArgs is a class to record button click event arguments which will sent to user.
+ /// Get current overlay image part to the attached ButtonExtension.
/// </summary>
- /// <since_tizen> 6 </since_tizen>
- 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>
- public class StateChangedEventArgs : EventArgs
+ /// <remarks>
+ /// It returns null if the passed extension is invalid.
+ /// </remarks>
+ /// <param name="extension">The extension instance that is currently attached to this Button.</param>
+ /// <return>The button's overlay image part.</return>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ImageView GetCurrentOverlayImage(ButtonExtension extension)
{
- /// <summary> previous state of Button </summary>
- /// <since_tizen> 6 </since_tizen>
- public ControlStates PreviousState;
- /// <summary> current state of Button </summary>
- /// <since_tizen> 6 </since_tizen>
- public ControlStates CurrentState;
+ return (extension == Extension) ? OverlayImage : null;
}
-
}
}