//-----------------------------------------------------------------------------
// Purpose: Callback for when the panel size has been changed
//-----------------------------------------------------------------------------
void EditablePanel::OnSizeChanged(int wide, int tall)
{
	BaseClass::OnSizeChanged(wide, tall);
	InvalidateLayout();

	int dx = wide - _baseWide;
	int dy = tall - _baseTall;

	for (int i = 0; i < GetChildCount(); i++)
	{
		// perform auto-layout on the child panel
		Panel *child = GetChild(i);

		int x, y, w, t;
		child->GetBounds(x, y, w, t);

		if (child->GetPinCorner() == PIN_TOPRIGHT || child->GetPinCorner() == PIN_BOTTOMRIGHT)
		{
			// move along with the right edge
			x += dx;
		}

		if (child->GetPinCorner() == PIN_BOTTOMLEFT || child->GetPinCorner() == PIN_BOTTOMRIGHT)
		{
			// move along with the lower edge
			y += dy;
		}

		// check for resize
		if (child->GetAutoResize() == AUTORESIZE_RIGHT || child->GetAutoResize() == AUTORESIZE_DOWNANDRIGHT)
		{
			w += dx;
		}

		if (child->GetAutoResize() == AUTORESIZE_DOWN || child->GetAutoResize() == AUTORESIZE_DOWNANDRIGHT)
		{
			t += dy;
		}

		// make sure the child isn't too big...
		if(x+w>wide)
		{
			continue;
		}
		
		if(y+t>tall)
		{
			continue;
		}

		child->SetBounds(x, y, w, t);
		child->InvalidateLayout();
	}
	Repaint();

	// update the baselines
	_baseWide = wide;
	_baseTall = tall;
}
//-----------------------------------------------------------------------------
// Purpose: Callback for when the panel size has been changed
//-----------------------------------------------------------------------------
void EditablePanel::OnSizeChanged(int wide, int tall)
{
	BaseClass::OnSizeChanged(wide, tall);
	InvalidateLayout();

	for (int i = 0; i < GetChildCount(); i++)
	{
		// perform auto-layout on the child panel
		Panel *child = GetChild(i);
		if ( !child )
			continue;

		int x, y, w, h;
		child->GetBounds( x, y, w, h );

		int px, py;
		child->GetPinOffset( px, py );

		int ox, oy;
		child->GetResizeOffset( ox, oy );

		int ex;
		int ey;

		AutoResize_e resize = child->GetAutoResize(); 
		bool bResizeHoriz = ( resize == AUTORESIZE_RIGHT || resize == AUTORESIZE_DOWNANDRIGHT );
		bool bResizeVert = ( resize == AUTORESIZE_DOWN || resize == AUTORESIZE_DOWNANDRIGHT );

		PinCorner_e pinCorner = child->GetPinCorner();
		if ( pinCorner == PIN_TOPRIGHT || pinCorner == PIN_BOTTOMRIGHT )
		{
			// move along with the right edge
			ex = wide + px;
			x = bResizeHoriz ? ox : ex - w;
		}
		else
		{
			x = px;
			ex = bResizeHoriz ? wide + ox : px + w;
		}

		if ( pinCorner == PIN_BOTTOMLEFT || pinCorner == PIN_BOTTOMRIGHT )
		{
			// move along with the right edge
			ey = tall + py;
			y = bResizeVert ? oy : ey - h;
		}
		else
		{
			y = py;
			ey = bResizeVert ? tall + oy : py + h;
		}

		// Clamp..
		if ( ex < x )
		{
			ex = x;
		}
		if ( ey < y )
		{
			ey = y;
		}

		child->SetBounds( x, y, ex - x, ey - y );
		child->InvalidateLayout();
	}
	Repaint();
}