using System;
using Tizen.NUI.BaseComponents;
using System.ComponentModel;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.Components
{
/// The ScrollBar class of nui component. It allows users to recognize the direction and the range of lists/content. .
/// </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 ScrollBar : Control
{
- private ScrollBarAttributes scrollBarAttrs;
+ /// 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 DirectionProperty = BindableProperty.Create(nameof(Direction), typeof(DirectionType), typeof(ScrollBar), DirectionType.Horizontal, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ScrollBar)bindable;
+ if (newValue != null)
+ {
+ instance.Style.Direction = (DirectionType?)newValue;
+ instance.UpdateValue();
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.Style.Direction;
+ });
+ /// 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 MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(int), typeof(ScrollBar), default(int), propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ScrollBar)bindable;
+ if (newValue != null)
+ {
+ if ((int)newValue >= 0)
+ {
+ instance.maxValue = (int)newValue;
+ instance.UpdateValue();
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.maxValue;
+ });
+ /// 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 MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(int), typeof(ScrollBar), default(int), propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ScrollBar)bindable;
+ if (newValue != null)
+ {
+ if ((int)newValue >= 0)
+ {
+ instance.minValue = (int)newValue;
+ instance.UpdateValue();
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.minValue;
+ });
+ /// 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 CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(int), typeof(ScrollBar), default(int), propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ScrollBar)bindable;
+ if (newValue != null)
+ {
+ if ((int)newValue >= 0)
+ {
+ instance.curValue = (int)newValue;
+ instance.UpdateValue();
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.curValue;
+ });
+ /// 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 DurationProperty = BindableProperty.Create(nameof(Duration), typeof(uint), typeof(ScrollBar), default(uint), propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ScrollBar)bindable;
+ if (newValue != null)
+ {
+ instance.Style.Duration = (uint)newValue;
+ if (instance.scrollAniPlayer != null)
+ {
+ instance.scrollAniPlayer.Duration = (int)(uint)newValue;
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.Style.Duration;
+ });
+
private ImageView trackImage;
private ImageView thumbImage;
private Animation scrollAniPlayer = null;
private int minValue;
private int maxValue;
private int curValue;
+ static ScrollBar() { }
/// <summary>
- /// The constructor of ScrollBar
+ /// The constructor of ScrollBar.
/// </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 ScrollBar() : base()
{
Initialize();
}
/// <summary>
- /// The constructor of ScrollBar with specific Attributes.
+ /// The constructor of ScrollBar with specific style.
/// </summary>
- /// <param name="attributes">The Attributes object to initialize the ScrollBar.</param>
+ /// <param name="style">The style object to initialize the ScrollBar.</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 ScrollBar(ScrollBarAttributes attributes) : base(attributes)
+ public ScrollBar(ScrollBarStyle style) : base(style)
{
Initialize();
}
/// The direction type of the Scroll.
/// </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 DirectionType
{
/// <summary>
/// The Horizontal type.
/// </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)]
Horizontal,
/// <summary>
/// The Vertical type.
/// </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)]
Vertical
}
#region public property
+ /// 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 new ScrollBarStyle Style => ViewStyle as ScrollBarStyle;
/// <summary>
/// The property to get/set the direction of the ScrollBar.
/// </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 DirectionType Direction
{
get
{
- return scrollBarAttrs.Direction.Value;
+ return (DirectionType)GetValue(DirectionProperty);
}
set
{
- scrollBarAttrs.Direction = value;
- RelayoutRequest();
+ SetValue(DirectionProperty, value);
}
}
/// </code>
/// </example>
/// <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 Size2D ThumbSize
+ public Size ThumbSize
{
get
{
- if (scrollBarAttrs.ThumbImageAttributes.Size2D == null)
- {
- scrollBarAttrs.ThumbImageAttributes.Size2D = new Size2D();
- }
- return scrollBarAttrs.ThumbImageAttributes.Size2D;
+ return Style?.Thumb?.Size;
}
set
{
- if (scrollBarAttrs.ThumbImageAttributes.Size2D == null)
+ if (null != Style?.Thumb)
{
- scrollBarAttrs.ThumbImageAttributes.Size2D = new Size2D();
- }
- if (thumbImage != null)
- {
- scrollBarAttrs.ThumbImageAttributes.Size2D.Width = value.Width;
- scrollBarAttrs.ThumbImageAttributes.Size2D.Height = value.Height;
+ Style.Thumb.Size = value;
RelayoutRequest();
}
}
/// The property to get/set the image URL of the track object.
/// </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 TrackImageURL
{
get
{
- return scrollBarAttrs.TrackImageAttributes.ResourceURL.All;
+ return Style?.Track?.ResourceUrl?.All;
}
set
{
- if (trackImage != null)
+ if (null != Style?.Track)
{
- if (scrollBarAttrs.TrackImageAttributes.ResourceURL == null)
- {
- scrollBarAttrs.TrackImageAttributes.ResourceURL = new StringSelector();
- }
- scrollBarAttrs.TrackImageAttributes.ResourceURL.All = value;
+ Style.Track.ResourceUrl = value;
+ RelayoutRequest();
}
- RelayoutRequest();
}
}
/// The property to get/set the color of the track object.
/// </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 TrackColor
{
get
{
- return scrollBarAttrs.TrackImageAttributes.BackgroundColor?.All;
+ return Style?.Track?.BackgroundColor?.All;
}
set
{
- if (scrollBarAttrs.TrackImageAttributes.BackgroundColor == null)
- {
- scrollBarAttrs.TrackImageAttributes.BackgroundColor = new ColorSelector { All = value };
- }
- else
+ if (null != Style?.Track)
{
- scrollBarAttrs.TrackImageAttributes.BackgroundColor.All = value;
+ Style.Track.BackgroundColor = value;
+ RelayoutRequest();
}
- RelayoutRequest();
}
}
/// The property to get/set the color of the thumb object.
/// </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 ThumbColor
{
get
{
- return scrollBarAttrs.ThumbImageAttributes.BackgroundColor?.All;
+ return Style?.Thumb?.BackgroundColor?.All;
}
set
{
- if(scrollBarAttrs.ThumbImageAttributes.BackgroundColor == null)
- {
- scrollBarAttrs.ThumbImageAttributes.BackgroundColor = new ColorSelector { All = value };
- }
- else
+ if(null != Style?.Thumb)
{
- scrollBarAttrs.ThumbImageAttributes.BackgroundColor.All = value;
+ Style.Thumb.BackgroundColor = value;
+ RelayoutRequest();
}
- RelayoutRequest();
}
}
/// The property to get/set the max value of the ScrollBar.
/// </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 MaxValue
{
get
{
- return maxValue;
+ return (int)GetValue(MaxValueProperty);
}
set
{
- if(value >= 0)
- {
- maxValue = value;
- RelayoutRequest();
- }
+ SetValue(MaxValueProperty, value);
}
}
/// The property to get/set the min value of the ScrollBar.
/// </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 MinValue
{
get
{
- return minValue;
+ return (int)GetValue(MinValueProperty);
}
set
{
- if(value >= 0)
- {
- minValue = value;
- RelayoutRequest();
- }
+ SetValue(MinValueProperty, value);
}
}
/// </code>
/// </example>
/// <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 CurrentValue
{
get
{
- return curValue;
+ return (int)GetValue(CurrentValueProperty);
}
set
{
- if(value >= 0)
- {
- curValue = value;
- RelayoutRequest();
- }
+ SetValue(CurrentValueProperty, value);
}
}
/// Property to set/get animation duration.
/// </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 uint Duration
{
get
{
- return scrollBarAttrs.Duration;
+ return (uint)GetValue(DurationProperty);
}
set
{
- scrollBarAttrs.Duration = value;
- if (scrollAniPlayer != null)
- {
- scrollAniPlayer.Duration = (int)value;
- }
+ SetValue(DurationProperty, value);
}
}
#endregion
/// Method to set current value. The thumb object would move to the corresponding position with animation or not.
/// </summary>
/// <param name="currentValue">The special current value.</param>
- /// <param name="isEnableAni">Enable move with animation or not, the default value is true.</param>
+ /// <param name="enableAnimation">Enable move with animation or not, the default value is true.</param>
/// <exception cref="ArgumentOutOfRangeException">Throw when current size is less than the min value, or greater than the max value.</exception>
/// <example>
/// <code>
/// </code>
/// </example>
/// <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 void SetCurrentValue(int currentValue, bool isEnableAni = true)
+ public void SetCurrentValue(int currentValue, bool enableAnimation = true)
{
if (currentValue < minValue || currentValue > maxValue)
{
//TNLog.E("Current value is less than the Min value, or greater than the Max value. currentValue = " + currentValue + ";");
+#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentOutOfRangeException("Wrong Current value. It shoud be greater than the Min value, and less than the Max value!");
+#pragma warning restore CA2208 // Instantiate argument exceptions correctly
}
- enableAni = isEnableAni;
+ enableAni = enableAnimation;
CurrentValue = currentValue;
}
/// </summary>
/// <param name="type">The DisposeTypes value.</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)
//Release your own managed resources here.
//You should release all of your own disposable objects here.
- if (trackImage != null)
- {
- Utility.Dispose(trackImage);
- }
-
- if (thumbImage != null)
- {
- Utility.Dispose(thumbImage);
- }
+ Utility.Dispose(trackImage);
+ Utility.Dispose(thumbImage);
if (scrollAniPlayer != null)
{
scrollAniPlayer.Dispose();
scrollAniPlayer = null;
}
- // UIDirectionChangedEvent -= OnUIDirectionChangedEvent;
}
//Release your own unmanaged resources here.
}
/// <summary>
- /// The method to update Attributes.
+ /// Get Scrollbar style.
/// </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()
+ protected override ViewStyle GetViewStyle()
{
- ApplyAttributes(this, scrollBarAttrs);
- ApplyAttributes(trackImage, scrollBarAttrs.TrackImageAttributes);
- ApplyAttributes(thumbImage, scrollBarAttrs.ThumbImageAttributes);
- if (enableAni)
- {
- UpdateValue(true);
- enableAni = false;
- }
- else
- {
- UpdateValue();
- }
- }
-
- /// <summary>
- /// Get Scrollbar 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 ScrollBarAttributes()
- {
- ThumbImageAttributes = new ImageAttributes
- {
- WidthResizePolicy = ResizePolicyType.Fixed,
- HeightResizePolicy = ResizePolicyType.Fixed,
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
- PivotPoint = Tizen.NUI.PivotPoint.TopLeft
- },
- TrackImageAttributes = new ImageAttributes
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent,
- PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
- PivotPoint = Tizen.NUI.PivotPoint.TopLeft
- }
-
- };
+ return new ScrollBarStyle();
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
{
- ScrollBarAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as ScrollBarAttributes;
- if (tempAttributes != null)
+ ScrollBarStyle tempStyle = StyleManager.Instance.GetViewStyle(style) as ScrollBarStyle;
+ if (tempStyle != null)
{
- attributes = scrollBarAttrs = tempAttributes;
- RelayoutRequest();
+ Style.CopyFrom(tempStyle);
+ UpdateValue();
}
}
private void Initialize()
{
- scrollBarAttrs = this.attributes as ScrollBarAttributes;
- if(scrollBarAttrs == null)
- {
- throw new Exception("ScrollBar attribute parse error.");
- }
-
this.Focusable = false;
trackImage = new ImageView
WidthResizePolicy = ResizePolicyType.FillToParent,
HeightResizePolicy = ResizePolicyType.FillToParent,
PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
- PivotPoint = Tizen.NUI.PivotPoint.TopLeft
-
+ ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
+ PivotPoint = Tizen.NUI.PivotPoint.CenterLeft
};
+ this.Add(trackImage);
+ trackImage.ApplyStyle(Style.Track);
+
thumbImage = new ImageView
{
Focusable = false,
WidthResizePolicy = ResizePolicyType.Fixed,
HeightResizePolicy = ResizePolicyType.Fixed,
PositionUsesPivotPoint = true,
- ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
- PivotPoint = Tizen.NUI.PivotPoint.TopLeft
+ ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
+ PivotPoint = Tizen.NUI.PivotPoint.CenterLeft
};
-
- Add(trackImage);
- Add(thumbImage);
+ this.Add(thumbImage);
+ thumbImage.ApplyStyle(Style.Thumb);
scrollAniPlayer = new Animation(334);
scrollAniPlayer.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
RelayoutRequest();
}
- private void UpdateValue(bool enableAni = false)
+ private void UpdateValue()
{
- if (trackImage == null || thumbImage == null || scrollBarAttrs.Direction == null)
- {
- return;
- }
+ if (minValue >= maxValue || curValue < minValue || curValue > maxValue) return;
- if (minValue >= maxValue || curValue < minValue || curValue > maxValue)
- {
- return;
- }
float width = (float)Size2D.Width;
float height = (float)Size2D.Height;
float thumbW = 0.0f;
float thumbH = 0.0f;
- if (scrollBarAttrs.ThumbImageAttributes.Size2D == null)
+ if (Style.Thumb.Size == null)
{
return;
}
else
{
- thumbW = scrollBarAttrs.ThumbImageAttributes.Size2D.Width;
- thumbH = scrollBarAttrs.ThumbImageAttributes.Size2D.Height;
+ thumbW = Style.Thumb.Size.Width;
+ thumbH = Style.Thumb.Size.Height;
}
float ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
- if (scrollBarAttrs.Direction == DirectionType.Horizontal)
+ if (Style.Direction == DirectionType.Horizontal)
{
if (LayoutDirection == ViewLayoutDirectionType.RTL)
{
float posY = (height - thumbH) / 2.0f;
thumbImagePosX = posX;
- if (scrollAniPlayer != null)
+ if (null != scrollAniPlayer)
{
scrollAniPlayer.Stop();
}
}
else
{
- if (scrollAniPlayer != null)
+ if (null != scrollAniPlayer)
{
scrollAniPlayer.Clear();
scrollAniPlayer.AnimateTo(thumbImage, "PositionX", posX);
float posY = ratio * (height - thumbH);
thumbImagePosY = posY;
- if (scrollAniPlayer != null)
+ if (null != scrollAniPlayer)
{
scrollAniPlayer.Stop();
}
}
else
{
- if (scrollAniPlayer != null)
+ if (null != scrollAniPlayer)
{
scrollAniPlayer.Clear();
scrollAniPlayer.AnimateTo(thumbImage, "PositionY", posY);
}
}
}
+
+ if (enableAni) enableAni = false;
}
private DirectionType CurrentDirection()
{
DirectionType dir = DirectionType.Horizontal;
- if (scrollBarAttrs != null)
+ if (null != Style.Direction)
{
- if (scrollBarAttrs.Direction != null)
- {
- dir = scrollBarAttrs.Direction.Value;
- }
+ dir = Style.Direction.Value;
}
return dir;
}
}
}
- return (int)curValue;
+ return curValue;
}
}
}