PixelSize RowFormWidget::GetMaximumSize() const { const UPixelScalar value_width = look.text_font->TextSize(_T("Foo Bar Foo Bar")).cx * 2; PixelSize size{ PixelScalar(GetRecommendedCaptionWidth() + value_width), 0 }; for (auto i = rows.begin(), end = rows.end(); i != end; ++i) size.cy += i->GetMaximumHeight(); return size; }
/** * Will this row grow when there is excess screen space? */ bool IsElastic(const DialogLook &look, bool vertical) const { return GetMaximumHeight(look, vertical) > GetMinimumHeight(look, vertical); }
void RowFormWidget::UpdateLayout() { PixelRect current_rect = GetWindow()->GetClientRect(); const unsigned total_width = current_rect.right - current_rect.left; const unsigned total_height = current_rect.bottom - current_rect.top; current_rect.bottom = current_rect.top; const bool expert = UIGlobals::GetDialogSettings().expert; /* first row traversal: count the number of "elastic" rows and determine the minimum total height */ unsigned min_height = 0; unsigned n_elastic = 0; unsigned caption_width = 0; for (auto i = rows.begin(), end = rows.end(); i != end; ++i) { if (!i->available || (i->expert && !expert)) continue; min_height += i->GetMinimumHeight(); if (i->IsElastic()) ++n_elastic; if (i->type == Row::Type::EDIT) { unsigned cw = i->GetControl().GetRecommendedCaptionWidth(); if (cw > caption_width) caption_width = cw; } } if (caption_width * 3 > total_width * 2) caption_width = total_width * 2 / 3; /* how much excess height in addition to the minimum height? */ unsigned excess_height = min_height < total_height ? total_height - min_height : 0; /* second row traversal: now move and resize the rows */ for (auto i = rows.begin(), end = rows.end(); i != end; ++i) { if (i->type == Row::Type::DUMMY) continue; Window &window = i->GetWindow(); if (!i->available) { window.Hide(); continue; } if (i->expert) { if (!expert) { window.Hide(); continue; } if (i->visible) window.Show(); } if (caption_width > 0 && i->type == Row::Type::EDIT && i->GetControl().HasCaption()) i->GetControl().SetCaptionWidth(caption_width); /* determine this row's height */ UPixelScalar height = i->GetMinimumHeight(); if (excess_height > 0 && i->IsElastic()) { assert(n_elastic > 0); /* distribute excess height among all elastic rows */ unsigned grow_height = excess_height / n_elastic; if (grow_height > 0) { height += grow_height; const UPixelScalar max_height = i->GetMaximumHeight(); if (height > max_height) { /* never grow beyond declared maximum height */ height = max_height; grow_height = max_height - height; } excess_height -= grow_height; } --n_elastic; } /* finally move and resize */ NextControlRect(current_rect, height); window.Move(current_rect); } assert(excess_height == 0 || n_elastic == 0); }
/** * Will this row grow when there is excess screen space? */ bool IsElastic() const { return GetMaximumHeight() > GetMinimumHeight(); }