using System;
using Tizen.NUI.BaseComponents;
using System.ComponentModel;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.Components
{
/// <since_tizen> 6 </since_tizen>
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("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("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("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("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("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)newValue;
+ }
+ }
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var instance = (ScrollBar)bindable;
+ return instance.Style.Duration;
+ });
+
private ImageView trackImage;
private ImageView thumbImage;
private Animation scrollAniPlayer = null;
private int curValue;
/// <summary>
- /// The constructor of ScrollBar
+ /// The constructor of ScrollBar.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public ScrollBar() : base()
}
/// <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();
}
}
#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.
{
get
{
- return scrollBarAttrs.Direction.Value;
+ return (DirectionType)GetValue(DirectionProperty);
}
set
{
- scrollBarAttrs.Direction = value;
- RelayoutRequest();
+ SetValue(DirectionProperty, value);
}
}
{
get
{
- if (scrollBarAttrs.ThumbImageAttributes.Size == null)
+ if (Style.Thumb.Size == null)
{
- scrollBarAttrs.ThumbImageAttributes.Size = new Size();
+ Style.Thumb.Size = new Size();
}
- return scrollBarAttrs.ThumbImageAttributes.Size;
+ return Style.Thumb.Size;
}
set
{
- if (scrollBarAttrs.ThumbImageAttributes.Size == null)
+ if (Style.Thumb.Size == null)
{
- scrollBarAttrs.ThumbImageAttributes.Size = new Size();
+ Style.Thumb.Size = new Size();
}
if (thumbImage != null)
{
- scrollBarAttrs.ThumbImageAttributes.Size.Width = value.Width;
- scrollBarAttrs.ThumbImageAttributes.Size.Height = value.Height;
+ Style.Thumb.Size.Width = value.Width;
+ Style.Thumb.Size.Height = value.Height;
RelayoutRequest();
}
}
{
get
{
- return scrollBarAttrs.TrackImageAttributes.ResourceURL.All;
+ return Style.Track.ResourceUrl.All;
}
set
{
if (trackImage != null)
{
- if (scrollBarAttrs.TrackImageAttributes.ResourceURL == null)
+ if (Style.Track.ResourceUrl == null)
{
- scrollBarAttrs.TrackImageAttributes.ResourceURL = new StringSelector();
+ Style.Track.ResourceUrl = new StringSelector();
}
- scrollBarAttrs.TrackImageAttributes.ResourceURL.All = value;
+ Style.Track.ResourceUrl.All = value;
}
RelayoutRequest();
}
{
get
{
- return scrollBarAttrs.TrackImageAttributes.BackgroundColor?.All;
+ return Style.Track.BackgroundColor?.All;
}
set
{
- if (scrollBarAttrs.TrackImageAttributes.BackgroundColor == null)
+ if (Style.Track.BackgroundColor == null)
{
- scrollBarAttrs.TrackImageAttributes.BackgroundColor = new ColorSelector { All = value };
+ Style.Track.BackgroundColor = new ColorSelector { All = value };
}
else
{
- scrollBarAttrs.TrackImageAttributes.BackgroundColor.All = value;
+ Style.Track.BackgroundColor.All = value;
}
RelayoutRequest();
}
{
get
{
- return scrollBarAttrs.ThumbImageAttributes.BackgroundColor?.All;
+ return Style.Thumb.BackgroundColor?.All;
}
set
{
- if(scrollBarAttrs.ThumbImageAttributes.BackgroundColor == null)
+ if(Style.Thumb.BackgroundColor == null)
{
- scrollBarAttrs.ThumbImageAttributes.BackgroundColor = new ColorSelector { All = value };
+ Style.Thumb.BackgroundColor = new ColorSelector { All = value };
}
else
{
- scrollBarAttrs.ThumbImageAttributes.BackgroundColor.All = value;
+ Style.Thumb.BackgroundColor.All = value;
}
RelayoutRequest();
}
{
get
{
- return maxValue;
+ return (int)GetValue(MaxValueProperty);
}
set
{
- if(value >= 0)
- {
- maxValue = value;
- RelayoutRequest();
- }
+ SetValue(MaxValueProperty, value);
}
}
{
get
{
- return minValue;
+ return (int)GetValue(MinValueProperty);
}
set
{
- if(value >= 0)
- {
- minValue = value;
- RelayoutRequest();
- }
+ SetValue(MinValueProperty, value);
}
}
{
get
{
- return curValue;
+ return (int)GetValue(CurrentValueProperty);
}
set
{
- if(value >= 0)
- {
- curValue = value;
- RelayoutRequest();
- }
+ SetValue(CurrentValueProperty, value);
}
}
{
get
{
- return scrollBarAttrs.Duration;
+ return (uint)GetValue(DurationProperty);
}
set
{
- scrollBarAttrs.Duration = value;
- if (scrollAniPlayer != null)
- {
- scrollAniPlayer.Duration = (int)value;
- }
+ SetValue(DurationProperty, value);
}
}
#endregion
/// </code>
/// </example>
/// <since_tizen> 6 </since_tizen>
- public void SetCurrentValue(int currentValue, bool EnableAnimation = true)
+ public void SetCurrentValue(int currentValue, bool enableAnimation = true)
{
if (currentValue < minValue || currentValue > maxValue)
{
throw new ArgumentOutOfRangeException("Wrong Current value. It shoud be greater than the Min value, and less than the Max value!");
}
- enableAni = EnableAnimation;
+ enableAni = enableAnimation;
CurrentValue = currentValue;
}
//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.GetAttributes(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.Size == null)
+ if (Style.Thumb.Size == null)
{
return;
}
else
{
- thumbW = scrollBarAttrs.ThumbImageAttributes.Size.Width;
- thumbH = scrollBarAttrs.ThumbImageAttributes.Size.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;
}
}
}