2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /// Enumeration for the visible type of scrollbar.
24 /// <since_tizen> preview </since_tizen>
25 public enum ScrollBarVisiblePolicy
28 /// Show scrollbars as needed.
33 /// Always show scrollbars.
38 /// Never show scrollbars.
44 /// Enumeration for the visible type of scrollbar.
46 /// <since_tizen> preview </since_tizen>
47 public enum ScrollBlock
50 /// Scrolling movement is allowed in both the directions (X-axis and Y-axis).
55 /// Scrolling movement is not allowed in the Y-axis direction.
60 /// Scrolling movement is not allowed in the X-axis direction.
66 /// Type that controls how the content is scrolled.
68 /// <since_tizen> preview </since_tizen>
69 public enum ScrollSingleDirection
72 /// Scroll in every direction.
77 /// Scroll in single direction if the direction is certain.
82 /// Scroll only in a single direction.
88 /// The Scroller is a container that holds and clips a single object and allows you to scroll across it.
90 /// <since_tizen> preview </since_tizen>
91 public class Scroller : Layout
94 SmartEvent _scrollAnimationStart;
95 SmartEvent _scrollAnimationStop;
96 SmartEvent _dragStart;
98 SmartEvent _scrollpage;
101 /// Creates and initializes a new instance of the Scroller class.
103 /// <param name="parent">The <see cref="EvasObject"/> to which the new Scroller will be attached as a child.</param>
104 /// <since_tizen> preview </since_tizen>
105 public Scroller(EvasObject parent) : base(parent)
110 /// Creates and initializes a new instance of the Scroller class.
112 /// <since_tizen> preview </since_tizen>
113 public Scroller() : base()
118 /// Scrolled will be triggered when the content has been scrolled.
120 /// <since_tizen> preview </since_tizen>
121 public event EventHandler Scrolled
134 /// ScrollAnimationStarted will be triggered when the content animation has been started.
136 /// <since_tizen> preview </since_tizen>
137 public event EventHandler ScrollAnimationStarted
141 _scrollAnimationStart.On += value;
145 _scrollAnimationStart.On -= value;
150 /// ScrollAnimationStopped will be triggered when the content animation has been stopped.
152 /// <since_tizen> preview </since_tizen>
153 public event EventHandler ScrollAnimationStopped
157 _scrollAnimationStop.On += value;
161 _scrollAnimationStop.On -= value;
166 /// DragStart will be triggered when dragging the contents around has started.
168 /// <since_tizen> preview </since_tizen>
169 public event EventHandler DragStart
173 _dragStart.On += value;
177 _dragStart.On -= value;
182 /// DragStop will be triggered when dragging the contents around has stopped.
184 /// <since_tizen> preview </since_tizen>
185 public event EventHandler DragStop
189 _dragStop.On += value;
193 _dragStop.On -= value;
198 /// PageScrolled will be triggered when the visible page has changed.
200 /// <since_tizen> preview </since_tizen>
201 public event EventHandler PageScrolled
205 _scrollpage.On += value;
209 _scrollpage.On -= value;
214 /// Gets the current region in the content object that is visible through the scroller.
216 /// <since_tizen> preview </since_tizen>
217 public Rect CurrentRegion
222 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
223 return new Rect(x, y, w, h);
228 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy.
231 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
232 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
234 /// <since_tizen> preview </since_tizen>
235 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
240 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
241 return (ScrollBarVisiblePolicy)policy;
245 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
246 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
251 /// Sets or gets the value of VerticalScrollBarVisiblePolicy.
254 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
255 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
257 /// <since_tizen> preview </since_tizen>
258 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
263 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
264 return (ScrollBarVisiblePolicy)policy;
268 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
269 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
274 /// Sets or gets the value of ScrollBlock.
277 /// This function will block scrolling movement in a given direction. One can disable movements in the X-axis, the Y-axis, or both.
278 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
280 /// <since_tizen> preview </since_tizen>
281 public ScrollBlock ScrollBlock
285 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
289 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
294 /// Sets or gets the scroll current page number.
297 /// Current page means the page which meets the top of the viewport.
298 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
299 /// The page number starts from 0. 0 is the first page.
301 /// <since_tizen> preview </since_tizen>
302 public int VerticalPageIndex
307 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
313 /// Sets or gets the scroll current page number.
316 /// Current page means the page which meets the left of the viewport.
317 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
318 /// The page number starts from 0. 0 is the first page.
320 /// <since_tizen> preview </since_tizen>
321 public int HorizontalPageIndex
326 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
332 /// Sets or gets the maximum limit of the movable page at vertical direction.
334 /// <since_tizen> preview </since_tizen>
335 public int VerticalPageScrollLimit
340 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
345 int h = HorizontalPageScrollLimit;
346 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
351 /// Sets or gets the maximum limit of the movable page at horizontal direction.
353 /// <since_tizen> preview </since_tizen>
354 public int HorizontalPageScrollLimit
359 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
364 int v = VerticalPageScrollLimit;
365 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
370 /// Sets or gets the vertical bounce behaviour.
371 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
372 /// This is a visual way to indicate the end has been reached.
373 /// This is enabled by default for both axis.
374 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
376 /// <since_tizen> preview </since_tizen>
377 public bool VerticalBounce
382 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
387 bool h = HorizontalBounce;
388 Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value);
393 /// Sets or gets the horizontal bounce behaviour.
394 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
395 /// This is a visual way to indicate the end has been reached.
396 /// This is enabled by default for both axis.
397 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
399 /// <since_tizen> preview </since_tizen>
400 public bool HorizontalBounce
405 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
410 bool v = VerticalBounce;
411 Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v);
416 /// Gets the width of the content object of the scroller.
418 /// <since_tizen> preview </since_tizen>
419 public int ChildWidth
424 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
430 /// Gets the height of the content object of the scroller.
432 /// <since_tizen> preview </since_tizen>
433 public int ChildHeight
438 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
444 /// Sets the scrolling gravity values for a scroller.
445 /// The gravity defines how the scroller will adjust its view when the size of the scroller contents increase.
446 /// The scroller will adjust the view to glue itself as follows:
447 /// 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.
448 /// Default values for x and y are 0.0.
450 /// <since_tizen> preview </since_tizen>
451 public double HorizontalGravity
456 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
461 double v = VerticalGravity;
462 Interop.Elementary.elm_scroller_gravity_set(RealHandle, value, v);
467 /// Sets the scrolling gravity values for a scroller.
468 /// The gravity defines how the scroller will adjust its view when the size of the scroller contents increase.
469 /// The scroller will adjust the view to glue itself as follows:
470 /// 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.
471 /// Default values for x and y are 0.0.
473 /// <since_tizen> preview </since_tizen>
474 public double VerticalGravity
479 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
484 double h = HorizontalGravity;
485 Interop.Elementary.elm_scroller_gravity_set(RealHandle, h, value);
490 /// Gets the scroll last page number.
491 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
493 /// <since_tizen> preview </since_tizen>
494 public int LastVerticalPageNumber
499 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
505 /// Gets the scroll last page number.
506 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
508 /// <since_tizen> preview </since_tizen>
509 public int LastHorizontalPageNumber
514 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
520 /// Sets an infinite loop_ for a scroller.
521 /// This function sets the infinite loop vertically.
522 /// If the content is set, it will be shown repeatedly.
524 /// <since_tizen> preview </since_tizen>
525 public bool VerticalLoop
530 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
535 bool h = HorizontalLoop;
536 Interop.Elementary.elm_scroller_loop_set(RealHandle, h, value);
541 /// Sets an infinite loop_ for a scroller.
542 /// This function sets the infinite loop horizontally.
543 /// If the content is set, it will be shown repeatedly.
545 /// <since_tizen> preview </since_tizen>
546 public bool HorizontalLoop
551 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
556 bool v = VerticalLoop;
557 Interop.Elementary.elm_scroller_loop_set(RealHandle, value, v);
562 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
564 /// <since_tizen> preview </since_tizen>
565 public double VerticalRelativePageSize
570 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
575 double h = HorizontalRelativePageSize;
576 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, h, value);
581 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
583 /// <since_tizen> preview </since_tizen>
584 public double HorizontalRelativePageSize
589 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
594 double v = VerticalRelativePageSize;
595 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, value, v);
600 /// Gets or sets the page snapping behavior of a scroller.
603 /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
604 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
605 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
606 /// This function will set if it that is enabled or not, for each axis.
608 /// <since_tizen> preview </since_tizen>
609 public bool VerticalSnap
614 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
619 bool h = HorizontalSnap;
620 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, h, value);
625 /// Gets or sets the page snapping behavior of a scroller.
628 /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
629 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
630 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
631 /// This function will set if it that is enabled or not, for each axis.
633 /// <since_tizen> preview </since_tizen>
634 public bool HorizontalSnap
639 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
644 bool v = VerticalSnap;
645 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, value, v);
650 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
652 /// <since_tizen> preview </since_tizen>
653 public int PageHeight
658 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
664 Interop.Elementary.elm_scroller_page_size_set(RealHandle, w, value);
669 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
671 /// <since_tizen> preview </since_tizen>
677 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
683 Interop.Elementary.elm_scroller_page_size_set(RealHandle, value, h);
688 /// Gets or sets the event propagation for a scroller.
689 /// This enables or disables event propagation from the scroller content to the scroller and its parent.
690 /// By default, event propagation is enabled.
692 /// <since_tizen> preview </since_tizen>
693 public bool ContentPropagateEvents
697 return Interop.Elementary.elm_scroller_propagate_events_get(RealHandle);
701 Interop.Elementary.elm_scroller_propagate_events_set(RealHandle, value);
706 /// Gets or sets the step size to move scroller by key event.
708 /// <since_tizen> preview </since_tizen>
709 public int HorizontalStepSize
714 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
719 int v = VerticalStepSize;
720 Interop.Elementary.elm_scroller_step_size_set(RealHandle, value, v);
725 /// Gets or sets the step size to move scroller by key event.
727 /// <since_tizen> preview </since_tizen>
728 public int VerticalStepSize
733 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
738 int h = HorizontalStepSize;
739 Interop.Elementary.elm_scroller_step_size_set(RealHandle, h, value);
744 /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
746 /// <since_tizen> preview </since_tizen>
747 public bool WheelDisabled
751 return Interop.Elementary.elm_scroller_wheel_disabled_get(RealHandle);
755 Interop.Elementary.elm_scroller_wheel_disabled_set(RealHandle, value);
760 /// Gets or sets the type of single direction scroll.
762 /// <since_tizen> preview </since_tizen>
763 public ScrollSingleDirection SingleDirection
767 return (ScrollSingleDirection)Interop.Elementary.elm_scroller_single_direction_get(RealHandle);
771 Interop.Elementary.elm_scroller_single_direction_set(RealHandle, (int)value);
776 /// Sets the scroller minimum size limited to the minimum size of the content.
777 /// By default, the scroller will be as small as its design allows, irrespective of its content.
778 /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
780 /// <param name="horizontal">Enable limiting minimum size horizontally.</param>
781 /// <param name="vertical">Enable limiting minimum size vertically.</param>
782 /// <since_tizen> preview </since_tizen>
783 public void MinimumLimit(bool horizontal, bool vertical)
785 Interop.Elementary.elm_scroller_content_min_limit(RealHandle, horizontal, vertical);
789 /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
791 /// <param name="width">The horizontal page size.</param>
792 /// <param name="height">The vertical page size.</param>
793 /// <since_tizen> preview </since_tizen>
794 public void SetPageSize(int width, int height)
796 Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
800 /// Sets the scroll page size relative to the viewport size.
803 /// The scroller is capable of limiting scrolling by the user to "pages".
804 /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
805 /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
806 /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
807 /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
808 /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
809 /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
811 /// <param name="width">The horizontal page relative size.</param>
812 /// <param name="height">The vertical page relative size.</param>
813 /// <since_tizen> preview </since_tizen>
814 public void SetPageSize(double width, double height)
816 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
820 /// Shows a specific virtual region within the scroller content object by the page number.
821 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
823 /// <param name="horizontalPageIndex">The horizontal page number.</param>
824 /// <param name="verticalPageIndex">The vertical page number.</param>
825 /// <param name="animated">True means slider with animation.</param>
826 /// <since_tizen> preview </since_tizen>
827 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
831 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
835 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
840 /// Shows a specific virtual region within the scroller content object.
843 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
844 /// starting at the top-left of the virtual content object) is shown within the scroller.
845 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
846 /// (if configuration in general calls for transitions).
847 /// It may not jump immediately to the new location and may take a while and show other content along the way.
849 /// <param name="region">Rect struct of region.</param>
850 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
851 /// <since_tizen> preview </since_tizen>
852 public void ScrollTo(Rect region, bool animated)
856 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
860 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
865 /// The callback of the Realized event.
867 /// <since_tizen> preview </since_tizen>
868 protected override void OnRealized()
871 _scroll = new SmartEvent(this, this.RealHandle, "scroll");
872 _scrollAnimationStart = new SmartEvent(this, this.RealHandle, "scroll,anim,start");
873 _scrollAnimationStop = new SmartEvent(this, this.RealHandle, "scroll,anim,stop");
874 _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
875 _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
876 _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
880 /// Creates a widget handle.
882 /// <param name="parent">Parent EvasObject.</param>
883 /// <returns>Handle IntPtr.</returns>
884 /// <since_tizen> preview </since_tizen>
885 protected override IntPtr CreateHandle(EvasObject parent)
887 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
888 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
890 RealHandle = Interop.Elementary.elm_scroller_add(handle);
891 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);