void Box::Layout() { if (m_children.size() == 0) return; PreferredSize(); const Point boxSize = GetSize(); Point::Component vc, fc; GetComponentsForOrient(m_orient == BOX_HORIZONTAL, vc, fc); // fast path. we know the exact size that everything wants, so just // loop and hand it out if (m_numVariable == 0) { Point childPos(0), childSize(0); for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { childSize[fc] = boxSize[fc]; childSize[vc] = (*i).contribSize[vc]; const Point actualSize(CalcSize((*i).widget, childSize)); SetWidgetDimensions((*i).widget, childPos, actualSize); childPos[vc] += actualSize[vc] + m_spacing; } } // we have one or more children that have requested the maximum size // possible. each with a known size gets it, and any remaining space is // distributed evenly among the max-sized children. if there is no // remaining space, then we're already outside the bounds, so just give // them something else { const int sizeAvail = boxSize[vc]; const int sizeMin = sizeAvail/10; // 10%, as good as anything const int amount = m_minAllocation < sizeAvail ? std::max((sizeAvail-m_minAllocation-m_spacing*(int(m_children.size())-1))/m_numVariable, sizeMin) : sizeMin; Point childPos(0), childSize(0); for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { childSize[fc] = boxSize[fc]; childSize[vc] = (*i).contribSize[vc] == SIZE_EXPAND ? amount : (*i).contribSize[vc]; const Point actualSize(CalcSize((*i).widget, childSize)); SetWidgetDimensions((*i).widget, childPos, actualSize); childPos[vc] += actualSize[vc] + m_spacing; } } LayoutChildren(); }
/*----------------------------------------------------------------------*/ /* extern */ void XfeComboBoxAddItem(Widget w,XmString item,int position) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* XmListPart * lp = _XfeXmListPart(w); */ assert( _XfeIsAlive(w) ); assert( XfeIsComboBox(w) ); XmListAddItem(cp->list,item,position); #if 0 DtComboBoxWidget combo = (DtComboBoxWidget)combo_w; DtComboBoxPart *combo_p = (DtComboBoxPart*)&(combo->combo_box); XmStringTable list_items = ((XmListWidget)combo_p->list)->list.items; int i; if (item && ((XmListWidget)combo_p->list)->list.itemCount) { for (i = 0; i < combo_p->item_count; i++) if (XmStringCompare(item, list_items[i])) break; if ((i < combo_p->item_count) && unique) return; } XmListAddItem(combo_p->list, item, pos); SyncWithList(combo_p); if (combo_p->label) { SetMaximumLabelSize(combo_p); if (combo_p->type == XmDROP_DOWN_LIST_BOX) { ClearShadow(combo, TRUE); if (combo_p->recompute_size) SetComboBoxSize(combo); LayoutChildren(combo); DrawShadow(combo); } } if (combo_p->type == XmDROP_DOWN_COMBO_BOX) SetTextFieldData(combo_p, NULL); else SetLabelData(combo_p, NULL, FALSE); #endif }
void ff::ViewWindow::Layout() { #if !METRO_APP noAssertRet(_allowLayout); assertRet(IsValid()); noAssertRet(IsActive()); _allowLayout = false; HWND parent = ::GetParent(Handle()); RectInt windowRect = ff::GetClientRect(parent); SetWindowPos(Handle(), HWND_TOP, windowRect, SWP_SHOWWINDOW); LayoutChildren(); _allowLayout = true; #endif }
void Grid::Layout() { const Point size = GetSize(); Point childPos, childSize; for (unsigned int rowNum = 0; rowNum < m_numRows; rowNum++) { childSize.y = m_colSpec.cellPercent[rowNum]*size.y; childPos.x = 0; for (unsigned int colNum = 0; colNum < m_numCols; colNum++) { childSize.x = m_rowSpec.cellPercent[colNum]*size.x; const unsigned int n = rowNum*m_numCols+colNum; if (m_widgets[n]) SetWidgetDimensions(m_widgets[n], childPos, childSize); childPos.x += childSize.x; } childPos.y += childSize.y; } LayoutChildren(); }
void Layer::Layout() { LayoutChildren(); }
void Box::Layout() { if (m_children.size() == 0) return; PreferredSize(); const Point boxSize = GetSize(); Point::Component vc, fc; GetComponentsForOrient(m_orient == BOX_HORIZONTAL, vc, fc); float sizeRemaining = boxSize[vc] - (m_spacing * (m_children.size()-1)); Point childPos(0); // the largest equal share each child can have const float maxChildSize = boxSize[vc]/m_children.size(); for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { (*i).padding = 0; float childSize = 0; // if we have enough room to give _everyone_ what they want, do it if (boxSize[vc] >= m_preferredSize[vc]) childSize = (*i).preferredSize[vc]; // if this child wants less than their share, give it to them else if (maxChildSize >= (*i).preferredSize[vc]) childSize = (*i).preferredSize[vc]; // otherwise they get their share else childSize = maxChildSize; (*i).size[vc] = childSize; (*i).size[fc] = boxSize[fc]; sizeRemaining -= childSize; if (m_countExpanded == 0) { SetWidgetDimensions((*i).widget, childPos, (*i).size); childPos[vc] += childSize + m_spacing; } } if (m_countExpanded > 0) { int candidates = m_countExpanded; while (candidates > 0 && sizeRemaining > 0 && !is_zero_general(sizeRemaining)) { float allocation = sizeRemaining / candidates; for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { if (!((*i).flags & BOX_EXPAND)) continue; float amountAdded; if (!((*i).flags & BOX_FILL)) { (*i).padding += allocation * 0.5; amountAdded = allocation; } else { (*i).size[vc] += allocation; amountAdded = allocation; } sizeRemaining -= amountAdded; } } for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { Point pos = childPos; pos[vc] += (*i).padding; SetWidgetDimensions((*i).widget, pos, (*i).size); childPos[vc] = pos[vc] + (*i).size[vc] + (*i).padding + m_spacing; } } LayoutChildren(); }
void Box::Layout() { if (m_children.empty()) return; PreferredSize(); const Point& boxSize = GetSize(); Point::Component vc, fc; GetComponentsForOrient(m_orient == BOX_HORIZONTAL, vc, fc); // fast path. we know the exact size that everything wants, so just // loop and hand it out if (m_numVariable == 0) { // we got what we asked for so everyone can have what they want if (boxSize[vc] >= m_preferredSize[vc]) { for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { (*i).size[fc] = boxSize[fc]; (*i).size[vc] = (*i).contribSize[vc]; } } // didn't get enough, so we have share it around else { // we can certainly afford to give everyone this much int availSize = boxSize[vc] - (m_spacing * (m_children.size()-1)); int minSize = availSize / m_children.size(); int remaining = availSize; int wantMore = 0; // loop and hand it out for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { (*i).size[fc] = boxSize[fc]; (*i).size[vc] = std::min(minSize, (*i).contribSize[vc]); remaining -= (*i).size[vc]; // if this one didn't get us much as it wanted then count it // if we have any left over we can give it some more if ((*i).size[vc] < (*i).contribSize[vc]) wantMore++; } // if there's some remaining and not everyone got what they wanted, hand it out assert(remaining >= 0); if (remaining && wantMore) { int extra = remaining / wantMore; for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { if ((*i).size[vc] < (*i).contribSize[vc]) (*i).size[vc] += extra; } } } } // we have one or more children that have requested the maximum size possible else { int availSize = boxSize[vc] - (m_spacing * (m_children.size()-1)); int remaining = availSize; // fixed ones first if (m_children.size() > m_numVariable) { // distribute evenly among the fixed ones int minSize = availSize / (m_children.size() - m_numVariable); // loop and hand it out for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { // don't give any to expanding ones yet if ((*i).contribSize[vc] == SIZE_EXPAND) continue; (*i).size[fc] = boxSize[fc]; (*i).size[vc] = std::min(minSize, (*i).contribSize[vc]); remaining -= (*i).size[vc]; } } // if there's any space remaining, distribute it among the expanding widgets assert(remaining >= 0); if (remaining) { int extra = remaining / m_numVariable; for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { if ((*i).contribSize[vc] != SIZE_EXPAND) continue; (*i).size[fc] = boxSize[fc]; (*i).size[vc] = extra; } } } // now loop over them again and position Point childPos(0); for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { const Point actualSize((*i).widget->CalcSize((*i).size)); SetWidgetDimensions((*i).widget, childPos, actualSize); childPos[vc] += actualSize[vc] + m_spacing; } LayoutChildren(); }