/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
namespace ElmSharp
{
///
/// It inherits .
/// The Container is an abstract class.
/// The other class inherits it to elementary, which is about displaying
/// its widgets in a nice layout.
///
/// preview
public abstract class Container : Widget
{
HashSet _children = new HashSet();
///
/// Creates and initializes a new instance of the class, which inherit from the Container.
///
/// The parent is a given object, which will be attached by the Container
/// as a child. It's type.
/// preview
protected Container(EvasObject parent) : base(parent)
{
}
///
/// Creates and initializes a new instance of the Container class.
///
/// preview
protected Container()
{
}
///
/// Sets the background color of a given Container.
///
/// preview
public override Color BackgroundColor
{
set
{
if (value.IsDefault)
{
SetPartColor("bg", Color.Transparent);
}
else
{
SetPartColor("bg", value);
}
_backgroundColor = value;
}
}
///
/// Gets the collection of a child EvasObject of the Container.
///
/// preview
protected IEnumerable Children => _children;
///
/// Add the EvasObject object as a child of the Container.
///
/// The EvasObject object to be added.
/// preview
protected void AddChild(EvasObject obj)
{
_children.Add(obj);
obj.Deleted += OnChildDeleted;
}
///
/// Removes the EvasObject object as a child of the Container.
///
/// The EvasObject object to be removed.
/// preview
protected void RemoveChild(EvasObject obj)
{
_children.Remove(obj);
}
///
/// Clears all the children of the Container.
///
/// preview
protected void ClearChildren()
{
_children.Clear();
}
///
/// The Container callback that is invoked when a child is removed.
///
/// The called Container.
///
void OnChildDeleted(object sender, EventArgs a)
{
_children.Remove((EvasObject)sender);
}
}
}