using System.Collections.Generic;
using System.Collections.Specialized;
using ElmSharp;
namespace Xamarin.Forms.Platform.Tizen.Native
{
///
/// A Canvas provides a class which can be a container for other controls.
///
///
/// This class is used as a container view for Layouts from Xamarin.Forms.Platform.Tizen framework.
/// It is used for implementing xamarin pages and layouts.
///
public class Canvas : Box, IContainable
{
///
/// The list of Views.
///
readonly ObservableCollection _children = new ObservableCollection();
///
/// Initializes a new instance of the class.
///
/// Canvas doesn't support replacing its children, this will be ignored.
/// Parent of this instance.
public Canvas(EvasObject parent) : base(parent)
{
_children.CollectionChanged += (o, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var v in e.NewItems)
{
var view = v as EvasObject;
if (null != view)
{
OnAdd(view);
}
}
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
foreach (var v in e.OldItems)
{
var view = v as EvasObject;
if (null != view)
{
OnRemove(view);
}
}
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
{
OnRemoveAll();
}
};
}
///
/// Gets list of native elements that are placed in the canvas.
///
public IList Children
{
get
{
return _children;
}
}
///
/// Provides destruction for native element and contained elements.
///
protected override void OnUnrealize()
{
foreach (var child in _children)
{
child.Unrealize();
}
base.OnUnrealize();
}
///
/// Adds a new child to a container.
///
/// Native element which will be added
void OnAdd(EvasObject view)
{
PackEnd(view);
}
///
/// Removes a child from a container.
///
/// Child element to be removed from canvas
void OnRemove(EvasObject view)
{
UnPack(view);
}
///
/// Removes all children from a canvas.
///
void OnRemoveAll()
{
UnPackAll();
}
}
}