+ int x, y, w, h; // working area
+ x = y = _bevel;
+ w = _area.width() - _borderwidth * 2 - _bevel * 2;
+ h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
+
+ int free = w - (visible.size() - 1) * _bevel;
+ if (free < 0) free = 0;
+ int each;
+
+ std::list<Widget*> adjustable;
+
+ // find the 'free' space, and how many children will be using it
+ for (it = visible.begin(), end = visible.end(); it != end; ++it) {
+ free -= (*it)->minSize().width();
+ if (free < 0) free = 0;
+ if ((*it)->maxSize().width() - (*it)->minSize().width() > 0)
+ adjustable.push_back(*it);
+ }
+ // some widgets may have max widths that restrict them, find the 'true'
+ // amount of free space after these widgets are not included
+ if (!adjustable.empty()) {
+ do {
+ each = free / adjustable.size();
+ for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
+ std::list<Widget*>::iterator next = it; ++next;
+ int m = (*it)->maxSize().width() - (*it)->minSize().width();
+ if (m > 0 && m < each) {
+ free -= m;
+ if (free < 0) free = 0;
+ adjustable.erase(it);
+ break; // if one is found to be fixed, then the free space needs to
+ // change, and the rest need to be reexamined
+ }
+ it = next;
+ }
+ } while (it != end && !adjustable.empty());
+ }
+
+ // place/size the widgets
+ if (!adjustable.empty())
+ each = free / adjustable.size();
+ else
+ each = 0;
+ for (it = visible.begin(), end = visible.end(); it != end; ++it) {
+ int w;
+ // is the widget adjustable?
+ std::list<Widget*>::const_iterator
+ found = std::find(adjustable.begin(), adjustable.end(), *it);
+ if (found != adjustable.end()) {
+ // adjustable
+ w = (*it)->minSize().width() + each;
+ } else {
+ // fixed
+ w = (*it)->minSize().width();
+ }
+ // align it vertically
+ int yy = y;
+ int hh = std::max(std::min(h, (*it)->_max_size.height()),
+ (*it)->_min_size.height());
+ if (hh < h) {
+ switch(_alignment) {
+ case RenderStyle::RightBottomJustify:
+ yy += h - hh;
+ break;
+ case RenderStyle::CenterJustify:
+ yy += (h - hh) / 2;
+ break;
+ case RenderStyle::LeftTopJustify:
+ break;
+ }
+ }
+ (*it)->internal_moveresize(x, yy, w, hh);
+ (*it)->render();
+ (*it)->layout();
+ x += w + _bevel;
+ }