using System;
namespace Gwen.Control.Layout
{
///
/// Base splitter class.
///
public class Splitter : Base
{
private readonly Base[] m_Panel;
private readonly bool[] m_Scale;
///
/// Initializes a new instance of the class.
///
/// Parent control.
public Splitter(Base parent) : base(parent)
{
m_Panel = new Base[2];
m_Scale = new bool[2];
m_Scale[0] = true;
m_Scale[1] = true;
}
///
/// Sets the contents of a splitter panel.
///
/// Panel index (0-1).
/// Panel contents.
/// Determines whether the content is to be scaled.
public void SetPanel(int panelIndex, Base panel, bool noScale = false)
{
if (panelIndex < 0 || panelIndex > 1)
throw new ArgumentException("Invalid panel index", "panelIndex");
m_Panel[panelIndex] = panel;
m_Scale[panelIndex] = !noScale;
if (null != m_Panel[panelIndex])
{
m_Panel[panelIndex].Parent = this;
}
}
///
/// Gets the contents of a secific panel.
///
/// Panel index (0-1).
///
Base GetPanel(int panelIndex)
{
if (panelIndex < 0 || panelIndex > 1)
throw new ArgumentException("Invalid panel index", "panelIndex");
return m_Panel[panelIndex];
}
///
/// Lays out the control's interior according to alignment, padding, dock etc.
///
/// Skin to use.
protected override void Layout(Skin.Base skin)
{
LayoutVertical(skin);
}
protected virtual void LayoutVertical(Skin.Base skin)
{
int w = Width;
int h = Height;
if (m_Panel[0] != null)
{
Margin m = m_Panel[0].Margin;
if (m_Scale[0])
m_Panel[0].SetBounds(m.Left, m.Top, w - m.Left - m.Right, (h*0.5f) - m.Top - m.Bottom);
else
m_Panel[0].Position(Pos.Center, 0, (int) (h*-0.25f));
}
if (m_Panel[1] != null)
{
Margin m = m_Panel[1].Margin;
if (m_Scale[1])
m_Panel[1].SetBounds(m.Left, m.Top + (h*0.5f), w - m.Left - m.Right, (h*0.5f) - m.Top - m.Bottom);
else
m_Panel[1].Position(Pos.Center, 0, (int) (h*0.25f));
}
}
protected virtual void LayoutHorizontal(Skin.Base skin)
{
throw new NotImplementedException();
}
}
}