using System;
using ElmSharp;
using EBox = ElmSharp.Box;
namespace Xamarin.Forms.Platform.Tizen.Native
{
///
/// Extends the ElmSharp.Box class with functionality useful to Xamarin.Forms renderer.
///
///
/// This class overrides the layout mechanism. Instead of using the native layout,
/// LayoutUpdated event is sent.
///
public class Box : EBox
{
///
/// The last processed geometry of the Box which was reported from the native layer.
///
Rect _previousGeometry;
///
/// Initializes a new instance of the class.
///
/// The parent EvasObject.
public Box(EvasObject parent) : base(parent)
{
SetLayoutCallback(() => { NotifyOnLayout(); });
}
///
/// Notifies that the layout has been updated.
///
public event EventHandler LayoutUpdated;
///
/// Triggers the LayoutUpdated event.
///
///
/// This method is called whenever there is a possibility that the size and/or position has been changed.
///
void NotifyOnLayout()
{
var g = Geometry;
if (0 == g.Width || 0 == g.Height)
{
// ignore irrelevant dimensions
return;
}
if (null != LayoutUpdated)
{
LayoutUpdated(this, new LayoutEventArgs()
{
HasChanged = g != _previousGeometry,
X = g.X,
Y = g.Y,
Width = g.Width,
Height = g.Height,
}
);
}
_previousGeometry = g;
}
}
}