From 493888d7f1c6d343d9f43f8888c6be33c9455286 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 24 Oct 2017 23:22:19 +0900 Subject: [PATCH] [ElmSharp*] Add Scrollable interface Implement Scroll to Entry, GenGrid, GenList, List, Panel, Toolbar. Fix NaviItem Style to override. Change-Id: I2349a272359eba6f00c23cbf470786876e3500f8 --- .../ElmSharp.Wearable/CircleGenList.cs | 3 +- src/ElmSharp/ElmSharp/Entry.cs | 478 ++++++++++++++++---- src/ElmSharp/ElmSharp/GenGrid.cs | 433 ++++++++++++++++-- src/ElmSharp/ElmSharp/GenList.cs | 390 +++++++++++++++- src/ElmSharp/ElmSharp/IScrollable.cs | 334 ++++++++++++++ src/ElmSharp/ElmSharp/List.cs | 390 +++++++++++++++- src/ElmSharp/ElmSharp/Panel.cs | 389 +++++++++++++++- src/ElmSharp/ElmSharp/ScrollableAdapter.cs | 270 ++++++++++++ src/ElmSharp/ElmSharp/Scroller.cs | 490 ++++----------------- src/ElmSharp/ElmSharp/Toolbar.cs | 390 +++++++++++++++- 10 files changed, 3020 insertions(+), 547 deletions(-) create mode 100644 src/ElmSharp/ElmSharp/IScrollable.cs create mode 100644 src/ElmSharp/ElmSharp/ScrollableAdapter.cs diff --git a/src/ElmSharp.Wearable/ElmSharp.Wearable/CircleGenList.cs b/src/ElmSharp.Wearable/ElmSharp.Wearable/CircleGenList.cs index 7dc18e1..f465547 100644 --- a/src/ElmSharp.Wearable/ElmSharp.Wearable/CircleGenList.cs +++ b/src/ElmSharp.Wearable/ElmSharp.Wearable/CircleGenList.cs @@ -189,7 +189,7 @@ namespace ElmSharp.Wearable /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. /// - public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy { get { @@ -199,6 +199,7 @@ namespace ElmSharp.Wearable } set { + base.VerticalScrollBarVisiblePolicy = value; int h; Interop.Eext.eext_circle_object_genlist_scroller_policy_get(CircleHandle, out h, IntPtr.Zero); Interop.Eext.eext_circle_object_genlist_scroller_policy_set(CircleHandle, (int)h, (int)value); diff --git a/src/ElmSharp/ElmSharp/Entry.cs b/src/ElmSharp/ElmSharp/Entry.cs index 92f57b5..3929a9a 100755 --- a/src/ElmSharp/ElmSharp/Entry.cs +++ b/src/ElmSharp/ElmSharp/Entry.cs @@ -250,8 +250,9 @@ namespace ElmSharp /// /// The entry is a convenience widget that shows a box in which the user can enter text. /// - public class Entry : Layout + public class Entry : Layout, IScrollable { + ScrollableAdapter _scroller; SmartEvent _clicked; SmartEvent _changedByUser; SmartEvent _cursorChanged; @@ -277,6 +278,8 @@ namespace ElmSharp _activated = new SmartEvent(this, this.RealHandle, "activated"); _activated.On += (s, e) => Activated?.Invoke(this, EventArgs.Empty); + + _scroller = new ScrollableAdapter(this); } /// @@ -788,94 +791,6 @@ namespace ElmSharp } /// - /// Sets or gets the value of HorizontalScrollBarVisiblePolicy - /// - /// - /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. - /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. - /// - public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy - { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v); - } - } - - /// - /// Sets or gets the value of VerticalScrollBarVisiblePolicy - /// - /// - /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. - /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. - /// - public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy - { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value); - } - } - - /// - /// Sets or gets the vertical bounce behaviour. - /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. - /// This is a visual way to indicate the end has been reached. - /// This is enabled by default for both axis. - /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. - /// - public bool VerticalBounce - { - get - { - bool v, h; - Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); - return v; - } - set - { - bool h = HorizontalBounce; - Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value); - } - } - - /// - /// Sets or gets the horizontal bounce behaviour. - /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. - /// This is a visual way to indicate the end has been reached. - /// This is enabled by default for both axis. - /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. - /// - public bool HorizontalBounce - { - get - { - bool v, h; - Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); - return h; - } - set - { - bool v = VerticalBounce; - Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v); - } - } - - /// /// Inserts the given text into the entry at the current cursor position. /// /// @@ -1114,5 +1029,390 @@ namespace ElmSharp { return Interop.Elementary.elm_entry_add(parent.Handle); } + + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion } } \ No newline at end of file diff --git a/src/ElmSharp/ElmSharp/GenGrid.cs b/src/ElmSharp/ElmSharp/GenGrid.cs index 146112b..c27ef52 100755 --- a/src/ElmSharp/ElmSharp/GenGrid.cs +++ b/src/ElmSharp/ElmSharp/GenGrid.cs @@ -44,8 +44,9 @@ namespace ElmSharp /// It has two direction in which a given GenGrid widget expands while placing its items, horizontal and vertical. /// The GenGrid items are represented through definition field details. /// - public class GenGrid : Layout + public class GenGrid : Layout, IScrollable { + ScrollableAdapter _scroller; HashSet _children = new HashSet(); SmartEvent _selected; @@ -66,6 +67,7 @@ namespace ElmSharp public GenGrid(EvasObject parent) : base(parent) { InitializeSmartEvent(); + _scroller = new ScrollableAdapter(this); } /// @@ -291,50 +293,6 @@ namespace ElmSharp } /// - /// Sets or gets the value of HorizontalScrollBarVisiblePolicy - /// - /// - /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. - /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. - /// - public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy - { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v); - } - } - - /// - /// Sets or gets the value of VerticalScrollBarVisiblePolicy - /// - /// - /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. - /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. - /// - public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy - { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value); - } - } - - /// /// Gets the first item in a given gengrid widget. /// public GenGridItem FirstItem @@ -572,6 +530,391 @@ namespace ElmSharp return handle; } + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion + void InitializeSmartEvent() { _selected = new SmartEvent(this, this.RealHandle, "selected", GenGridItemEventArgs.CreateFromSmartEvent); diff --git a/src/ElmSharp/ElmSharp/GenList.cs b/src/ElmSharp/ElmSharp/GenList.cs index 600c57b..c8c2c45 100755 --- a/src/ElmSharp/ElmSharp/GenList.cs +++ b/src/ElmSharp/ElmSharp/GenList.cs @@ -128,8 +128,9 @@ namespace ElmSharp /// But the price to pay is more complexity when it comes to usage. /// If all you want is a simple list with icons and a single text, use the widget. /// - public class GenList : Layout + public class GenList : Layout, IScrollable { + ScrollableAdapter _scroller; HashSet _children = new HashSet(); SmartEvent _selected; @@ -750,9 +751,396 @@ namespace ElmSharp RealHandle = Interop.Elementary.elm_genlist_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); + _scroller = new ScrollableAdapter(this); + return handle; } + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion + void InitializeSmartEvent() { _selected = new SmartEvent(this, this.RealHandle, "selected", GenListItemEventArgs.CreateFromSmartEvent); diff --git a/src/ElmSharp/ElmSharp/IScrollable.cs b/src/ElmSharp/ElmSharp/IScrollable.cs new file mode 100644 index 0000000..d4e9e9f --- /dev/null +++ b/src/ElmSharp/ElmSharp/IScrollable.cs @@ -0,0 +1,334 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ElmSharp +{ + /// + /// Interface for all other scrollable widgets + /// + public interface IScrollable + { + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + event EventHandler Scrolled; + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + event EventHandler DragStart; + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + event EventHandler DragStop; + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + event EventHandler PageScrolled; + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + double VerticalGravity { get; set; } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + double HorizontalGravity { get; set; } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + bool VerticalBounce { get; set; } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + bool HorizontalBounce { get; set; } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + bool WheelDisabled { get; set; } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + ScrollBlock ScrollBlock { get; set; } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy { get; set; } + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy { get; set; } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + Rect CurrentRegion { get; } + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + int VerticalPageScrollLimit { get; set; } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + int HorizontalPageScrollLimit { get; set; } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + int HorizontalPageSize { get; set; } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + int VerticalPageSize { get; set; } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + bool VerticalSnap { get; set; } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + bool HorizontalSnap { get; set; } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + int PageHeight { get; set; } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + int PageWidth { get; set; } + + /// + /// Gets or sets the type of single direction scroll. + /// + ScrollSingleDirection SingleDirection { get; set; } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + int HorizontalStepSize { get; set; } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + int VerticalStepSize { get; set; } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + bool VerticalLoop { get; set; } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + bool HorizontalLoop { get; set; } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + double VerticalRelativePageSize { get; set; } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + double HorizontalRelativePageSize { get; set; } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + int LastVerticalPageNumber { get; } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + int LastHorizontalPageNumber { get; } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + int VerticalPageIndex { get; } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + int HorizontalPageIndex { get; } + + /// + /// Gets the width of the content object of the scroller. + /// + int ChildWidth { get; } + + /// + /// Gets the height of the content object of the scroller. + /// + int ChildHeight { get; } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + void MinimumLimit(bool horizontal, bool vertical); + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated); + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + void ScrollTo(Rect region, bool animated); + } + + /// + /// Enumeration for visible type of scrollbar. + /// + public enum ScrollBarVisiblePolicy + { + /// + /// Show scrollbars as needed + /// + Auto = 0, + + /// + /// Always show scrollbars + /// + Visible, + + /// + /// Never show scrollbars + /// + Invisible + } + + /// + /// Enumeration for visible type of scrollbar. + /// + public enum ScrollBlock + { + /// + /// Scrolling movement is allowed in both direction.(X axis and Y axis) + /// + None = 1, + + /// + /// Scrolling movement is not allowed in Y axis direction. + /// + Vertical = 2, + + /// + /// Scrolling movement is not allowed in X axis direction. + /// + Horizontal = 4 + } + + /// + /// Type that controls how the content is scrolled. + /// + public enum ScrollSingleDirection + { + /// + /// Scroll every direction. + /// + None, + + /// + /// Scroll single direction if the direction is certain. + /// + Soft, + + /// + /// Scroll only single direction. + /// + Hard, + } +} diff --git a/src/ElmSharp/ElmSharp/List.cs b/src/ElmSharp/ElmSharp/List.cs index 59eec69..a8f2bc9 100755 --- a/src/ElmSharp/ElmSharp/List.cs +++ b/src/ElmSharp/ElmSharp/List.cs @@ -73,8 +73,9 @@ namespace ElmSharp /// /// /// - public class List : Layout + public class List : Layout, IScrollable { + ScrollableAdapter _scroller; HashSet _children = new HashSet(); SmartEvent _selected; SmartEvent _unselected; @@ -241,9 +242,396 @@ namespace ElmSharp RealHandle = Interop.Elementary.elm_list_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); + _scroller = new ScrollableAdapter(this); + return handle; } + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion + void AddInternal(ListItem item) { _children.Add(item); diff --git a/src/ElmSharp/ElmSharp/Panel.cs b/src/ElmSharp/ElmSharp/Panel.cs index f34cde3..b2270d8 100755 --- a/src/ElmSharp/ElmSharp/Panel.cs +++ b/src/ElmSharp/ElmSharp/Panel.cs @@ -44,8 +44,9 @@ namespace ElmSharp /// /// The Panel is a container that can contain subobjects. /// - public class Panel : Layout + public class Panel : Layout, IScrollable { + ScrollableAdapter _scroller; SmartEvent _toggled; /// @@ -56,6 +57,7 @@ namespace ElmSharp { _toggled = new SmartEvent(this, this.RealHandle, "toggled"); _toggled.On += (s, e) => Toggled?.Invoke(this, EventArgs.Empty); + _scroller = new ScrollableAdapter(this); } /// @@ -138,5 +140,390 @@ namespace ElmSharp return handle; } + + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion } } diff --git a/src/ElmSharp/ElmSharp/ScrollableAdapter.cs b/src/ElmSharp/ElmSharp/ScrollableAdapter.cs new file mode 100644 index 0000000..4f85d2a --- /dev/null +++ b/src/ElmSharp/ElmSharp/ScrollableAdapter.cs @@ -0,0 +1,270 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using static Interop.Elementary; + +namespace ElmSharp +{ + class ScrollableAdapter : IScrollable + { + EvasObject obj; + SmartEvent _scroll; + SmartEvent _dragStart; + SmartEvent _dragStop; + SmartEvent _scrollPage; + + public ScrollableAdapter(List list) : this(list as EvasObject) + { + } + + public ScrollableAdapter(Entry entry) : this(entry as EvasObject) + { + } + + public ScrollableAdapter(Panel panel) : this(panel as EvasObject) + { + } + + public ScrollableAdapter(GenGrid gengrid) : this(gengrid as EvasObject) + { + } + + public ScrollableAdapter(Scroller scroller) : this(scroller as EvasObject) + { + } + + public ScrollableAdapter(GenList genlist) : this(genlist as EvasObject) + { + } + + public ScrollableAdapter(Toolbar toolbar) : this(toolbar as EvasObject) + { + } + + ScrollableAdapter(EvasObject scrollable) + { + obj = scrollable; + _scroll = new SmartEvent(obj, obj.RealHandle, "scroll"); + _dragStart = new SmartEvent(obj, obj.RealHandle, "scroll,drag,start"); + _dragStop = new SmartEvent(obj, obj.RealHandle, "scroll,drag,stop"); + _scrollPage = new SmartEvent(obj, obj.RealHandle, "scroll,page,changed"); + } + + public event EventHandler Scrolled + { + add => _scroll.On += value; + remove => _scroll.On -= value; + } + public event EventHandler DragStart + { + add => _dragStart.On += value; + remove => _dragStart.On -= value; + } + public event EventHandler DragStop + { + add => _dragStop.On += value; + remove => _dragStop.On -= value; + } + public event EventHandler PageScrolled + { + add => _scrollPage.On += value; + remove => _scrollPage.On -= value; + } + + public double VerticalGravity + { + get => Get2(elm_scroller_gravity_get); + set => Set(elm_scroller_gravity_set, HorizontalGravity, value); + } + public double HorizontalGravity + { + get => Get1(elm_scroller_gravity_get); + set => Set(elm_scroller_gravity_set, value, VerticalGravity); + } + public bool VerticalBounce + { + get => Get2(elm_scroller_bounce_get); + set => Set(elm_scroller_bounce_set, HorizontalBounce, value); + } + public bool HorizontalBounce + { + get => Get1(elm_scroller_bounce_get); + set => Set(elm_scroller_bounce_set, value, VerticalBounce); + } + public bool WheelDisabled + { + get => Get(elm_scroller_wheel_disabled_get); + set => Set(elm_scroller_wheel_disabled_set, value); + } + public ScrollBlock ScrollBlock + { + get => (ScrollBlock)Get(elm_scroller_movement_block_get); + set => Set(elm_scroller_movement_block_set, (int)value); + } + public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => (ScrollBarVisiblePolicy)Get2(elm_scroller_policy_get); + set => Set(elm_scroller_policy_set, (int)HorizontalScrollBarVisiblePolicy, (int)value); + } + public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => (ScrollBarVisiblePolicy)Get1(elm_scroller_policy_get); + set => Set(elm_scroller_policy_set, (int)value, (int)VerticalScrollBarVisiblePolicy); + } + + public Rect CurrentRegion + { + get + { + int x, y, w, h; + elm_scroller_region_get(obj.RealHandle, out x, out y, out w, out h); + return new Rect(x, y, w, h); + } + } + + public int VerticalPageScrollLimit + { + get => Get2(elm_scroller_page_scroll_limit_get); + set => Set(elm_scroller_page_scroll_limit_set, HorizontalPageScrollLimit, value); + } + public int HorizontalPageScrollLimit + { + get => Get1(elm_scroller_page_scroll_limit_get); + set => Set(elm_scroller_page_scroll_limit_set, value, VerticalPageScrollLimit); + } + + public int HorizontalPageSize + { + get => Get1(elm_scroller_page_size_get); + set => Set(elm_scroller_page_size_set, value, VerticalPageSize); + } + + public int VerticalPageSize + { + get => Get2(elm_scroller_page_size_get); + set => Set(elm_scroller_page_size_set, HorizontalPageSize, value); + } + + public bool VerticalSnap + { + get => Get2(elm_scroller_page_snap_get); + set => Set(elm_scroller_page_snap_set, HorizontalSnap, value); + } + public bool HorizontalSnap + { + get => Get1(elm_scroller_page_snap_get); + set => Set(elm_scroller_page_snap_set, value, VerticalSnap); + } + public int PageHeight + { + get => Get2(elm_scroller_page_size_get); + set => Set(elm_scroller_page_size_set, PageWidth, value); + } + public int PageWidth + { + get => Get1(elm_scroller_page_size_get); + set => Set(elm_scroller_page_size_set, value, PageHeight); + } + public ScrollSingleDirection SingleDirection + { + get => (ScrollSingleDirection)elm_scroller_single_direction_get(obj.RealHandle); + set => Set(elm_scroller_single_direction_set, (int)value); + } + public int HorizontalStepSize + { + get => Get1(elm_scroller_step_size_get); + set => Set(elm_scroller_step_size_set, value, VerticalStepSize); + } + public int VerticalStepSize + { + get => Get2(elm_scroller_step_size_get); + set => Set(elm_scroller_step_size_set, HorizontalStepSize, value); + } + public bool VerticalLoop + { + get => Get2(elm_scroller_loop_get); + set => Set(elm_scroller_loop_set, HorizontalLoop, value); + } + public bool HorizontalLoop + { + get => Get1(elm_scroller_loop_get); + set => Set(elm_scroller_loop_set, value, VerticalLoop); + } + public double VerticalRelativePageSize + { + get => Get2(elm_scroller_page_relative_get); + set => Set(elm_scroller_page_relative_set, HorizontalRelativePageSize, value); + } + public double HorizontalRelativePageSize + { + get => Get1(elm_scroller_page_relative_get); + set => Set(elm_scroller_page_relative_set, value, VerticalRelativePageSize); + } + + public int LastVerticalPageNumber => Get2(elm_scroller_last_page_get); + + public int LastHorizontalPageNumber => Get1(elm_scroller_last_page_get); + + public int VerticalPageIndex => Get2(elm_scroller_current_page_get); + + public int HorizontalPageIndex => Get1(elm_scroller_current_page_get); + + public int ChildWidth => Get1(elm_scroller_child_size_get); + + public int ChildHeight => Get2(elm_scroller_child_size_get); + + public void MinimumLimit(bool horizontal, bool vertical) + { + Set(elm_scroller_content_min_limit, horizontal, vertical); + } + + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + if (animated) + { + Set(elm_scroller_page_bring_in, horizontalPageIndex, verticalPageIndex); + } + else + { + Set(elm_scroller_page_show, horizontalPageIndex, verticalPageIndex); + } + } + + public void ScrollTo(Rect region, bool animated) + { + if (animated) + { + elm_scroller_region_bring_in(obj.RealHandle, region.X, region.Y, region.Width, region.Height); + } + else + { + elm_scroller_region_show(obj.RealHandle, region.X, region.Y, region.Width, region.Height); + } + } + + delegate T Getter(IntPtr handle); + delegate void Setter(IntPtr handle, T v); + delegate void DoubleGetter(IntPtr handle, out T v1, out T v2); + delegate void DoubleSetter(IntPtr handle, T v1, T v2); + + T Get(Getter func) => func(obj.RealHandle); + void Set(Setter func, T value) => func(obj.RealHandle, value); + + T Get1(DoubleGetter func) + { + T v1, v2; + func(obj.RealHandle, out v1, out v2); + return v1; + } + + T Get2(DoubleGetter func) + { + T v1, v2; + func(obj.RealHandle, out v1, out v2); + return v2; + } + + void Set(DoubleSetter func, T v1, T v2) => func(obj.RealHandle, v1, v2); + } +} diff --git a/src/ElmSharp/ElmSharp/Scroller.cs b/src/ElmSharp/ElmSharp/Scroller.cs index a6063a7..926b68f 100755 --- a/src/ElmSharp/ElmSharp/Scroller.cs +++ b/src/ElmSharp/ElmSharp/Scroller.cs @@ -19,77 +19,11 @@ using System; namespace ElmSharp { /// - /// Enumeration for visible type of scrollbar. - /// - public enum ScrollBarVisiblePolicy - { - /// - /// Show scrollbars as needed - /// - Auto = 0, - - /// - /// Always show scrollbars - /// - Visible, - - /// - /// Never show scrollbars - /// - Invisible - } - - /// - /// Enumeration for visible type of scrollbar. - /// - public enum ScrollBlock - { - /// - /// Scrolling movement is allowed in both direction.(X axis and Y axis) - /// - None = 1, - - /// - /// Scrolling movement is not allowed in Y axis direction. - /// - Vertical = 2, - - /// - /// Scrolling movement is not allowed in X axis direction. - /// - Horizontal = 4 - } - - /// - /// Type that controls how the content is scrolled. - /// - public enum ScrollSingleDirection - { - /// - /// Scroll every direction. - /// - None, - - /// - /// Scroll single direction if the direction is certain. - /// - Soft, - - /// - /// Scroll only single direction. - /// - Hard, - } - - /// /// The Scroller is a container that holds and clips a single object and allows you to scroll across it. /// - public class Scroller : Layout + public class Scroller : Layout, IScrollable { - SmartEvent _scroll; - SmartEvent _dragStart; - SmartEvent _dragStop; - SmartEvent _scrollpage; + ScrollableAdapter _adapter; /// /// Creates and initializes a new instance of the Scroller class. @@ -111,14 +45,8 @@ namespace ElmSharp /// public event EventHandler Scrolled { - add - { - _scroll.On += value; - } - remove - { - _scroll.On -= value; - } + add => _adapter.Scrolled += value; + remove => _adapter.Scrolled -= value; } /// @@ -126,14 +54,8 @@ namespace ElmSharp /// public event EventHandler DragStart { - add - { - _dragStart.On += value; - } - remove - { - _dragStart.On -= value; - } + add => _adapter.DragStart += value; + remove => _adapter.DragStart -= value; } /// @@ -141,14 +63,8 @@ namespace ElmSharp /// public event EventHandler DragStop { - add - { - _dragStop.On += value; - } - remove - { - _dragStop.On -= value; - } + add => _adapter.DragStop += value; + remove => _adapter.DragStop -= value; } /// @@ -156,28 +72,14 @@ namespace ElmSharp /// public event EventHandler PageScrolled { - add - { - _scrollpage.On += value; - } - remove - { - _scrollpage.On -= value; - } + add => _adapter.PageScrolled += value; + remove => _adapter.PageScrolled -= value; } /// /// Gets the current region in the content object that is visible through the Scroller. /// - public Rect CurrentRegion - { - get - { - int x, y, w, h; - Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h); - return new Rect(x, y, w, h); - } - } + public Rect CurrentRegion => _adapter.CurrentRegion; /// /// Sets or gets the value of HorizontalScrollBarVisiblePolicy @@ -188,17 +90,8 @@ namespace ElmSharp /// public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v); - } + get => _adapter.HorizontalScrollBarVisiblePolicy; + set => _adapter.HorizontalScrollBarVisiblePolicy = value; } /// @@ -210,17 +103,8 @@ namespace ElmSharp /// public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy { - get - { - int policy; - Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy); - return (ScrollBarVisiblePolicy)policy; - } - set - { - ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy; - Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value); - } + get => _adapter.VerticalScrollBarVisiblePolicy; + set => _adapter.VerticalScrollBarVisiblePolicy = value; } /// @@ -232,14 +116,8 @@ namespace ElmSharp /// public ScrollBlock ScrollBlock { - get - { - return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle); - } - set - { - Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value); - } + get => _adapter.ScrollBlock; + set => _adapter.ScrollBlock = value; } /// @@ -250,15 +128,7 @@ namespace ElmSharp /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. /// The page number starts from 0. 0 is the first page. /// - public int VerticalPageIndex - { - get - { - int v, h; - Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v); - return v; - } - } + public int VerticalPageIndex => _adapter.VerticalPageIndex; /// /// Sets or gets scroll current page number. @@ -268,32 +138,15 @@ namespace ElmSharp /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. /// The page number starts from 0. 0 is the first page. /// - public int HorizontalPageIndex - { - get - { - int v, h; - Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v); - return h; - } - } + public int HorizontalPageIndex => _adapter.HorizontalPageIndex; /// /// Sets or gets the maximum limit of the movable page at vertical direction. /// public int VerticalPageScrollLimit { - get - { - int v, h; - Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v); - return v; - } - set - { - int h = HorizontalPageScrollLimit; - Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value); - } + get => _adapter.VerticalPageScrollLimit; + set => _adapter.VerticalPageScrollLimit = value; } /// @@ -301,17 +154,8 @@ namespace ElmSharp /// public int HorizontalPageScrollLimit { - get - { - int v, h; - Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v); - return h; - } - set - { - int v = VerticalPageScrollLimit; - Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v); - } + get => _adapter.HorizontalPageScrollLimit; + set => _adapter.HorizontalPageScrollLimit = value; } /// @@ -323,17 +167,8 @@ namespace ElmSharp /// public bool VerticalBounce { - get - { - bool v, h; - Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); - return v; - } - set - { - bool h = HorizontalBounce; - Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value); - } + get => _adapter.VerticalBounce; + set => _adapter.VerticalBounce = value; } /// @@ -345,17 +180,8 @@ namespace ElmSharp /// public bool HorizontalBounce { - get - { - bool v, h; - Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); - return h; - } - set - { - bool v = VerticalBounce; - Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v); - } + get => _adapter.HorizontalBounce; + set => _adapter.HorizontalBounce = value; } /// @@ -363,12 +189,7 @@ namespace ElmSharp /// public int ChildWidth { - get - { - int w, h; - Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h); - return w; - } + get => _adapter.ChildWidth; } /// @@ -376,12 +197,7 @@ namespace ElmSharp /// public int ChildHeight { - get - { - int w, h; - Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h); - return h; - } + get => _adapter.ChildHeight; } /// @@ -393,17 +209,8 @@ namespace ElmSharp /// public double HorizontalGravity { - get - { - double v, h; - Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v); - return h; - } - set - { - double v = VerticalGravity; - Interop.Elementary.elm_scroller_gravity_set(RealHandle, value, v); - } + get => _adapter.HorizontalGravity; + set => _adapter.HorizontalGravity = value; } /// @@ -415,46 +222,21 @@ namespace ElmSharp /// public double VerticalGravity { - get - { - double v, h; - Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v); - return v; - } - set - { - double h = HorizontalGravity; - Interop.Elementary.elm_scroller_gravity_set(RealHandle, h, value); - } + get => _adapter.VerticalGravity; + set => _adapter.VerticalGravity = value; } /// /// Get scroll last page number. /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. /// - public int LastVerticalPageNumber - { - get - { - int v, h; - Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v); - return v; - } - } + public int LastVerticalPageNumber => _adapter.LastVerticalPageNumber; /// /// Get scroll last page number. /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. /// - public int LastHorizontalPageNumber - { - get - { - int v, h; - Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v); - return h; - } - } + public int LastHorizontalPageNumber => _adapter.LastHorizontalPageNumber; /// /// Set an infinite loop_ for a scroller. @@ -463,17 +245,8 @@ namespace ElmSharp /// public bool VerticalLoop { - get - { - bool v, h; - Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v); - return v; - } - set - { - bool h = HorizontalLoop; - Interop.Elementary.elm_scroller_loop_set(RealHandle, h, value); - } + get => _adapter.VerticalLoop; + set => _adapter.VerticalLoop = value; } /// @@ -483,17 +256,26 @@ namespace ElmSharp /// public bool HorizontalLoop { - get - { - bool v, h; - Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v); - return h; - } - set - { - bool v = VerticalLoop; - Interop.Elementary.elm_scroller_loop_set(RealHandle, value, v); - } + get => _adapter.HorizontalLoop; + set => _adapter.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _adapter.HorizontalPageSize; + set => _adapter.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _adapter.VerticalPageSize; + set => _adapter.VerticalPageSize = value; } /// @@ -501,17 +283,8 @@ namespace ElmSharp /// public double VerticalRelativePageSize { - get - { - double v, h; - Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v); - return v; - } - set - { - double h = HorizontalRelativePageSize; - Interop.Elementary.elm_scroller_page_relative_set(RealHandle, h, value); - } + get => _adapter.VerticalRelativePageSize; + set => _adapter.VerticalRelativePageSize = value; } /// @@ -519,17 +292,8 @@ namespace ElmSharp /// public double HorizontalRelativePageSize { - get - { - double v, h; - Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v); - return h; - } - set - { - double v = VerticalRelativePageSize; - Interop.Elementary.elm_scroller_page_relative_set(RealHandle, value, v); - } + get => _adapter.HorizontalRelativePageSize; + set => _adapter.HorizontalRelativePageSize = value; } /// @@ -543,17 +307,8 @@ namespace ElmSharp /// public bool VerticalSnap { - get - { - bool v, h; - Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v); - return v; - } - set - { - bool h = HorizontalSnap; - Interop.Elementary.elm_scroller_page_snap_set(RealHandle, h, value); - } + get => _adapter.VerticalSnap; + set => _adapter.VerticalSnap = value; } /// @@ -567,17 +322,8 @@ namespace ElmSharp /// public bool HorizontalSnap { - get - { - bool v, h; - Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v); - return h; - } - set - { - bool v = VerticalSnap; - Interop.Elementary.elm_scroller_page_snap_set(RealHandle, value, v); - } + get => _adapter.HorizontalSnap; + set => _adapter.HorizontalSnap = value; } /// @@ -585,17 +331,8 @@ namespace ElmSharp /// public int PageHeight { - get - { - int w, h; - Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h); - return h; - } - set - { - int w = PageWidth; - Interop.Elementary.elm_scroller_page_size_set(RealHandle, w, value); - } + get => _adapter.PageHeight; + set => _adapter.PageHeight = value; } /// @@ -603,17 +340,8 @@ namespace ElmSharp /// public int PageWidth { - get - { - int w, h; - Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h); - return w; - } - set - { - int h = PageHeight; - Interop.Elementary.elm_scroller_page_size_set(RealHandle, value, h); - } + get => _adapter.PageWidth; + set => _adapter.PageWidth = value; } /// @@ -638,17 +366,8 @@ namespace ElmSharp /// public int HorizontalStepSize { - get - { - int h, v; - Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v); - return h; - } - set - { - int v = VerticalStepSize; - Interop.Elementary.elm_scroller_step_size_set(RealHandle, value, v); - } + get => _adapter.HorizontalStepSize; + set => _adapter.HorizontalStepSize = value; } /// @@ -656,17 +375,8 @@ namespace ElmSharp /// public int VerticalStepSize { - get - { - int h, v; - Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v); - return v; - } - set - { - int h = HorizontalStepSize; - Interop.Elementary.elm_scroller_step_size_set(RealHandle, h, value); - } + get => _adapter.VerticalStepSize; + set => _adapter.VerticalStepSize = value; } /// @@ -674,14 +384,8 @@ namespace ElmSharp /// public bool WheelDisabled { - get - { - return Interop.Elementary.elm_scroller_wheel_disabled_get(RealHandle); - } - set - { - Interop.Elementary.elm_scroller_wheel_disabled_set(RealHandle, value); - } + get => _adapter.WheelDisabled; + set => _adapter.WheelDisabled = value; } /// @@ -689,14 +393,8 @@ namespace ElmSharp /// public ScrollSingleDirection SingleDirection { - get - { - return (ScrollSingleDirection)Interop.Elementary.elm_scroller_single_direction_get(RealHandle); - } - set - { - Interop.Elementary.elm_scroller_single_direction_set(RealHandle, (int)value); - } + get => _adapter.SingleDirection; + set => _adapter.SingleDirection = value; } /// @@ -708,7 +406,7 @@ namespace ElmSharp /// Enable limiting minimum size vertically public void MinimumLimit(bool horizontal, bool vertical) { - Interop.Elementary.elm_scroller_content_min_limit(RealHandle, horizontal, vertical); + _adapter.MinimumLimit(horizontal, vertical); } /// @@ -749,14 +447,7 @@ namespace ElmSharp /// True means slider with animation. public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) { - if (animated) - { - Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex); - } - else - { - Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex); - } + _adapter.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); } /// @@ -773,26 +464,7 @@ namespace ElmSharp /// True means allows the scroller to "smoothly slide" to this location. public void ScrollTo(Rect region, bool animated) { - if (animated) - { - Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height); - } - else - { - Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height); - } - } - - /// - /// The callback of Realized Event - /// - protected override void OnRealized() - { - base.OnRealized(); - _scroll = new SmartEvent(this, this.RealHandle, "scroll"); - _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start"); - _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop"); - _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed"); + _adapter.ScrollTo(region, animated); } /// @@ -808,6 +480,8 @@ namespace ElmSharp RealHandle = Interop.Elementary.elm_scroller_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); + _adapter = new ScrollableAdapter(this); + return handle; } } diff --git a/src/ElmSharp/ElmSharp/Toolbar.cs b/src/ElmSharp/ElmSharp/Toolbar.cs index 49d7178..5b92ca7 100755 --- a/src/ElmSharp/ElmSharp/Toolbar.cs +++ b/src/ElmSharp/ElmSharp/Toolbar.cs @@ -125,8 +125,9 @@ namespace ElmSharp /// /// The Toolbar is a widget that displays a list of items inside a box. /// - public class Toolbar : Widget + public class Toolbar : Widget, IScrollable { + ScrollableAdapter _scroller; SmartEvent _clicked; SmartEvent _selected; SmartEvent _longpressed; @@ -158,6 +159,8 @@ namespace ElmSharp { e.Item?.SendClicked(); }; + + _scroller = new ScrollableAdapter(this); } /// @@ -466,5 +469,390 @@ namespace ElmSharp return handle; } + + #region IScroller Implementation + + /// + /// Scrolled will be triggered when the content has been scrolled. + /// + public event EventHandler Scrolled + { + add => _scroller.Scrolled += value; + remove => _scroller.Scrolled -= value; + } + + /// + /// DragStart will be triggered when dragging the contents around has started. + /// + public event EventHandler DragStart + { + add => _scroller.DragStart += value; + remove => _scroller.DragStart -= value; + } + + /// + /// DragStop will be triggered when dragging the contents around has stopped. + /// + public event EventHandler DragStop + { + add => _scroller.DragStop += value; + remove => _scroller.DragStop -= value; + } + + /// + /// PageScrolled will be triggered when the visible page has changed. + /// + public event EventHandler PageScrolled + { + add => _scroller.PageScrolled += value; + remove => _scroller.PageScrolled -= value; + } + + /// + /// Gets the current region in the content object that is visible through the Scroller. + /// + public Rect CurrentRegion => _scroller.CurrentRegion; + + /// + /// Sets or gets the value of HorizontalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy + { + get => _scroller.HorizontalScrollBarVisiblePolicy; + set => _scroller.HorizontalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of VerticalScrollBarVisiblePolicy + /// + /// + /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden. + /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. + /// + public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy + { + get => _scroller.VerticalScrollBarVisiblePolicy; + set => _scroller.VerticalScrollBarVisiblePolicy = value; + } + + /// + /// Sets or gets the value of ScrollBlock. + /// + /// + /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both. + /// The default value is ScrollBlock.None, where movements are allowed in both directions. + /// + public ScrollBlock ScrollBlock + { + get => _scroller.ScrollBlock; + set => _scroller.ScrollBlock = value; + } + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the top of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int VerticalPageIndex => _scroller.VerticalPageIndex; + + /// + /// Sets or gets scroll current page number. + /// + /// + /// Current page means the page which meets the left of the viewport. + /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport. + /// The page number starts from 0. 0 is the first page. + /// + public int HorizontalPageIndex => _scroller.HorizontalPageIndex; + + /// + /// Sets or gets the maximum limit of the movable page at vertical direction. + /// + public int VerticalPageScrollLimit + { + get => _scroller.VerticalPageScrollLimit; + set => _scroller.VerticalPageScrollLimit = value; + } + + /// + /// Sets or gets the maximum limit of the movable page at horizontal direction. + /// + public int HorizontalPageScrollLimit + { + get => _scroller.HorizontalPageScrollLimit; + set => _scroller.HorizontalPageScrollLimit = value; + } + + /// + /// Sets or gets the vertical bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool VerticalBounce + { + get => _scroller.VerticalBounce; + set => _scroller.VerticalBounce = value; + } + + /// + /// Sets or gets the horizontal bounce behaviour. + /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. + /// This is a visual way to indicate the end has been reached. + /// This is enabled by default for both axis. + /// This API will set if it is enabled for the given axis with the boolean parameters for each axis. + /// + public bool HorizontalBounce + { + get => _scroller.HorizontalBounce; + set => _scroller.HorizontalBounce = value; + } + + /// + /// Gets the width of the content object of the scroller. + /// + public int ChildWidth + { + get => _scroller.ChildWidth; + } + + /// + /// Gets the height of the content object of the scroller. + /// + public int ChildHeight + { + get => _scroller.ChildHeight; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double HorizontalGravity + { + get => _scroller.HorizontalGravity; + set => _scroller.HorizontalGravity = value; + } + + /// + /// Set scrolling gravity values for a scroller. + /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase. + /// The scroller will adjust the view to glue itself as follows. + /// x=0.0, for staying where it is relative to the left edge of the content x=1.0, for staying where it is relative to the rigth edge of the content y=0.0, for staying where it is relative to the top edge of the content y=1.0, for staying where it is relative to the bottom edge of the content + /// Default values for x and y are 0.0 + /// + public double VerticalGravity + { + get => _scroller.VerticalGravity; + set => _scroller.VerticalGravity = value; + } + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber; + + /// + /// Get scroll last page number. + /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages. + /// + public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber; + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop vertically. + /// If the content is set, it will be shown repeatedly. + /// + public bool VerticalLoop + { + get => _scroller.VerticalLoop; + set => _scroller.VerticalLoop = value; + } + + /// + /// Set an infinite loop_ for a scroller. + /// This function sets the infinite loop horizontally. + /// If the content is set, it will be shown repeatedly. + /// + public bool HorizontalLoop + { + get => _scroller.HorizontalLoop; + set => _scroller.HorizontalLoop = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int HorizontalPageSize + { + get => _scroller.HorizontalPageSize; + set => _scroller.HorizontalPageSize = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int VerticalPageSize + { + get => _scroller.VerticalPageSize; + set => _scroller.VerticalPageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double VerticalRelativePageSize + { + get => _scroller.VerticalRelativePageSize; + set => _scroller.VerticalRelativePageSize = value; + } + + /// + /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size. + /// + public double HorizontalRelativePageSize + { + get => _scroller.HorizontalRelativePageSize; + set => _scroller.HorizontalRelativePageSize = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see VerticalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool VerticalSnap + { + get => _scroller.VerticalSnap; + set => _scroller.VerticalSnap = value; + } + + /// + /// Gets or Sets the page snapping behavior of a scroller. + /// + /// + /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize), + /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further, + /// it will stop at the next page boundaries. This is disabled, by default, for both axis. + /// This function will set if it that is enabled or not, for each axis. + /// + public bool HorizontalSnap + { + get => _scroller.HorizontalSnap; + set => _scroller.HorizontalSnap = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageHeight + { + get => _scroller.PageHeight; + set => _scroller.PageHeight = value; + } + + /// + /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis. + /// + public int PageWidth + { + get => _scroller.PageWidth; + set => _scroller.PageWidth = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int HorizontalStepSize + { + get => _scroller.HorizontalStepSize; + set => _scroller.HorizontalStepSize = value; + } + + /// + /// Gets or sets the step size to move scroller by key event. + /// + public int VerticalStepSize + { + get => _scroller.VerticalStepSize; + set => _scroller.VerticalStepSize = value; + } + + /// + /// Gets or sets a value whether mouse wheel is enabled or not over the scroller. + /// + public bool WheelDisabled + { + get => _scroller.WheelDisabled; + set => _scroller.WheelDisabled = value; + } + + /// + /// Gets or sets the type of single direction scroll. + /// + public ScrollSingleDirection SingleDirection + { + get => _scroller.SingleDirection; + set => _scroller.SingleDirection = value; + } + + /// + /// Sets the scroller minimum size limited to the minimum size of the content. + /// By default the scroller will be as small as its design allows, irrespective of its content. + /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction. + /// + /// Enable limiting minimum size horizontally + /// Enable limiting minimum size vertically + public void MinimumLimit(bool horizontal, bool vertical) + { + _scroller.MinimumLimit(horizontal, vertical); + } + + /// + /// Shows a specific virtual region within the scroller content object by the page number. + /// (0, 0) of the indicated page is located at the top-left corner of the viewport. + /// + /// The horizontal page number. + /// The vertical page number. + /// True means slider with animation. + public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated) + { + _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated); + } + + /// + /// Shows a specific virtual region within the scroller content object. + /// + /// + /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0) + /// starting at the top-left of the virtual content object) is shown within the scroller. + /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location + /// (if configuration in general calls for transitions). + /// It may not jump immediately to the new location and may take a while and show other content along the way. + /// + /// Rect struct of region. + /// True means allows the scroller to "smoothly slide" to this location. + public void ScrollTo(Rect region, bool animated) + { + _scroller.ScrollTo(region, animated); + } + + #endregion } } \ No newline at end of file -- 2.7.4