c9c21428e20c97f8f032f825d5be512ddfa78a82
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Box.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     public class Box : Container
22     {
23         private Interop.Elementary.BoxLayoutCallback _layoutCallback;
24
25         public Box(EvasObject parent) : base(parent)
26         {
27         }
28
29         public bool IsHorizontal
30         {
31             get
32             {
33                 return Interop.Elementary.elm_box_horizontal_get(RealHandle);
34             }
35             set
36             {
37                 Interop.Elementary.elm_box_horizontal_set(RealHandle, value);
38             }
39         }
40
41         public void PackEnd(EvasObject content)
42         {
43             Interop.Elementary.elm_box_pack_end(RealHandle, content);
44             AddChild(content);
45         }
46
47         public void PackStart(EvasObject content)
48         {
49             Interop.Elementary.elm_box_pack_start(RealHandle, content);
50             AddChild(content);
51         }
52
53         public void PackAfter(EvasObject content, EvasObject after)
54         {
55             Interop.Elementary.elm_box_pack_after(RealHandle, content, after);
56             AddChild(content);
57         }
58
59         public void UnPack(EvasObject content)
60         {
61             Interop.Elementary.elm_box_unpack(RealHandle, content);
62             RemoveChild(content);
63         }
64
65         public void UnPackAll()
66         {
67             Interop.Elementary.elm_box_unpack_all(RealHandle);
68             ClearChildren();
69         }
70
71         public void SetLayoutCallback(Action action)
72         {
73             _layoutCallback = (obj, priv, data) =>
74             {
75                 action();
76             };
77             Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null);
78         }
79
80         public override void SetPartColor(string part, Color color)
81         {
82             Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
83                                                                               color.G * color.A / 255,
84                                                                               color.B * color.A / 255,
85                                                                               color.A);
86         }
87
88         public override Color GetPartColor(string part)
89         {
90             int r, g, b, a;
91             Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
92             return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
93         }
94
95         protected override IntPtr CreateHandle(EvasObject parent)
96         {
97             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
98             Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
99
100             RealHandle = Interop.Elementary.elm_box_add(handle);
101             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
102
103             return handle;
104         }
105     }
106 }