Release 4.0.0-preview1-00337
[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     public abstract class Container : Widget
29     {
30         HashSet<EvasObject> _children = new HashSet<EvasObject>();
31
32         /// <summary>
33         /// Creates and initializes a new instance of class which inherit from Container.
34         /// </summary>
35         /// <param name="parent">The parent is a given object which will be attached by Container
36         /// as a child.It's <see cref="EvasObject"/> type.</param>
37         public Container(EvasObject parent) : base(parent)
38         {
39         }
40
41         /// <summary>
42         /// Creates and initializes a new instance of Container class.
43         /// </summary>
44         protected Container() : base()
45         {
46         }
47
48         /// <summary>
49         /// Sets the background color of a given Container.
50         /// </summary>
51         public override Color BackgroundColor
52         {
53             set
54             {
55                 if (value.IsDefault)
56                 {
57                     SetPartColor("bg", Color.Transparent);
58                 }
59                 else
60                 {
61                     SetPartColor("bg", value);
62                 }
63                 _backgroundColor = value;
64             }
65         }
66
67         /// <summary>
68         /// Gets the collection of child EvasObject of the Container.
69         /// </summary>
70         protected IEnumerable<EvasObject> Children => _children;
71
72         /// <summary>
73         /// Add an EvasObject object as a child of Container.
74         /// </summary>
75         /// <param name="obj">The EvasObject object to be added</param>
76         protected void AddChild(EvasObject obj)
77         {
78             _children.Add(obj);
79             obj.Deleted += OnChildDeleted;
80         }
81
82         /// <summary>
83         /// Remove an EvasObject object as a child of Container.
84         /// </summary>
85         /// <param name="obj">The EvasObject object to be removed</param>
86         protected void RemoveChild(EvasObject obj)
87         {
88             _children.Remove(obj);
89         }
90
91         /// <summary>
92         /// Clear all children of the Container.
93         /// </summary>
94         protected void ClearChildren()
95         {
96             _children.Clear();
97         }
98
99         /// <summary>
100         /// The Container Callback that is invoked when a child is removed.
101         /// </summary>
102         /// <param name="sender">The called Container</param>
103         /// <param name="a"><see cref="EventArgs"/></param>
104         void OnChildDeleted(object sender, EventArgs a)
105         {
106             _children.Remove((EvasObject)sender);
107         }
108     }
109 }