本文整理汇总了C++中Control::DesiredSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Control::DesiredSize方法的具体用法?C++ Control::DesiredSize怎么用?C++ Control::DesiredSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Control
的用法示例。
在下文中一共展示了Control::DesiredSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Arrange
void Grid::Arrange(const Rect finalRect) {
Cell* cell;
Control* el;
for (Grid::CellData& d : els) {
cell = GetCell(d.row, d.col);
el = d.el;
Point pos(GetCellPos(d.row, d.col));
int elDx = el->DesiredSize().Width;
int containerDx = 0;
for (int i = d.col; i < d.col + d.colSpan; i++) {
containerDx += maxColWidth[i];
}
int xOff = d.horizAlign.CalcOffset(elDx, containerDx);
pos.X += xOff;
int elDy = el->DesiredSize().Height;
int containerDy = maxRowHeight[d.row];
int yOff = d.vertAlign.CalcOffset(elDy, containerDy);
pos.Y += yOff;
Rect r(pos, cell->desiredSize);
el->Arrange(r);
}
SetPosition(finalRect);
}
示例2: Measure
Size Grid::Measure(const Size availableSize) {
RebuildCellDataIfNeeded();
Size borderSize(GetBorderAndPaddingSize(cachedStyle));
Cell* cell;
Control* el;
for (Grid::CellData& d : els) {
cell = GetCell(d.row, d.col);
cell->desiredSize.Width = 0;
cell->desiredSize.Height = 0;
el = d.el;
if (!el->IsVisible())
continue;
// calculate max dx of each column (dx of widest cell in the row)
// and max dy of each row (dy of tallest cell in the column)
el->Measure(availableSize);
// TODO: take cell's border and padding into account
cell->desiredSize = el->DesiredSize();
// if a cell spans multiple columns, we don't count its size here
if (d.colSpan == 1) {
if (cell->desiredSize.Width > maxColWidth[d.col])
maxColWidth[d.col] = cell->desiredSize.Width;
}
if (cell->desiredSize.Height > maxRowHeight[d.row])
maxRowHeight[d.row] = cell->desiredSize.Height;
}
// account for cells with colSpan > 1. If cell.dx > total dx
// of columns it spans, we widen the columns by equally
// re-distributing the difference among columns
for (Grid::CellData& d : els) {
if (d.colSpan == 1)
continue;
cell = GetCell(d.row, d.col);
int totalDx = 0;
for (int i = d.col; i < d.col + d.colSpan; i++) {
totalDx += maxColWidth[i];
}
int diff = cell->desiredSize.Width - totalDx;
if (diff > 0) {
int diffPerCol = diff / d.colSpan;
int rest = diff % d.colSpan;
// note: we could try to redistribute rest for ideal sizing instead of
// over-sizing but not sure if that would matter in practice
if (rest > 0)
diffPerCol += 1;
CrashIf(diffPerCol * d.colSpan < diff);
for (int i = d.col; i < d.col + d.colSpan; i++) {
maxColWidth[i] += diffPerCol;
}
}
}
int desiredWidth = 0;
int desiredHeight = 0;
for (int row = 0; row < rows; row++) {
desiredHeight += maxRowHeight[row];
}
for (int col = 0; col < cols; col++) {
desiredWidth += maxColWidth[col];
}
// TODO: what to do if desired size is more than availableSize?
desiredSize.Width = desiredWidth + borderSize.Width;
desiredSize.Height = desiredHeight + borderSize.Height;
return desiredSize;
}