Release 4.0.0-preview1-00051
[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
48     {
49         SmartEvent _toggled;
50
51         /// <summary>
52         /// Creates and initializes a new instance of Panel class.
53         /// </summary>
54         /// <param name="parent">The EvasObject to which the new Panel will be attached as a child.</param>
55         public Panel(EvasObject parent) : base(parent)
56         {
57             _toggled = new SmartEvent(this, this.RealHandle, "toggled");
58             _toggled.On += (s, e) => Toggled?.Invoke(this, EventArgs.Empty);
59         }
60
61         /// <summary>
62         /// Sets or gets the hidden status of a given Panel widget.
63         /// </summary>
64         public bool IsOpen
65         {
66             get
67             {
68                 return !Interop.Elementary.elm_panel_hidden_get(RealHandle);
69             }
70             set
71             {
72                 Interop.Elementary.elm_panel_hidden_set(RealHandle, !value);
73             }
74         }
75
76         /// <summary>
77         /// Sets or gets the direction of a given Panel widget.
78         /// </summary>
79         public PanelDirection Direction
80         {
81             get
82             {
83                 return (PanelDirection)Interop.Elementary.elm_panel_orient_get(RealHandle);
84             }
85             set
86             {
87                 Interop.Elementary.elm_panel_orient_set(RealHandle, (int)value);
88             }
89         }
90
91         /// <summary>
92         /// Toggled will be triggered when toggles Panel.
93         /// </summary>
94         public event EventHandler Toggled;
95
96         /// <summary>
97         /// Enable or disable scrolling in the Panel.
98         /// </summary>
99         /// <param name="enable">
100         /// Bool value can be false or true.
101         /// </param>
102         public void SetScrollable(bool enable)
103         {
104             Interop.Elementary.elm_panel_scrollable_set(RealHandle, enable);
105         }
106
107         /// <summary>
108         /// Sets the scroll size of Panel.
109         /// </summary>
110         /// <param name="ratio">
111         /// The size of scroll area.
112         /// </param>
113         public void SetScrollableArea(double ratio)
114         {
115             Interop.Elementary.elm_panel_scrollable_content_size_set(RealHandle, ratio);
116         }
117
118         /// <summary>
119         /// Toggles the hidden state of the Panel.
120         /// </summary>
121         public void Toggle()
122         {
123             Interop.Elementary.elm_panel_toggle(RealHandle);
124         }
125
126         protected override IntPtr CreateHandle(EvasObject parent)
127         {
128             IntPtr handle = Interop.Elementary.elm_layout_add(parent);
129             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
130
131             RealHandle = Interop.Elementary.elm_panel_add(handle);
132             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
133
134             return handle;
135         }
136     }
137 }