mirror of https://github.com/OpenTTD/OpenTTD
Change: Use RectPadding Horizontal()/Vertical() helpers.
parent
04cbe57d2a
commit
dd9f6bc803
|
@ -126,7 +126,7 @@ public:
|
|||
/* First initialise some variables... */
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->SetupSmallestSize(w, init_array);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||
}
|
||||
|
||||
/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
|
||||
|
|
|
@ -1613,13 +1613,13 @@ public:
|
|||
this->acs->SetupSmallestSize(w, init_array);
|
||||
this->inf->SetupSmallestSize(w, init_array);
|
||||
|
||||
uint min_avs_width = this->avs->smallest_x + this->avs->padding.left + this->avs->padding.right;
|
||||
uint min_acs_width = this->acs->smallest_x + this->acs->padding.left + this->acs->padding.right;
|
||||
uint min_inf_width = this->inf->smallest_x + this->inf->padding.left + this->inf->padding.right;
|
||||
uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
|
||||
uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
|
||||
uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
|
||||
|
||||
uint min_avs_height = this->avs->smallest_y + this->avs->padding.top + this->avs->padding.bottom;
|
||||
uint min_acs_height = this->acs->smallest_y + this->acs->padding.top + this->acs->padding.bottom;
|
||||
uint min_inf_height = this->inf->smallest_y + this->inf->padding.top + this->inf->padding.bottom;
|
||||
uint min_avs_height = this->avs->smallest_y + this->avs->padding.Vertical();
|
||||
uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
|
||||
uint min_inf_height = this->inf->smallest_y + this->inf->padding.Vertical();
|
||||
|
||||
/* Smallest window is in two column mode. */
|
||||
this->smallest_x = std::max(min_avs_width, min_acs_width) + INTER_COLUMN_SPACING + min_inf_width;
|
||||
|
@ -1649,9 +1649,9 @@ public:
|
|||
{
|
||||
this->StoreSizePosition(sizing, x, y, given_width, given_height);
|
||||
|
||||
uint min_avs_width = this->avs->smallest_x + this->avs->padding.left + this->avs->padding.right;
|
||||
uint min_acs_width = this->acs->smallest_x + this->acs->padding.left + this->acs->padding.right;
|
||||
uint min_inf_width = this->inf->smallest_x + this->inf->padding.left + this->inf->padding.right;
|
||||
uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
|
||||
uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
|
||||
uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
|
||||
|
||||
uint min_list_width = std::max(min_avs_width, min_acs_width); // Smallest width of the lists such that they have equal width (incl padding).
|
||||
uint avs_extra_width = min_list_width - min_avs_width; // Additional width needed for avs to reach min_list_width.
|
||||
|
@ -1687,10 +1687,10 @@ public:
|
|||
avs_width = ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
|
||||
|
||||
uint acs_width = given_width - // Remaining space, including horizontal padding.
|
||||
inf_width - this->inf->padding.left - this->inf->padding.right -
|
||||
avs_width - this->avs->padding.left - this->avs->padding.right - 2 * INTER_COLUMN_SPACING;
|
||||
inf_width - this->inf->padding.Horizontal() -
|
||||
avs_width - this->avs->padding.Horizontal() - 2 * INTER_COLUMN_SPACING;
|
||||
acs_width = ComputeMaxSize(min_acs_width, acs_width, this->acs->GetHorizontalStepSize(sizing)) -
|
||||
this->acs->padding.left - this->acs->padding.right;
|
||||
this->acs->padding.Horizontal();
|
||||
|
||||
/* Never use fill_y on these; the minimal size is chosen, so that the 3 column view looks nice */
|
||||
uint avs_height = ComputeMaxSize(this->avs->smallest_y, given_height, this->avs->resize_y);
|
||||
|
@ -1726,8 +1726,8 @@ public:
|
|||
uint acs_width = ComputeMaxSize(this->acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
|
||||
this->acs->GetHorizontalStepSize(sizing));
|
||||
|
||||
uint min_avs_height = (!this->editable) ? 0 : this->avs->smallest_y + this->avs->padding.top + this->avs->padding.bottom + INTER_LIST_SPACING;
|
||||
uint min_acs_height = this->acs->smallest_y + this->acs->padding.top + this->acs->padding.bottom;
|
||||
uint min_avs_height = (!this->editable) ? 0 : this->avs->smallest_y + this->avs->padding.Vertical() + INTER_LIST_SPACING;
|
||||
uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
|
||||
uint extra_height = given_height - min_acs_height - min_avs_height;
|
||||
|
||||
/* Never use fill_y on these; instead use the INTER_LIST_SPACING as filler */
|
||||
|
@ -1754,9 +1754,9 @@ public:
|
|||
} else {
|
||||
this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
|
||||
}
|
||||
uint dx = this->acs->current_x + this->acs->padding.left + this->acs->padding.right;
|
||||
uint dx = this->acs->current_x + this->acs->padding.Horizontal();
|
||||
if (this->editable) {
|
||||
dx = std::max(dx, this->avs->current_x + this->avs->padding.left + this->avs->padding.right);
|
||||
dx = std::max(dx, this->avs->current_x + this->avs->padding.Horizontal());
|
||||
}
|
||||
x += dx + INTER_COLUMN_SPACING + this->inf->padding.left;
|
||||
this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
|
||||
|
|
|
@ -1354,10 +1354,10 @@ public:
|
|||
/* First initialise some variables... */
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->SetupSmallestSize(w, init_array);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||
if (this->IsButton(child_wid->type)) {
|
||||
nbuttons++;
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.left + child_wid->padding.right);
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
|
||||
} else if (child_wid->type == NWID_SPACER) {
|
||||
this->spacers++;
|
||||
}
|
||||
|
|
|
@ -1124,8 +1124,8 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
|
|||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->SetupSmallestSize(w, init_array);
|
||||
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.left + child_wid->padding.right);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom);
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||
this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
|
||||
this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
|
||||
this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
|
||||
|
@ -1142,11 +1142,11 @@ void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
|||
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
|
||||
uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.left - child_wid->padding.right, hor_step);
|
||||
uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
|
||||
uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
|
||||
|
||||
uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
|
||||
uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.top - child_wid->padding.bottom, vert_step);
|
||||
uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
|
||||
uint child_pos_y = child_wid->padding.top;
|
||||
|
||||
child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
|
||||
|
@ -1269,7 +1269,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
|
|||
child_wid->SetupSmallestSize(w, init_array);
|
||||
longest = std::max(longest, child_wid->smallest_x);
|
||||
max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom);
|
||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||
}
|
||||
/* 1b. Make the container higher if needed to accommodate all children nicely. */
|
||||
[[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
|
||||
|
@ -1277,7 +1277,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
|
|||
for (;;) {
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
|
||||
uint child_height = child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom;
|
||||
uint child_height = child_wid->smallest_y + child_wid->padding.Vertical();
|
||||
if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
|
||||
uint remainder = (cur_height - child_height) % step_size;
|
||||
if (remainder > 0) { // Child did not fit entirely, widen the container.
|
||||
|
@ -1305,7 +1305,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
|
|||
child_wid->padding.right += this->pip_post;
|
||||
}
|
||||
|
||||
this->smallest_x += child_wid->smallest_x + child_wid->padding.left + child_wid->padding.right;
|
||||
this->smallest_x += child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||
if (child_wid->fill_x > 0) {
|
||||
if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
|
||||
}
|
||||
|
@ -1329,7 +1329,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
|||
if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
|
||||
/* For EQUALSIZE containers this does not sum to smallest_x during initialisation */
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
additional_length -= child_wid->smallest_x + child_wid->padding.right + child_wid->padding.left;
|
||||
additional_length -= child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||
}
|
||||
} else {
|
||||
additional_length -= this->smallest_x;
|
||||
|
@ -1363,7 +1363,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
|||
}
|
||||
|
||||
uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
|
||||
child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.top - child_wid->padding.bottom, vert_step);
|
||||
child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
|
||||
}
|
||||
|
||||
/* First.5 loop: count how many children are of the biggest step size. */
|
||||
|
@ -1415,7 +1415,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
|||
uint child_y = y + child_wid->padding.top;
|
||||
|
||||
child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
|
||||
uint padded_child_width = child_width + child_wid->padding.right + child_wid->padding.left;
|
||||
uint padded_child_width = child_width + child_wid->padding.Horizontal();
|
||||
position = rtl ? position - padded_child_width : position + padded_child_width;
|
||||
|
||||
child_wid = child_wid->next;
|
||||
|
@ -1454,7 +1454,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
|
|||
child_wid->SetupSmallestSize(w, init_array);
|
||||
highest = std::max(highest, child_wid->smallest_y);
|
||||
max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.left + child_wid->padding.right);
|
||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
|
||||
}
|
||||
/* 1b. Make the container wider if needed to accommodate all children nicely. */
|
||||
[[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
|
||||
|
@ -1462,7 +1462,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
|
|||
for (;;) {
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
|
||||
uint child_width = child_wid->smallest_x + child_wid->padding.left + child_wid->padding.right;
|
||||
uint child_width = child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||
if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
|
||||
uint remainder = (cur_width - child_width) % step_size;
|
||||
if (remainder > 0) { // Child did not fit entirely, widen the container.
|
||||
|
@ -1490,7 +1490,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
|
|||
child_wid->padding.bottom += this->pip_post;
|
||||
}
|
||||
|
||||
this->smallest_y += child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom;
|
||||
this->smallest_y += child_wid->smallest_y + child_wid->padding.Vertical();
|
||||
if (child_wid->fill_y > 0) {
|
||||
if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
|
||||
}
|
||||
|
@ -1514,7 +1514,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
|||
if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
|
||||
/* For EQUALSIZE containers this does not sum to smallest_y during initialisation */
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
additional_length -= child_wid->smallest_y + child_wid->padding.top + child_wid->padding.bottom;
|
||||
additional_length -= child_wid->smallest_y + child_wid->padding.Vertical();
|
||||
}
|
||||
} else {
|
||||
additional_length -= this->smallest_y;
|
||||
|
@ -1539,7 +1539,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
|||
}
|
||||
|
||||
uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
|
||||
child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.left - child_wid->padding.right, hor_step);
|
||||
child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
|
||||
}
|
||||
|
||||
/* First.5 loop: count how many children are of the biggest step size. */
|
||||
|
@ -1589,7 +1589,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
|||
uint child_height = child_wid->current_y;
|
||||
|
||||
child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding.top, child_wid->current_x, child_height, rtl);
|
||||
position += child_height + child_wid->padding.top + child_wid->padding.bottom;
|
||||
position += child_height + child_wid->padding.Vertical();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1950,8 +1950,8 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
|
|||
this->child->padding.top = std::max((int)WD_FRAMETEXT_TOP, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP / 2 : 0);
|
||||
this->child->padding.bottom = WD_FRAMETEXT_BOTTOM;
|
||||
|
||||
this->smallest_x += this->child->padding.left + this->child->padding.right;
|
||||
this->smallest_y += this->child->padding.top + this->child->padding.bottom;
|
||||
this->smallest_x += this->child->padding.Horizontal();
|
||||
this->smallest_y += this->child->padding.Vertical();
|
||||
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
|
||||
|
@ -1962,8 +1962,8 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
|
|||
this->child->padding.top = WD_BEVEL_TOP;
|
||||
this->child->padding.bottom = WD_BEVEL_BOTTOM;
|
||||
|
||||
this->smallest_x += this->child->padding.left + this->child->padding.right;
|
||||
this->smallest_y += this->child->padding.top + this->child->padding.bottom;
|
||||
this->smallest_x += this->child->padding.Horizontal();
|
||||
this->smallest_y += this->child->padding.Vertical();
|
||||
}
|
||||
} else {
|
||||
Dimension d = {this->min_x, this->min_y};
|
||||
|
@ -1996,8 +1996,8 @@ void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
|||
|
||||
if (this->child != nullptr) {
|
||||
uint x_offset = (rtl ? this->child->padding.right : this->child->padding.left);
|
||||
uint width = given_width - this->child->padding.right - this->child->padding.left;
|
||||
uint height = given_height - this->child->padding.top - this->child->padding.bottom;
|
||||
uint width = given_width - this->child->padding.Horizontal();
|
||||
uint height = given_height - this->child->padding.Vertical();
|
||||
this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding.top, width, height, rtl);
|
||||
}
|
||||
}
|
||||
|
@ -2927,7 +2927,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
|||
}
|
||||
|
||||
case WPT_PADDING:
|
||||
if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left);
|
||||
if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding);
|
||||
break;
|
||||
|
||||
case WPT_PIPSPACE: {
|
||||
|
|
|
@ -156,6 +156,16 @@ public:
|
|||
this->AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional space (padding) around the widget.
|
||||
* @param padding Amount of padding around the widget.
|
||||
*/
|
||||
inline void SetPadding(const RectPadding &padding)
|
||||
{
|
||||
this->uz_padding = padding;
|
||||
this->AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
inline uint GetHorizontalStepSize(SizingType sizing) const;
|
||||
inline uint GetVerticalStepSize(SizingType sizing) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue