[ElmSharp*] Add Scrollable interface
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Panel.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// Enumeration for paneldirection type.
23     /// </summary>
24     public enum PanelDirection
25     {
26         /// <summary>
27         /// Top to bottom
28         /// </summary>
29         Top = 0,
30         /// <summary>
31         /// Bottom to top
32         /// </summary>
33         Bottom,
34         /// <summary>
35         /// Left to right
36         /// </summary>
37         Left,
38         /// <summary>
39         /// Right to left
40         /// </summary>
41         Right,
42     }
43
44     /// <summary>
45     /// The Panel is a container that can contain subobjects.
46     /// </summary>
47     public class Panel : Layout, IScrollable
48     {
49         ScrollableAdapter _scroller;
50         SmartEvent _toggled;
51
52         /// <summary>
53         /// Creates and initializes a new instance of Panel class.
54         /// </summary>
55         /// <param name="parent">The EvasObject to which the new Panel will be attached as a child.</param>
56         public Panel(EvasObject parent) : base(parent)
57         {
58             _toggled = new SmartEvent(this, this.RealHandle, "toggled");
59             _toggled.On += (s, e) => Toggled?.Invoke(this, EventArgs.Empty);
60             _scroller = new ScrollableAdapter(this);
61         }
62
63         /// <summary>
64         /// Sets or gets the hidden status of a given Panel widget.
65         /// </summary>
66         public bool IsOpen
67         {
68             get
69             {
70                 return !Interop.Elementary.elm_panel_hidden_get(RealHandle);
71             }
72             set
73             {
74                 Interop.Elementary.elm_panel_hidden_set(RealHandle, !value);
75             }
76         }
77
78         /// <summary>
79         /// Sets or gets the direction of a given Panel widget.
80         /// </summary>
81         public PanelDirection Direction
82         {
83             get
84             {
85                 return (PanelDirection)Interop.Elementary.elm_panel_orient_get(RealHandle);
86             }
87             set
88             {
89                 Interop.Elementary.elm_panel_orient_set(RealHandle, (int)value);
90             }
91         }
92
93         /// <summary>
94         /// Toggled will be triggered when toggles Panel.
95         /// </summary>
96         public event EventHandler Toggled;
97
98         /// <summary>
99         /// Enable or disable scrolling in the Panel.
100         /// </summary>
101         /// <param name="enable">
102         /// Bool value can be false or true.
103         /// </param>
104         public void SetScrollable(bool enable)
105         {
106             Interop.Elementary.elm_panel_scrollable_set(RealHandle, enable);
107         }
108
109         /// <summary>
110         /// Sets the scroll size of Panel.
111         /// </summary>
112         /// <param name="ratio">
113         /// The size of scroll area.
114         /// </param>
115         public void SetScrollableArea(double ratio)
116         {
117             Interop.Elementary.elm_panel_scrollable_content_size_set(RealHandle, ratio);
118         }
119
120         /// <summary>
121         /// Toggles the hidden state of the Panel.
122         /// </summary>
123         public void Toggle()
124         {
125             Interop.Elementary.elm_panel_toggle(RealHandle);
126         }
127
128         /// <summary>
129         /// Creates a widget handle.
130         /// </summary>
131         /// <param name="parent">Parent EvasObject</param>
132         /// <returns>Handle IntPtr</returns>
133         protected override IntPtr CreateHandle(EvasObject parent)
134         {
135             IntPtr handle = Interop.Elementary.elm_layout_add(parent);
136             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
137
138             RealHandle = Interop.Elementary.elm_panel_add(handle);
139             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
140
141             return handle;
142         }
143
144         #region IScroller Implementation
145
146         /// <summary>
147         /// Scrolled will be triggered when the content has been scrolled.
148         /// </summary>
149         public event EventHandler Scrolled
150         {
151             add => _scroller.Scrolled += value;
152             remove => _scroller.Scrolled -= value;
153         }
154
155         /// <summary>
156         /// DragStart will be triggered when dragging the contents around has started.
157         /// </summary>
158         public event EventHandler DragStart
159         {
160             add => _scroller.DragStart += value;
161             remove => _scroller.DragStart -= value;
162         }
163
164         /// <summary>
165         /// DragStop will be triggered when dragging the contents around has stopped.
166         /// </summary>
167         public event EventHandler DragStop
168         {
169             add => _scroller.DragStop += value;
170             remove => _scroller.DragStop -= value;
171         }
172
173         /// <summary>
174         /// PageScrolled will be triggered when the visible page has changed.
175         /// </summary>
176         public event EventHandler PageScrolled
177         {
178             add => _scroller.PageScrolled += value;
179             remove => _scroller.PageScrolled -= value;
180         }
181
182         /// <summary>
183         /// Gets the current region in the content object that is visible through the Scroller.
184         /// </summary>
185         public Rect CurrentRegion => _scroller.CurrentRegion;
186
187         /// <summary>
188         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
189         /// </summary>
190         /// <remarks>
191         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
192         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
193         /// </remarks>
194         public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
195         {
196             get => _scroller.HorizontalScrollBarVisiblePolicy;
197             set => _scroller.HorizontalScrollBarVisiblePolicy = value;
198         }
199
200         /// <summary>
201         /// Sets or gets the value of VerticalScrollBarVisiblePolicy
202         /// </summary>
203         /// <remarks>
204         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
205         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
206         /// </remarks>
207         public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
208         {
209             get => _scroller.VerticalScrollBarVisiblePolicy;
210             set => _scroller.VerticalScrollBarVisiblePolicy = value;
211         }
212
213         /// <summary>
214         /// Sets or gets the value of ScrollBlock.
215         /// </summary>
216         /// <remarks>
217         /// This function will block scrolling movement  in a given direction.One can disable movements in the X axis, the Y axis or both.
218         /// The default value is ScrollBlock.None, where movements are allowed in both directions.
219         /// </remarks>
220         public ScrollBlock ScrollBlock
221         {
222             get => _scroller.ScrollBlock;
223             set => _scroller.ScrollBlock = value;
224         }
225
226         /// <summary>
227         /// Sets or gets scroll current page number.
228         /// </summary>
229         /// <remarks>
230         /// Current page means the page which meets the top of the viewport.
231         /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
232         /// The page number starts from 0. 0 is the first page.
233         /// </remarks>
234         public int VerticalPageIndex => _scroller.VerticalPageIndex;
235
236         /// <summary>
237         /// Sets or gets scroll current page number.
238         /// </summary>
239         /// <remarks>
240         /// Current page means the page which meets the left of the viewport.
241         /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
242         /// The page number starts from 0. 0 is the first page.
243         /// </remarks>
244         public int HorizontalPageIndex => _scroller.HorizontalPageIndex;
245
246         /// <summary>
247         /// Sets or gets the maximum limit of the movable page at vertical direction.
248         /// </summary>
249         public int VerticalPageScrollLimit
250         {
251             get => _scroller.VerticalPageScrollLimit;
252             set => _scroller.VerticalPageScrollLimit = value;
253         }
254
255         /// <summary>
256         /// Sets or gets the maximum limit of the movable page at horizontal direction.
257         /// </summary>
258         public int HorizontalPageScrollLimit
259         {
260             get => _scroller.HorizontalPageScrollLimit;
261             set => _scroller.HorizontalPageScrollLimit = value;
262         }
263
264         /// <summary>
265         /// Sets or gets the vertical bounce behaviour.
266         /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
267         /// This is a visual way to indicate the end has been reached.
268         /// This is enabled by default for both axis.
269         /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
270         /// </summary>
271         public bool VerticalBounce
272         {
273             get => _scroller.VerticalBounce;
274             set => _scroller.VerticalBounce = value;
275         }
276
277         /// <summary>
278         /// Sets or gets the horizontal bounce behaviour.
279         /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
280         /// This is a visual way to indicate the end has been reached.
281         /// This is enabled by default for both axis.
282         /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
283         /// </summary>
284         public bool HorizontalBounce
285         {
286             get => _scroller.HorizontalBounce;
287             set => _scroller.HorizontalBounce = value;
288         }
289
290         /// <summary>
291         /// Gets the width of the content object of the scroller.
292         /// </summary>
293         public int ChildWidth
294         {
295             get => _scroller.ChildWidth;
296         }
297
298         /// <summary>
299         /// Gets the height of the content object of the scroller.
300         /// </summary>
301         public int ChildHeight
302         {
303             get => _scroller.ChildHeight;
304         }
305
306         /// <summary>
307         /// Set scrolling gravity values for a scroller.
308         /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
309         /// The scroller will adjust the view to glue itself as follows.
310         /// 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
311         /// Default values for x and y are 0.0
312         /// </summary>
313         public double HorizontalGravity
314         {
315             get => _scroller.HorizontalGravity;
316             set => _scroller.HorizontalGravity = value;
317         }
318
319         /// <summary>
320         /// Set scrolling gravity values for a scroller.
321         /// The gravity, defines how the scroller will adjust its view when the size of the scroller contents increase.
322         /// The scroller will adjust the view to glue itself as follows.
323         /// 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
324         /// Default values for x and y are 0.0
325         /// </summary>
326         public double VerticalGravity
327         {
328             get => _scroller.VerticalGravity;
329             set => _scroller.VerticalGravity = value;
330         }
331
332         /// <summary>
333         /// Get scroll last page number.
334         /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
335         /// </summary>
336         public int LastVerticalPageNumber => _scroller.LastVerticalPageNumber;
337
338         /// <summary>
339         /// Get scroll last page number.
340         /// The page number starts from 0. 0 is the first page. This returns the last page number among the pages.
341         /// </summary>
342         public int LastHorizontalPageNumber => _scroller.LastHorizontalPageNumber;
343
344         /// <summary>
345         /// Set an infinite loop_ for a scroller.
346         /// This function sets the infinite loop vertically.
347         /// If the content is set, it will be shown repeatedly.
348         /// </summary>
349         public bool VerticalLoop
350         {
351             get => _scroller.VerticalLoop;
352             set => _scroller.VerticalLoop = value;
353         }
354
355         /// <summary>
356         /// Set an infinite loop_ for a scroller.
357         /// This function sets the infinite loop horizontally.
358         /// If the content is set, it will be shown repeatedly.
359         /// </summary>
360         public bool HorizontalLoop
361         {
362             get => _scroller.HorizontalLoop;
363             set => _scroller.HorizontalLoop = value;
364         }
365
366         /// <summary>
367         /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
368         /// </summary>
369         public int HorizontalPageSize
370         {
371             get => _scroller.HorizontalPageSize;
372             set => _scroller.HorizontalPageSize = value;
373         }
374
375         /// <summary>
376         /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
377         /// </summary>
378         public int VerticalPageSize
379         {
380             get => _scroller.VerticalPageSize;
381             set => _scroller.VerticalPageSize = value;
382         }
383
384         /// <summary>
385         /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
386         /// </summary>
387         public double VerticalRelativePageSize
388         {
389             get => _scroller.VerticalRelativePageSize;
390             set => _scroller.VerticalRelativePageSize = value;
391         }
392
393         /// <summary>
394         /// Gets or sets a given scroller widget's scrolling page size, relative to its viewport size.
395         /// </summary>
396         public double HorizontalRelativePageSize
397         {
398             get => _scroller.HorizontalRelativePageSize;
399             set => _scroller.HorizontalRelativePageSize = value;
400         }
401
402         /// <summary>
403         /// Gets or Sets the page snapping behavior of a scroller.
404         /// </summary>
405         /// <remarks>
406         /// When scrolling, if a scroller is paged (see VerticalRelativePageSize),
407         /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
408         /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
409         /// This function will set if it that is enabled or not, for each axis.
410         /// </remarks>
411         public bool VerticalSnap
412         {
413             get => _scroller.VerticalSnap;
414             set => _scroller.VerticalSnap = value;
415         }
416
417         /// <summary>
418         /// Gets or Sets the page snapping behavior of a scroller.
419         /// </summary>
420         /// <remarks>
421         /// When scrolling, if a scroller is paged (see HorizontalRelativePageSize),
422         /// the scroller may snap to pages when being scrolled, i.e., even if it had momentum to scroll further,
423         /// it will stop at the next page boundaries. This is disabled, by default, for both axis.
424         /// This function will set if it that is enabled or not, for each axis.
425         /// </remarks>
426         public bool HorizontalSnap
427         {
428             get => _scroller.HorizontalSnap;
429             set => _scroller.HorizontalSnap = value;
430         }
431
432         /// <summary>
433         /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
434         /// </summary>
435         public int PageHeight
436         {
437             get => _scroller.PageHeight;
438             set => _scroller.PageHeight = value;
439         }
440
441         /// <summary>
442         /// Gets or sets the page size to an absolute fixed value, with 0 turning it off for that axis.
443         /// </summary>
444         public int PageWidth
445         {
446             get => _scroller.PageWidth;
447             set => _scroller.PageWidth = value;
448         }
449
450         /// <summary>
451         /// Gets or sets the step size to move scroller by key event.
452         /// </summary>
453         public int HorizontalStepSize
454         {
455             get => _scroller.HorizontalStepSize;
456             set => _scroller.HorizontalStepSize = value;
457         }
458
459         /// <summary>
460         /// Gets or sets the step size to move scroller by key event.
461         /// </summary>
462         public int VerticalStepSize
463         {
464             get => _scroller.VerticalStepSize;
465             set => _scroller.VerticalStepSize = value;
466         }
467
468         /// <summary>
469         /// Gets or sets a value whether mouse wheel is enabled or not over the scroller.
470         /// </summary>
471         public bool WheelDisabled
472         {
473             get => _scroller.WheelDisabled;
474             set => _scroller.WheelDisabled = value;
475         }
476
477         /// <summary>
478         /// Gets or sets the type of single direction scroll.
479         /// </summary>
480         public ScrollSingleDirection SingleDirection
481         {
482             get => _scroller.SingleDirection;
483             set => _scroller.SingleDirection = value;
484         }
485
486         /// <summary>
487         /// Sets the scroller minimum size limited to the minimum size of the content.
488         /// By default the scroller will be as small as its design allows, irrespective of its content.
489         /// This will make the scroller minimum size the right size horizontally and/or vertically to perfectly fit its content in that direction.
490         /// </summary>
491         /// <param name="horizontal">Enable limiting minimum size horizontally</param>
492         /// <param name="vertical">Enable limiting minimum size vertically</param>
493         public void MinimumLimit(bool horizontal, bool vertical)
494         {
495             _scroller.MinimumLimit(horizontal, vertical);
496         }
497
498         /// <summary>
499         /// Shows a specific virtual region within the scroller content object by the page number.
500         /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
501         /// </summary>
502         /// <param name="horizontalPageIndex">The horizontal page number.</param>
503         /// <param name="verticalPageIndex">The vertical page number.</param>
504         /// <param name="animated">True means slider with animation.</param>
505         public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
506         {
507             _scroller.ScrollTo(horizontalPageIndex, verticalPageIndex, animated);
508         }
509
510         /// <summary>
511         /// Shows a specific virtual region within the scroller content object.
512         /// </summary>
513         /// <remarks>
514         /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
515         /// starting at the top-left of the virtual content object) is shown within the scroller.
516         /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
517         /// (if configuration in general calls for transitions).
518         /// It may not jump immediately to the new location and may take a while and show other content along the way.
519         /// </remarks>
520         /// <param name="region">Rect struct of region.</param>
521         /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
522         public void ScrollTo(Rect region, bool animated)
523         {
524             _scroller.ScrollTo(region, animated);
525         }
526
527         #endregion
528     }
529 }