Ejemplo n.º 1
0
void HKWidgetListbox::ArrangeChildren()
{
	// early out?
	int numChildren = GetNumChildren();
	if(numChildren == 0)
		return;

	MFVector pPos = orientation == Horizontal ? MakeVector(padding.x + scrollOffset, padding.y) : MakeVector(padding.x, padding.y + scrollOffset);
	MFVector pSize = MakeVector(size.x - (padding.x + padding.z), size.y - (padding.y + padding.w));

	contentSize = 0.f;

	for(int a=0; a<numChildren; ++a)
	{
		HKWidget *pWidget = GetChild(a);
		if(pWidget->GetVisible() == Gone)
			continue;

		const MFVector &cMargin = pWidget->GetLayoutMargin();
		const MFVector &cSize = pWidget->GetSize();

		MFVector tPos = pPos + MakeVector(cMargin.x, cMargin.y);
		MFVector tSize = MFMax(pSize - MakeVector(cMargin.x + cMargin.z, cMargin.y + cMargin.w), MFVector::zero);

		if(orientation == Horizontal)
		{
			float itemSize = cSize.x + cMargin.x + cMargin.z;
			contentSize += itemSize;
			pPos.x += itemSize;
			pWidget->SetPosition(tPos);
			pWidget->SetHeight(tSize.y);
		}
		else
		{
			float itemSize = cSize.y + cMargin.y + cMargin.w;
			contentSize += itemSize;
			pPos.y += itemSize;
			pWidget->SetPosition(tPos);
			pWidget->SetWidth(tSize.x);
		}
	}
}