mirror of https://github.com/OpenTTD/OpenTTD
Change: Add flag to apply resize to largest resize step first.
Resize step is normally allocated equally amongst all resizable widgets. With this flag, we allocate as much as possible from the largest resize step first.pull/9994/head
parent
dc1b84aa1e
commit
ba94efba87
|
@ -1356,7 +1356,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
if (hor_step > 0) {
|
if (hor_step > 0) {
|
||||||
num_changing_childs++;
|
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
||||||
biggest_stepsize = std::max(biggest_stepsize, hor_step);
|
biggest_stepsize = std::max(biggest_stepsize, hor_step);
|
||||||
} else {
|
} else {
|
||||||
child_wid->current_x = child_wid->smallest_x;
|
child_wid->current_x = child_wid->smallest_x;
|
||||||
|
@ -1366,6 +1366,16 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
||||||
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_top - child_wid->padding_bottom, vert_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* First.5 loop: count how many children are of the biggest step size. */
|
||||||
|
if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
|
if (hor_step == biggest_stepsize) {
|
||||||
|
num_changing_childs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
|
/* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
|
||||||
while (biggest_stepsize > 0) {
|
while (biggest_stepsize > 0) {
|
||||||
uint next_biggest_stepsize = 0;
|
uint next_biggest_stepsize = 0;
|
||||||
|
@ -1383,6 +1393,16 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui
|
||||||
next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
|
next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
|
||||||
}
|
}
|
||||||
biggest_stepsize = next_biggest_stepsize;
|
biggest_stepsize = next_biggest_stepsize;
|
||||||
|
|
||||||
|
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
|
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
||||||
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
|
if (hor_step == biggest_stepsize) {
|
||||||
|
num_changing_childs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert(num_changing_childs == 0);
|
assert(num_changing_childs == 0);
|
||||||
|
|
||||||
|
@ -1512,7 +1532,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
if (vert_step > 0) {
|
if (vert_step > 0) {
|
||||||
num_changing_childs++;
|
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
||||||
biggest_stepsize = std::max(biggest_stepsize, vert_step);
|
biggest_stepsize = std::max(biggest_stepsize, vert_step);
|
||||||
} else {
|
} else {
|
||||||
child_wid->current_y = child_wid->smallest_y;
|
child_wid->current_y = child_wid->smallest_y;
|
||||||
|
@ -1522,6 +1542,16 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
||||||
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_left - child_wid->padding_right, hor_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* First.5 loop: count how many children are of the biggest step size. */
|
||||||
|
if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
|
if (vert_step == biggest_stepsize) {
|
||||||
|
num_changing_childs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
|
/* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
|
||||||
while (biggest_stepsize > 0) {
|
while (biggest_stepsize > 0) {
|
||||||
uint next_biggest_stepsize = 0;
|
uint next_biggest_stepsize = 0;
|
||||||
|
@ -1539,6 +1569,16 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
||||||
next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
|
next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
|
||||||
}
|
}
|
||||||
biggest_stepsize = next_biggest_stepsize;
|
biggest_stepsize = next_biggest_stepsize;
|
||||||
|
|
||||||
|
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
|
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
||||||
|
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||||
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
|
if (vert_step == biggest_stepsize) {
|
||||||
|
num_changing_childs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert(num_changing_childs == 0);
|
assert(num_changing_childs == 0);
|
||||||
|
|
||||||
|
|
|
@ -458,9 +458,11 @@ public:
|
||||||
/** Nested widget container flags, */
|
/** Nested widget container flags, */
|
||||||
enum NWidContainerFlags {
|
enum NWidContainerFlags {
|
||||||
NCB_EQUALSIZE = 0, ///< Containers should keep all their (resizing) children equally large.
|
NCB_EQUALSIZE = 0, ///< Containers should keep all their (resizing) children equally large.
|
||||||
|
NCB_BIGFIRST = 1, ///< Allocate space to biggest resize first.
|
||||||
|
|
||||||
NC_NONE = 0, ///< All flags cleared.
|
NC_NONE = 0, ///< All flags cleared.
|
||||||
NC_EQUALSIZE = 1 << NCB_EQUALSIZE, ///< Value of the #NCB_EQUALSIZE flag.
|
NC_EQUALSIZE = 1 << NCB_EQUALSIZE, ///< Value of the #NCB_EQUALSIZE flag.
|
||||||
|
NC_BIGFIRST = 1 << NCB_BIGFIRST, ///< Value of the #NCB_BIGFIRST flag.
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(NWidContainerFlags)
|
DECLARE_ENUM_AS_BIT_SET(NWidContainerFlags)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue