void RowFormWidget::UpdateLayout() { PixelRect current_rect = GetWindow().GetClientRect(); const unsigned total_width = current_rect.GetWidth(); const unsigned total_height = current_rect.GetHeight(); 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; int caption_width = -1; for (const auto &i : rows) { if (!i.IsAvailable(expert)) continue; min_height += i.GetMinimumHeight(look, vertical); if (i.IsElastic(look, vertical)) ++n_elastic; if (!vertical && i.type == Row::Type::EDIT) { int cw = i.GetControl().GetRecommendedCaptionWidth(); if (cw > caption_width) caption_width = cw; } } if (caption_width * 3 > int(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) { if (!i.IsAvailable(expert)) { i.Hide(); continue; } /* determine this row's height */ unsigned height = i.GetMinimumHeight(look, vertical); if (excess_height > 0 && i.IsElastic(look, vertical)) { 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 unsigned max_height = i.GetMaximumHeight(look, vertical); if (height > max_height) { /* never grow beyond declared maximum height */ grow_height = max_height - height + grow_height; height = max_height; } excess_height -= grow_height; } --n_elastic; } NextControlRect(current_rect, height); i.UpdateLayout((ContainerWindow &)GetWindow(), current_rect, caption_width); } assert(excess_height == 0 || n_elastic == 0); }
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 (const auto &i : rows) { 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) { if (i.type == Row::Type::DUMMY) continue; /* 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; } if (i.type == Row::Type::WIDGET) { Widget &widget = i.GetWidget(); if (!i.available || (i.expert && !expert)) { widget.Hide(); continue; } /* TODO: visible check - hard to implement without remembering the control position, because Widget::Show() wants a PixelRect parameter */ NextControlRect(current_rect, height); if (!i.initialised) { i.initialised = true; widget.Initialise(*(ContainerWindow *)GetWindow(), current_rect); } if (!i.prepared) { i.prepared = true; widget.Prepare(*(ContainerWindow *)GetWindow(), current_rect); } widget.Show(current_rect); 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); /* finally move and resize */ NextControlRect(current_rect, height); window.Move(current_rect); } assert(excess_height == 0 || n_elastic == 0); }
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); }