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)
103 /// Creates and initializes a new instance of the Scroller class.
105 public Scroller() : base()
110 /// Scrolled will be triggered when the content has been scrolled.
112 public event EventHandler Scrolled
125 /// DragStart will be triggered when dragging the contents around has started.
127 public event EventHandler DragStart
131 _dragStart.On += value;
135 _dragStart.On -= value;
140 /// DragStop will be triggered when dragging the contents around has stopped.
142 public event EventHandler DragStop
146 _dragStop.On += value;
150 _dragStop.On -= value;
155 /// PageScrolled will be triggered when the visible page has changed.
157 public event EventHandler PageScrolled
161 _scrollpage.On += value;
165 _scrollpage.On -= value;
170 /// Gets the current region in the content object that is visible through the Scroller.
172 public Rect CurrentRegion
177 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
178 return new Rect(x, y, w, h);
183 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
186 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
187 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
189 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
194 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
195 return (ScrollBarVisiblePolicy)policy;
199 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
200 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
205 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
208 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
209 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
211 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
216 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
217 return (ScrollBarVisiblePolicy)policy;
221 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
222 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
227 /// Sets or gets the value of ScrollBlock.
230 /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both.
231 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
233 public ScrollBlock ScrollBlock
237 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
241 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
246 /// Sets or gets scroll current page number.
249 /// Current page means the page which meets the top of the viewport.
250 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
251 /// The page number starts from 0. 0 is the first page.
253 public int VerticalPageIndex
258 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
264 /// Sets or gets scroll current page number.
267 /// Current page means the page which meets the left of the viewport.
268 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
269 /// The page number starts from 0. 0 is the first page.
271 public int HorizontalPageIndex
276 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
282 /// Sets or gets the maximum limit of the movable page at vertical direction.
284 public int VerticalPageScrollLimit
289 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
294 int h = HorizontalPageScrollLimit;
295 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
300 /// Sets or gets the maximum limit of the movable page at horizontal direction.
302 public int HorizontalPageScrollLimit
307 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
312 int v = VerticalPageScrollLimit;
313 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
318 /// Sets or gets the vertical bounce behaviour.
319 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
320 /// This is a visual way to indicate the end has been reached.
321 /// This is enabled by default for both axis.
322 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
324 public bool VerticalBounce
329 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
334 bool h = HorizontalBounce;
335 Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value);
340 /// Sets or gets the horizontal bounce behaviour.
341 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
342 /// This is a visual way to indicate the end has been reached.
343 /// This is enabled by default for both axis.
344 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
346 public bool HorizontalBounce
351 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
356 bool v = VerticalBounce;
357 Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v);
362 /// Gets the width of the content object of the scroller.
364 public int ChildWidth
369 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
375 /// Gets the height of the content object of the scroller.
377 public int ChildHeight
382 Interop.Elementary.elm_scroller_child_size_get(RealHandle, out w, out h);
388 /// Set scrolling gravity values for a scroller.
389 /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
390 /// The scroller will adjust the view to glue itself as follows.
391 /// 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
392 /// Default values for x and y are 0.0
394 public double HorizontalGravity
399 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
404 double v = VerticalGravity;
405 Interop.Elementary.elm_scroller_gravity_set(RealHandle, value, v);
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 public double VerticalGravity
421 Interop.Elementary.elm_scroller_gravity_get(RealHandle, out h, out v);
426 double h = HorizontalGravity;
427 Interop.Elementary.elm_scroller_gravity_set(RealHandle, h, value);
432 /// Get scroll last page number.
433 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
435 public int LastVerticalPageNumber
440 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
446 /// Get scroll last page number.
447 /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
449 public int LastHorizontalPageNumber
454 Interop.Elementary.elm_scroller_last_page_get(RealHandle, out h, out v);
460 /// Set an infinite loop_ for a scroller.
461 /// This function sets the infinite loop vertically.
462 /// If the content is set, it will be shown repeatedly.
464 public bool VerticalLoop
469 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
474 bool h = HorizontalLoop;
475 Interop.Elementary.elm_scroller_loop_set(RealHandle, h, value);
480 /// Set an infinite loop_ for a scroller.
481 /// This function sets the infinite loop horizontally.
482 /// If the content is set, it will be shown repeatedly.
484 public bool HorizontalLoop
489 Interop.Elementary.elm_scroller_loop_get(RealHandle, out h, out v);
494 bool v = VerticalLoop;
495 Interop.Elementary.elm_scroller_loop_set(RealHandle, value, v);
500 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
502 public double VerticalRelativePageSize
507 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
512 double h = HorizontalRelativePageSize;
513 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, h, value);
518 /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
520 public double HorizontalRelativePageSize
525 Interop.Elementary.elm_scroller_page_relative_get(RealHandle, out h, out v);
530 double v = VerticalRelativePageSize;
531 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, value, v);
536 /// Gets or Sets the page snapping behavior of a scroller.
539 /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
540 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
541 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
542 /// This function will set if it that is enabled or not, for each axis.
544 public bool VerticalSnap
549 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
554 bool h = HorizontalSnap;
555 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, h, value);
560 /// Gets or Sets the page snapping behavior of a scroller.
563 /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
564 /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
565 /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
566 /// This function will set if it that is enabled or not, for each axis.
568 public bool HorizontalSnap
573 Interop.Elementary.elm_scroller_page_snap_get(RealHandle, out h, out v);
578 bool v = VerticalSnap;
579 Interop.Elementary.elm_scroller_page_snap_set(RealHandle, value, v);
584 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
586 public int PageHeight
591 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
597 Interop.Elementary.elm_scroller_page_size_set(RealHandle, w, value);
602 /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
609 Interop.Elementary.elm_scroller_page_size_get(RealHandle, out w, out h);
615 Interop.Elementary.elm_scroller_page_size_set(RealHandle, value, h);
620 /// Gets or sets the event propagation for a scroller.
621 /// This enables or disables event propagation from the scroller content to the scroller and its parent.
622 /// By default event propagation is enabled.
624 public bool ContentPropagateEvents
628 return Interop.Elementary.elm_scroller_propagate_events_get(RealHandle);
632 Interop.Elementary.elm_scroller_propagate_events_set(RealHandle, value);
637 /// Gets or sets the step size to move scroller by key event.
639 public int HorizontalStepSize
644 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
649 int v = VerticalStepSize;
650 Interop.Elementary.elm_scroller_step_size_set(RealHandle, value, v);
655 /// Gets or sets the step size to move scroller by key event.
657 public int VerticalStepSize
662 Interop.Elementary.elm_scroller_step_size_get(RealHandle, out h, out v);
667 int h = HorizontalStepSize;
668 Interop.Elementary.elm_scroller_step_size_set(RealHandle, h, value);
673 /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
675 public bool WheelDisabled
679 return Interop.Elementary.elm_scroller_wheel_disabled_get(RealHandle);
683 Interop.Elementary.elm_scroller_wheel_disabled_set(RealHandle, value);
688 /// Gets or sets the type of single direction scroll.
690 public ScrollSingleDirection SingleDirection
694 return (ScrollSingleDirection)Interop.Elementary.elm_scroller_single_direction_get(RealHandle);
698 Interop.Elementary.elm_scroller_single_direction_set(RealHandle, (int)value);
703 /// Sets the scroller minimum size limited to the minimum size of the content.
704 /// By default the scroller will be as small as its design allows, irrespective of its content.
705 /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
707 /// <param name="horizontal">Enable limiting minimum size horizontally</param>
708 /// <param name="vertical">Enable limiting minimum size vertically</param>
709 public void MinimumLimit(bool horizontal, bool vertical)
711 Interop.Elementary.elm_scroller_content_min_limit(RealHandle, horizontal, vertical);
715 /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
717 /// <param name="width">The horizontal page size.</param>
718 /// <param name="height">The vertical page size.</param>
719 public void SetPageSize(int width, int height)
721 Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
725 /// Sets the scroll page size relative to the viewport size.
728 /// The scroller is capable of limiting scrolling by the user to "pages".
729 /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
730 /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
731 /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
732 /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
733 /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
734 /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
736 /// <param name="width">The horizontal page relative size.</param>
737 /// <param name="height">The vertical page relative size.</param>
738 public void SetPageSize(double width, double height)
740 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
744 /// Shows a specific virtual region within the scroller content object by the page number.
745 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
747 /// <param name="horizontalPageIndex">The horizontal page number.</param>
748 /// <param name="verticalPageIndex">The vertical page number.</param>
749 /// <param name="animated">True means slider with animation.</param>
750 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
754 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
758 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
763 /// Shows a specific virtual region within the scroller content object.
766 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
767 /// starting at the top-left of the virtual content object) is shown within the scroller.
768 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
769 /// (if configuration in general calls for transitions).
770 /// It may not jump immediately to the new location and may take a while and show other content along the way.
772 /// <param name="region">Rect struct of region.</param>
773 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
774 public void ScrollTo(Rect region, bool animated)
778 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
782 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
787 /// The callback of Realized Event
789 protected override void OnRealized()
792 _scroll = new SmartEvent(this, this.RealHandle, "scroll");
793 _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
794 _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
795 _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
799 /// Creates a widget handle.
801 /// <param name="parent">Parent EvasObject</param>
802 /// <returns>Handle IntPtr</returns>
803 protected override IntPtr CreateHandle(EvasObject parent)
805 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
806 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
808 RealHandle = Interop.Elementary.elm_scroller_add(handle);
809 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);