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 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 visible type of scrollbar.
46 /// <since_tizen> preview </since_tizen>
47 public enum ScrollBlock
50 /// Scrolling movement is allowed in both direction.(X axis and Y axis)
55 /// Scrolling movement is not allowed in Y axis direction.
60 /// Scrolling movement is not allowed in X axis direction.
66 /// Type that controls how the content is scrolled.
68 /// <since_tizen> preview </since_tizen>
69 public enum ScrollSingleDirection
72 /// Scroll every direction.
77 /// Scroll single direction if the direction is certain.
82 /// Scroll only 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 _dragStart;
96 SmartEvent _scrollpage;
99 /// Creates and initializes a new instance of the Scroller class.
101 /// <param name="parent">The <see cref="EvasObject"/> to which the new Scroller will be attached as a child.</param>
102 /// <since_tizen> preview </since_tizen>
103 public Scroller(EvasObject parent) : base(parent)
108 /// Creates and initializes a new instance of the Scroller class.
110 /// <since_tizen> preview </since_tizen>
111 public Scroller() : base()
116 /// Scrolled will be triggered when the content has been scrolled.
118 /// <since_tizen> preview </since_tizen>
119 public event EventHandler Scrolled
132 /// DragStart will be triggered when dragging the contents around has started.
134 /// <since_tizen> preview </since_tizen>
135 public event EventHandler DragStart
139 _dragStart.On += value;
143 _dragStart.On -= value;
148 /// DragStop will be triggered when dragging the contents around has stopped.
150 /// <since_tizen> preview </since_tizen>
151 public event EventHandler DragStop
155 _dragStop.On += value;
159 _dragStop.On -= value;
164 /// PageScrolled will be triggered when the visible page has changed.
166 /// <since_tizen> preview </since_tizen>
167 public event EventHandler PageScrolled
171 _scrollpage.On += value;
175 _scrollpage.On -= value;
180 /// Gets the current region in the content object that is visible through the Scroller.
182 /// <since_tizen> preview </since_tizen>
183 public Rect CurrentRegion
188 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
189 return new Rect(x, y, w, h);
194 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
197 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
198 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
200 /// <since_tizen> preview </since_tizen>
201 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
206 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
207 return (ScrollBarVisiblePolicy)policy;
211 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
212 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
217 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
220 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
221 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
223 /// <since_tizen> preview </since_tizen>
224 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
229 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
230 return (ScrollBarVisiblePolicy)policy;
234 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
235 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
240 /// Sets or gets the value of ScrollBlock.
243 /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both.
244 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
246 /// <since_tizen> preview </since_tizen>
247 public ScrollBlock ScrollBlock
251 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
255 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
260 /// Sets or gets scroll current page number.
263 /// Current page means the page which meets the top of the viewport.
264 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
265 /// The page number starts from 0. 0 is the first page.
267 /// <since_tizen> preview </since_tizen>
268 public int VerticalPageIndex
273 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
279 /// Sets or gets scroll current page number.
282 /// Current page means the page which meets the left of the viewport.
283 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
284 /// The page number starts from 0. 0 is the first page.
286 /// <since_tizen> preview </since_tizen>
287 public int HorizontalPageIndex
292 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
298 /// Sets or gets the maximum limit of the movable page at vertical direction.
300 /// <since_tizen> preview </since_tizen>
301 public int VerticalPageScrollLimit
306 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
311 int h = HorizontalPageScrollLimit;
312 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
317 /// Sets or gets the maximum limit of the movable page at horizontal direction.
319 /// <since_tizen> preview </since_tizen>
320 public int HorizontalPageScrollLimit
325 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
330 int v = VerticalPageScrollLimit;
331 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
336 /// Sets or gets the vertical bounce behaviour.
337 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
338 /// This is a visual way to indicate the end has been reached.
339 /// This is enabled by default for both axis.
340 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
342 /// <since_tizen> preview </since_tizen>
343 public bool VerticalBounce
348 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
353 bool h = HorizontalBounce;
354 Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value);
359 /// Sets or gets the horizontal bounce behaviour.
360 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
361 /// This is a visual way to indicate the end has been reached.
362 /// This is enabled by default for both axis.
363 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
365 /// <since_tizen> preview </since_tizen>
366 public bool HorizontalBounce
371 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
376 bool v = VerticalBounce;
377 Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v);
382 /// Gets the width of the content object of the scroller.
384 /// <since_tizen> preview </since_tizen>
385 public int ChildWidth
390 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
396 /// Gets the height of the content object of the scroller.
398 /// <since_tizen> preview </since_tizen>
399 public int ChildHeight
404 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
410 /// Set scrolling gravity values for a scroller.
411 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
412 /// The scroller will adjust the view to glue itself as follows.
413 /// 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
414 /// Default values for x and y are 0.0
416 /// <since_tizen> preview </since_tizen>
417 public double HorizontalGravity
422 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
427 double v = VerticalGravity;
428 Interop.Elementary.elm_scroller_gravity_set(RealHandle, value, v);
433 /// Set scrolling gravity values for a scroller.
434 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
435 /// The scroller will adjust the view to glue itself as follows.
436 /// 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
437 /// Default values for x and y are 0.0
439 /// <since_tizen> preview </since_tizen>
440 public double VerticalGravity
445 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
450 double h = HorizontalGravity;
451 Interop.Elementary.elm_scroller_gravity_set(RealHandle, h, value);
456 /// Get scroll last page number.
457 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
459 /// <since_tizen> preview </since_tizen>
460 public int LastVerticalPageNumber
465 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
471 /// Get scroll last page number.
472 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
474 /// <since_tizen> preview </since_tizen>
475 public int LastHorizontalPageNumber
480 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
486 /// Set an infinite loop_ for a scroller.
487 /// This function sets the infinite loop vertically.
488 /// If the content is set, it will be shown repeatedly.
490 /// <since_tizen> preview </since_tizen>
491 public bool VerticalLoop
496 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
501 bool h = HorizontalLoop;
502 Interop.Elementary.elm_scroller_loop_set(RealHandle, h, value);
507 /// Set an infinite loop_ for a scroller.
508 /// This function sets the infinite loop horizontally.
509 /// If the content is set, it will be shown repeatedly.
511 /// <since_tizen> preview </since_tizen>
512 public bool HorizontalLoop
517 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
522 bool v = VerticalLoop;
523 Interop.Elementary.elm_scroller_loop_set(RealHandle, value, v);
528 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
530 /// <since_tizen> preview </since_tizen>
531 public double VerticalRelativePageSize
536 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
541 double h = HorizontalRelativePageSize;
542 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, h, value);
547 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
549 /// <since_tizen> preview </since_tizen>
550 public double HorizontalRelativePageSize
555 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
560 double v = VerticalRelativePageSize;
561 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, value, v);
566 /// Gets or Sets the page snapping behavior of a scroller.
569 /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
570 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
571 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
572 /// This function will set if it that is enabled or not, for each axis.
574 /// <since_tizen> preview </since_tizen>
575 public bool VerticalSnap
580 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
585 bool h = HorizontalSnap;
586 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, h, value);
591 /// Gets or Sets the page snapping behavior of a scroller.
594 /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
595 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
596 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
597 /// This function will set if it that is enabled or not, for each axis.
599 /// <since_tizen> preview </since_tizen>
600 public bool HorizontalSnap
605 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
610 bool v = VerticalSnap;
611 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, value, v);
616 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
618 /// <since_tizen> preview </since_tizen>
619 public int PageHeight
624 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
630 Interop.Elementary.elm_scroller_page_size_set(RealHandle, w, value);
635 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
637 /// <since_tizen> preview </since_tizen>
643 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
649 Interop.Elementary.elm_scroller_page_size_set(RealHandle, value, h);
654 /// Gets or sets the event propagation for a scroller.
655 /// This enables or disables event propagation from the scroller content to the scroller and its parent.
656 /// By default event propagation is enabled.
658 /// <since_tizen> preview </since_tizen>
659 public bool ContentPropagateEvents
663 return Interop.Elementary.elm_scroller_propagate_events_get(RealHandle);
667 Interop.Elementary.elm_scroller_propagate_events_set(RealHandle, value);
672 /// Gets or sets the step size to move scroller by key event.
674 /// <since_tizen> preview </since_tizen>
675 public int HorizontalStepSize
680 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
685 int v = VerticalStepSize;
686 Interop.Elementary.elm_scroller_step_size_set(RealHandle, value, v);
691 /// Gets or sets the step size to move scroller by key event.
693 /// <since_tizen> preview </since_tizen>
694 public int VerticalStepSize
699 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
704 int h = HorizontalStepSize;
705 Interop.Elementary.elm_scroller_step_size_set(RealHandle, h, value);
710 /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
712 /// <since_tizen> preview </since_tizen>
713 public bool WheelDisabled
717 return Interop.Elementary.elm_scroller_wheel_disabled_get(RealHandle);
721 Interop.Elementary.elm_scroller_wheel_disabled_set(RealHandle, value);
726 /// Gets or sets the type of single direction scroll.
728 /// <since_tizen> preview </since_tizen>
729 public ScrollSingleDirection SingleDirection
733 return (ScrollSingleDirection)Interop.Elementary.elm_scroller_single_direction_get(RealHandle);
737 Interop.Elementary.elm_scroller_single_direction_set(RealHandle, (int)value);
742 /// Sets the scroller minimum size limited to the minimum size of the content.
743 /// By default the scroller will be as small as its design allows, irrespective of its content.
744 /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
746 /// <param name="horizontal">Enable limiting minimum size horizontally</param>
747 /// <param name="vertical">Enable limiting minimum size vertically</param>
748 /// <since_tizen> preview </since_tizen>
749 public void MinimumLimit(bool horizontal, bool vertical)
751 Interop.Elementary.elm_scroller_content_min_limit(RealHandle, horizontal, vertical);
755 /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
757 /// <param name="width">The horizontal page size.</param>
758 /// <param name="height">The vertical page size.</param>
759 /// <since_tizen> preview </since_tizen>
760 public void SetPageSize(int width, int height)
762 Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
766 /// Sets the scroll page size relative to the viewport size.
769 /// The scroller is capable of limiting scrolling by the user to "pages".
770 /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
771 /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
772 /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
773 /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
774 /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
775 /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
777 /// <param name="width">The horizontal page relative size.</param>
778 /// <param name="height">The vertical page relative size.</param>
779 /// <since_tizen> preview </since_tizen>
780 public void SetPageSize(double width, double height)
782 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
786 /// Shows a specific virtual region within the scroller content object by the page number.
787 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
789 /// <param name="horizontalPageIndex">The horizontal page number.</param>
790 /// <param name="verticalPageIndex">The vertical page number.</param>
791 /// <param name="animated">True means slider with animation.</param>
792 /// <since_tizen> preview </since_tizen>
793 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
797 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
801 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
806 /// Shows a specific virtual region within the scroller content object.
809 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
810 /// starting at the top-left of the virtual content object) is shown within the scroller.
811 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
812 /// (if configuration in general calls for transitions).
813 /// It may not jump immediately to the new location and may take a while and show other content along the way.
815 /// <param name="region">Rect struct of region.</param>
816 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
817 /// <since_tizen> preview </since_tizen>
818 public void ScrollTo(Rect region, bool animated)
822 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
826 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
831 /// The callback of Realized Event
833 /// <since_tizen> preview </since_tizen>
834 protected override void OnRealized()
837 _scroll = new SmartEvent(this, this.RealHandle, "scroll");
838 _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
839 _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
840 _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
844 /// Creates a widget handle.
846 /// <param name="parent">Parent EvasObject</param>
847 /// <returns>Handle IntPtr</returns>
848 /// <since_tizen> preview </since_tizen>
849 protected override IntPtr CreateHandle(EvasObject parent)
851 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
852 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
854 RealHandle = Interop.Elementary.elm_scroller_add(handle);
855 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);