Merge "[NUI] suuport NUIWatchApplication for watchface app"
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Container.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 using System.Collections.Generic;
19
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// It inherits <see cref="Widget"/>.
24     /// The Container is a abstract class.
25     /// Other class inherits it to Elementary is about displaying
26     /// its widgets in a nice layout.
27     /// </summary>
28     /// <since_tizen> preview </since_tizen>
29     public abstract class Container : Widget
30     {
31         HashSet<EvasObject> _children = new HashSet<EvasObject>();
32
33         /// <summary>
34         /// Creates and initializes a new instance of class which inherit from Container.
35         /// </summary>
36         /// <param name="parent">The parent is a given object which will be attached by Container
37         /// as a child.It's <see cref="EvasObject"/> type.</param>
38         /// <since_tizen> preview </since_tizen>
39         public Container(EvasObject parent) : base(parent)
40         {
41         }
42
43         /// <summary>
44         /// Creates and initializes a new instance of Container class.
45         /// </summary>
46         /// <since_tizen> preview </since_tizen>
47         protected Container() : base()
48         {
49         }
50
51         /// <summary>
52         /// Sets the background color of a given Container.
53         /// </summary>
54         /// <since_tizen> preview </since_tizen>
55         public override Color BackgroundColor
56         {
57             set
58             {
59                 if (value.IsDefault)
60                 {
61                     SetPartColor("bg", Color.Transparent);
62                 }
63                 else
64                 {
65                     SetPartColor("bg", value);
66                 }
67                 _backgroundColor = value;
68             }
69         }
70
71         /// <summary>
72         /// Gets the collection of child EvasObject of the Container.
73         /// </summary>
74         /// <since_tizen> preview </since_tizen>
75         protected IEnumerable<EvasObject> Children => _children;
76
77         /// <summary>
78         /// Add an EvasObject object as a child of Container.
79         /// </summary>
80         /// <param name="obj">The EvasObject object to be added</param>
81         /// <since_tizen> preview </since_tizen>
82         protected void AddChild(EvasObject obj)
83         {
84             _children.Add(obj);
85             obj.Deleted += OnChildDeleted;
86         }
87
88         /// <summary>
89         /// Remove an EvasObject object as a child of Container.
90         /// </summary>
91         /// <param name="obj">The EvasObject object to be removed</param>
92         /// <since_tizen> preview </since_tizen>
93         protected void RemoveChild(EvasObject obj)
94         {
95             _children.Remove(obj);
96         }
97
98         /// <summary>
99         /// Clear all children of the Container.
100         /// </summary>
101         /// <since_tizen> preview </since_tizen>
102         protected void ClearChildren()
103         {
104             _children.Clear();
105         }
106
107         /// <summary>
108         /// The Container Callback that is invoked when a child is removed.
109         /// </summary>
110         /// <param name="sender">The called Container</param>
111         /// <param name="a"><see cref="EventArgs"/></param>
112         void OnChildDeleted(object sender, EventArgs a)
113         {
114             _children.Remove((EvasObject)sender);
115         }
116     }
117 }