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 public enum ScrollBarVisiblePolicy
27 /// Show scrollbars as needed
32 /// Always show scrollbars
37 /// Never show scrollbars
43 /// Enumeration for visible type of scrollbar.
45 public enum ScrollBlock
48 /// Scrolling movement is allowed in both direction.(X axis and Y axis)
53 /// Scrolling movement is not allowed in Y axis direction.
58 /// Scrolling movement is not allowed in X axis direction.
64 /// Type that controls how the content is scrolled.
66 public enum ScrollSingleDirection
69 /// Scroll every direction.
74 /// Scroll single direction if the direction is certain.
79 /// Scroll only single direction.
85 /// The Scroller is a container that holds and clips a single object and allows you to scroll across it.
87 public class Scroller : Layout
90 SmartEvent _dragStart;
92 SmartEvent _scrollpage;
95 /// Creates and initializes a new instance of the Scroller class.
97 /// <param name="parent">The <see cref="EvasObject"/> to which the new Scroller will be attached as a child.</param>
98 public Scroller(EvasObject parent) : base(parent)
100 _scroll = new SmartEvent(this, this.RealHandle, "scroll");
101 _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
102 _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
103 _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
107 /// Scrolled will be triggered when the content has been scrolled.
109 public event EventHandler Scrolled
122 /// DragStart will be triggered when dragging the contents around has started.
124 public event EventHandler DragStart
128 _dragStart.On += value;
132 _dragStart.On -= value;
137 /// DragStop will be triggered when dragging the contents around has stopped.
139 public event EventHandler DragStop
143 _dragStop.On += value;
147 _dragStop.On -= value;
152 /// PageScrolled will be triggered when the visible page has changed.
154 public event EventHandler PageScrolled
158 _scrollpage.On += value;
162 _scrollpage.On -= value;
167 /// Gets the current region in the content object that is visible through the Scroller.
169 public Rect CurrentRegion
174 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
175 return new Rect(x, y, w, h);
180 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
183 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
184 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
186 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
191 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
192 return (ScrollBarVisiblePolicy)policy;
196 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
197 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
202 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
205 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
206 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
208 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
213 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
214 return (ScrollBarVisiblePolicy)policy;
218 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
219 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
224 /// Sets or gets the value of ScrollBlock.
227 /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both.
228 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
230 public ScrollBlock ScrollBlock
234 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
238 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
243 /// Sets or gets scroll current page number.
246 /// Current page means the page which meets the top of the viewport.
247 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
248 /// The page number starts from 0. 0 is the first page.
250 public int VerticalPageIndex
255 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
261 /// Sets or gets scroll current page number.
264 /// Current page means the page which meets the left of the viewport.
265 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
266 /// The page number starts from 0. 0 is the first page.
268 public int HorizontalPageIndex
273 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
279 /// Sets or gets the maximum limit of the movable page at vertical direction.
281 public int VerticalPageScrollLimit
286 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
291 int h = HorizontalPageScrollLimit;
292 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
297 /// Sets or gets the maximum limit of the movable page at horizontal direction.
299 public int HorizontalPageScrollLimit
304 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
309 int v = VerticalPageScrollLimit;
310 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
315 /// Sets or gets the vertical bounce behaviour.
316 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
317 /// This is a visual way to indicate the end has been reached.
318 /// This is enabled by default for both axis.
319 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
321 public bool VerticalBounce
326 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
331 bool h = HorizontalBounce;
332 Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value);
337 /// Sets or gets the horizontal bounce behaviour.
338 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
339 /// This is a visual way to indicate the end has been reached.
340 /// This is enabled by default for both axis.
341 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
343 public bool HorizontalBounce
348 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
353 bool v = VerticalBounce;
354 Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v);
359 /// Gets the width of the content object of the scroller.
361 public int ChildWidth
366 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
372 /// Gets the height of the content object of the scroller.
374 public int ChildHeight
379 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
385 /// Set scrolling gravity values for a scroller.
386 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
387 /// The scroller will adjust the view to glue itself as follows.
388 /// 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
389 /// Default values for x and y are 0.0
391 public double HorizontalGravity
396 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
401 double v = VerticalGravity;
402 Interop.Elementary.elm_scroller_gravity_set(RealHandle, value, v);
407 /// Set scrolling gravity values for a scroller.
408 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
409 /// The scroller will adjust the view to glue itself as follows.
410 /// 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
411 /// Default values for x and y are 0.0
413 public double VerticalGravity
418 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
423 double h = HorizontalGravity;
424 Interop.Elementary.elm_scroller_gravity_set(RealHandle, h, value);
429 /// Get scroll last page number.
430 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
432 public int LastVerticalPageNumber
437 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
443 /// Get scroll last page number.
444 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
446 public int LastHorizontalPageNumber
451 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
457 /// Set an infinite loop_ for a scroller.
458 /// This function sets the infinite loop vertically.
459 /// If the content is set, it will be shown repeatedly.
461 public bool VerticalLoop
466 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
471 bool h = HorizontalLoop;
472 Interop.Elementary.elm_scroller_loop_set(RealHandle, h, value);
477 /// Set an infinite loop_ for a scroller.
478 /// This function sets the infinite loop horizontally.
479 /// If the content is set, it will be shown repeatedly.
481 public bool HorizontalLoop
486 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
491 bool v = VerticalLoop;
492 Interop.Elementary.elm_scroller_loop_set(RealHandle, value, v);
497 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
499 public double VerticalRelativePageSize
504 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
509 double h = HorizontalRelativePageSize;
510 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, h, value);
515 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
517 public double HorizontalRelativePageSize
522 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
527 double v = VerticalRelativePageSize;
528 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, value, v);
533 /// Gets or Sets the page snapping behavior of a scroller.
536 /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
537 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
538 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
539 /// This function will set if it that is enabled or not, for each axis.
541 public bool VerticalSnap
546 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
551 bool h = HorizontalSnap;
552 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, h, value);
557 /// Gets or Sets the page snapping behavior of a scroller.
560 /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
561 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
562 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
563 /// This function will set if it that is enabled or not, for each axis.
565 public bool HorizontalSnap
570 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
575 bool v = VerticalSnap;
576 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, value, v);
581 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
583 public int PageHeight
588 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
594 Interop.Elementary.elm_scroller_page_size_set(RealHandle, w, value);
599 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
606 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
612 Interop.Elementary.elm_scroller_page_size_set(RealHandle, value, h);
617 /// Gets or sets the event propagation for a scroller.
618 /// This enables or disables event propagation from the scroller content to the scroller and its parent.
619 /// By default event propagation is enabled.
621 public bool ContentPropagateEvents
625 return Interop.Elementary.elm_scroller_propagate_events_get(RealHandle);
629 Interop.Elementary.elm_scroller_propagate_events_set(RealHandle, value);
634 /// Gets or sets the step size to move scroller by key event.
636 public int HorizontalStepSize
641 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
646 int v = VerticalStepSize;
647 Interop.Elementary.elm_scroller_step_size_set(RealHandle, value, v);
652 /// Gets or sets the step size to move scroller by key event.
654 public int VerticalStepSize
659 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
664 int h = HorizontalStepSize;
665 Interop.Elementary.elm_scroller_step_size_set(RealHandle, h, value);
670 /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
672 public bool WheelDisabled
676 return Interop.Elementary.elm_scroller_wheel_disabled_get(RealHandle);
680 Interop.Elementary.elm_scroller_wheel_disabled_set(RealHandle, value);
685 /// Gets or sets the type of single direction scroll.
687 public ScrollSingleDirection SingleDirection
691 return (ScrollSingleDirection)Interop.Elementary.elm_scroller_single_direction_get(RealHandle);
695 Interop.Elementary.elm_scroller_single_direction_set(RealHandle, (int)value);
700 /// Sets the scroller minimum size limited to the minimum size of the content.
701 /// By default the scroller will be as small as its design allows, irrespective of its content.
702 /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
704 /// <param name="horizontal">Enable limiting minimum size horizontally</param>
705 /// <param name="vertical">Enable limiting minimum size vertically</param>
706 public void MinimumLimit(bool horizontal, bool vertical)
708 Interop.Elementary.elm_scroller_content_min_limit(RealHandle, horizontal, vertical);
712 /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
714 /// <param name="width">The horizontal page size.</param>
715 /// <param name="height">The vertical page size.</param>
716 public void SetPageSize(int width, int height)
718 Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
722 /// Sets the scroll page size relative to the viewport size.
725 /// The scroller is capable of limiting scrolling by the user to "pages".
726 /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
727 /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
728 /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
729 /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
730 /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
731 /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
733 /// <param name="width">The horizontal page relative size.</param>
734 /// <param name="height">The vertical page relative size.</param>
735 public void SetPageSize(double width, double height)
737 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
741 /// Shows a specific virtual region within the scroller content object by the page number.
742 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
744 /// <param name="horizontalPageIndex">The horizontal page number.</param>
745 /// <param name="verticalPageIndex">The vertical page number.</param>
746 /// <param name="animated">True means slider with animation.</param>
747 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
751 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
755 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
760 /// Shows a specific virtual region within the scroller content object.
763 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
764 /// starting at the top-left of the virtual content object) is shown within the scroller.
765 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
766 /// (if configuration in general calls for transitions).
767 /// It may not jump immediately to the new location and may take a while and show other content along the way.
769 /// <param name="region">Rect struct of region.</param>
770 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
771 public void ScrollTo(Rect region, bool animated)
775 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
779 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
784 /// Creates a widget handle.
786 /// <param name="parent">Parent EvasObject</param>
787 /// <returns>Handle IntPtr</returns>
788 protected override IntPtr CreateHandle(EvasObject parent)
790 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
791 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
793 RealHandle = Interop.Elementary.elm_scroller_add(handle);
794 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);