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
31 /// Always show scrollbars
35 /// Never show scrollbars
40 /// Enumeration for visible type of scrollbar.
42 public enum ScrollBlock
45 /// Scrolling movement is allowed in both direction.(X axis and Y axis)
49 /// Scrolling movement is not allowed in Y axis direction.
53 /// Scrolling movement is not allowed in X axis direction.
58 /// The Scroller is a container that holds and clips a single object and allows you to scroll across it.
60 public class Scroller : Layout
63 SmartEvent _dragStart;
65 SmartEvent _scrollpage;
68 /// Creates and initializes a new instance of the Scroller class.
70 /// <param name="parent">The <see cref="EvasObject"/> to which the new Scroller will be attached as a child.</param>
71 public Scroller(EvasObject parent) : base(parent)
73 _scroll = new SmartEvent(this, this.RealHandle, "scroll");
74 _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
75 _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
76 _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
80 /// Scrolled will be triggered when the content has been scrolled.
82 public event EventHandler Scrolled
95 /// DragStart will be triggered when dragging the contents around has started.
97 public event EventHandler DragStart
101 _dragStart.On += value;
105 _dragStart.On -= value;
110 /// DragStop will be triggered when dragging the contents around has stopped.
112 public event EventHandler DragStop
116 _dragStop.On += value;
120 _dragStop.On -= value;
125 /// PageScrolled will be triggered when the visible page has changed.
127 public event EventHandler PageScrolled
131 _scrollpage.On += value;
135 _scrollpage.On -= value;
140 /// Gets the current region in the content object that is visible through the Scroller.
142 public Rect CurrentRegion
147 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
148 return new Rect(x, y, w, h);
153 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
156 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
157 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
159 public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
164 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
165 return (ScrollBarVisiblePolicy)policy;
169 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
170 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
175 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
178 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
179 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
181 public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
186 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
187 return (ScrollBarVisiblePolicy)policy;
191 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
192 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
197 /// Sets or gets the value of ScrollBlock.
200 /// This function will block scrolling movement in a given direction.One can disable movements in the X axis, the Y axis or both.
201 /// The default value is ScrollBlock.None, where movements are allowed in both directions.
203 public ScrollBlock ScrollBlock
207 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
211 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
216 /// Sets or gets scroll current page number.
219 /// Current page means the page which meets the top of the viewport.
220 /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
221 /// The page number starts from 0. 0 is the first page.
223 public int VerticalPageIndex
228 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
234 /// Sets or gets scroll current page number.
237 /// Current page means the page which meets the left of the viewport.
238 /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
239 /// The page number starts from 0. 0 is the first page.
241 public int HorizontalPageIndex
246 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
252 /// Sets or gets the maximum limit of the movable page at vertical direction.
254 public int VerticalPageScrollLimit
259 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
264 int h = HorizontalPageScrollLimit;
265 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
270 /// Sets or gets the maximum limit of the movable page at horizontal direction.
272 public int HorizontalPageScrollLimit
277 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
282 int v = VerticalPageScrollLimit;
283 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
288 /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
290 /// <param name="width">The horizontal page size.</param>
291 /// <param name="height">The vertical page size.</param>
292 public void SetPageSize(int width, int height)
294 Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
298 /// Sets the scroll page size relative to the viewport size.
301 /// The scroller is capable of limiting scrolling by the user to "pages".
302 /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
303 /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
304 /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
305 /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
306 /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
307 /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
309 /// <param name="width">The horizontal page relative size.</param>
310 /// <param name="height">The vertical page relative size.</param>
311 public void SetPageSize(double width, double height)
313 Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
317 /// Shows a specific virtual region within the scroller content object by the page number.
318 /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
320 /// <param name="horizontalPageIndex">The horizontal page number.</param>
321 /// <param name="verticalPageIndex">The vertical page number.</param>
322 /// <param name="animated">True means slider with animation.</param>
323 public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
327 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
331 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
336 /// Shows a specific virtual region within the scroller content object.
339 /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
340 /// starting at the top-left of the virtual content object) is shown within the scroller.
341 /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
342 /// (if configuration in general calls for transitions).
343 /// It may not jump immediately to the new location and may take a while and show other content along the way.
345 /// <param name="region">Rect struct of region.</param>
346 /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
347 public void ScrollTo(Rect region, bool animated)
351 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
355 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
359 protected override IntPtr CreateHandle(EvasObject parent)
361 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
362 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
364 RealHandle = Interop.Elementary.elm_scroller_add(handle);
365 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);