Enhance Panes widget
[platform/core/csapi/elm-sharp.git] / ElmSharp / ElmSharp / Panes.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     /// The Panes is a widget that adds a draggable bar between two contents.
23     /// When dragged this bar resizes contents' size.
24     /// </summary>
25     public class Panes : Layout
26     {
27         SmartEvent _press;
28         SmartEvent _unpressed;
29
30         /// <summary>
31         /// Creates and initializes a new instance of the Panes class.
32         /// </summary>
33         /// <param name="parent">The EvasObject to which the new Panes will be attached as a child.</param>
34         public Panes(EvasObject parent) : base(parent)
35         {
36             _press = new SmartEvent(this, this.RealHandle, "press");
37             _unpressed = new SmartEvent(this, this.RealHandle, "unpressed");
38
39             _press.On += (s, e) => Pressed?.Invoke(this, e);
40             _unpressed.On += (s, e) => Unpressed?.Invoke(this, e);
41         }
42
43         /// <summary>
44         /// Pressed will be triggered when panes have been pressed (button isn't released yet).
45         /// </summary>
46         public event EventHandler Pressed;
47
48         /// <summary>
49         /// Unpressed will be triggered when panes are released after being pressed.
50         /// </summary>
51         public event EventHandler Unpressed;
52
53         /// <summary>
54         /// Sets or gets resize mode of a given Panes widget.
55         /// True means the left and right panes resize homogeneously.
56         /// </summary>
57         public bool IsFixed
58         {
59             get
60             {
61                 return Interop.Elementary.elm_panes_fixed_get(RealHandle);
62             }
63             set
64             {
65                 Interop.Elementary.elm_panes_fixed_set(RealHandle, value);
66             }
67         }
68
69         /// <summary>
70         /// Sets or Gets the size proportion of the Panes widget's left side.
71         /// </summary>
72         /// <remarks>
73         /// By default it's homogeneous, i.e., both sides have the same size.If something different is required,
74         /// it can be set with this function. For example, if the left content should be displayed over 75% of the panes size,
75         /// size should be passed as 0.75. This way, the right content is resized to 25% of the panes size.
76         /// If displayed vertically, left content is displayed at the top, and right content at the bottom.
77         /// This proportion changes when the user drags the panes bar.
78         ///
79         /// The value is float type and between 0.0 and 1.0 representing the size proportion of the left side.
80         /// </remarks>
81         public double Proportion
82         {
83             get
84             {
85                 return Interop.Elementary.elm_panes_content_left_size_get(RealHandle);
86             }
87             set
88             {
89                 Interop.Elementary.elm_panes_content_left_size_set(RealHandle, value);
90             }
91         }
92
93         /// <summary>
94         /// Sets or gets the orientation of a given Panes widget.
95         /// </summary>
96         /// <remarks>
97         /// Uses this function to change how your panes are to be disposed: vertically or horizontally.
98         /// By default it's displayed horizontally.
99         /// </remarks>
100         public bool IsHorizontal
101         {
102             get
103             {
104                 return Interop.Elementary.elm_panes_horizontal_get(RealHandle);
105             }
106             set
107             {
108                 Interop.Elementary.elm_panes_horizontal_set(RealHandle, value);
109             }
110         }
111
112         public int LeftMinimumSize
113         {
114             get
115             {
116                 return Interop.Elementary.elm_panes_content_left_min_size_get(RealHandle);
117             }
118             set
119             {
120                 Interop.Elementary.elm_panes_content_left_min_size_set(RealHandle, value);
121             }
122         }
123
124         public double LeftMinimumRelativeSize
125         {
126             get
127             {
128                 return Interop.Elementary.elm_panes_content_left_min_relative_size_get(RealHandle);
129             }
130             set
131             {
132                 Interop.Elementary.elm_panes_content_left_min_relative_size_set(RealHandle, value);
133             }
134         }
135
136         public int RightMinimumSize
137         {
138             get
139             {
140                 return Interop.Elementary.elm_panes_content_right_min_size_get(RealHandle);
141             }
142             set
143             {
144                 Interop.Elementary.elm_panes_content_right_min_size_set(RealHandle, value);
145             }
146         }
147
148         public double RightMinimumRelativeSize
149         {
150             get
151             {
152                 return Interop.Elementary.elm_panes_content_right_min_relative_size_get(RealHandle);
153             }
154             set
155             {
156                 Interop.Elementary.elm_panes_content_right_min_relative_size_set(RealHandle, value);
157             }
158         }
159
160         protected override IntPtr CreateHandle(EvasObject parent)
161         {
162             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
163             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
164
165             RealHandle = Interop.Elementary.elm_panes_add(handle);
166             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
167
168             return handle;
169         }
170     }
171 }