/*------------------------------------------------------------------------------
 src/lib/djWidget/stackLayout.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djLayout.h"

namespace dj {

StackLayout::StackLayout(LayoutItem * parent) :
  Layout(parent)
{}

const Vec2i StackLayout::sizeHint() const
{
  DJ_DBG_FNC("dj::StackLayout::sizeHint");
  
  Vec2i out;
  for (ConstListIt<LayoutItem *> it = itemList(); it.isValid(); ++it)
    out = max(it()->sizeHint(), out);
  
  out = out + margin() * 2;
  DJ_DBG_PRN("out = " << out);
  return out;
}

void StackLayout::resize(int x, int y, int w, int h)
{
  Layout::resize(x, y, w, h);

  DJ_DBG_FNC("dj::StackLayout::resize");
  DJ_DBG_PRN("in = " << Box2i(x, y, w, h));
  
  const int _x = x + margin();
  const int _y = y + margin();
  const int _w = w - margin() * 2;
  const int _h = h - margin() * 2;
  for (ConstListIt<LayoutItem *> it = itemList(); it.isValid(); ++it)
    it()->resize(_x, _y, _w, _h);
}

}
