mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 07:21:53 +00:00
Codechange: Hide toolbar buttons by setting width to zero.
Zero-width is how widgets are hidden elsewhere. This removes the need for an extra array to lookup if a button is hidden.
This commit is contained in:
parent
81ecbaaa33
commit
af41c5cb4e
@ -1358,7 +1358,6 @@ static MenuClickedProc * const _menu_clicked_procs[] = {
|
||||
|
||||
/** Full blown container to make it behave exactly as we want :) */
|
||||
class NWidgetToolbarContainer : public NWidgetContainer {
|
||||
bool visible[WID_TN_END]; ///< The visible headers
|
||||
protected:
|
||||
uint spacers; ///< Number of spacer widgets in this toolbar
|
||||
|
||||
@ -1420,16 +1419,13 @@ public:
|
||||
this->current_y = given_height;
|
||||
|
||||
/* Figure out what are the visible buttons */
|
||||
memset(this->visible, 0, sizeof(this->visible));
|
||||
uint arrangable_count, button_count, spacer_count;
|
||||
const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
|
||||
for (uint i = 0; i < arrangable_count; i++) {
|
||||
this->visible[arrangement[i]] = true;
|
||||
}
|
||||
|
||||
/* Create us ourselves a quick lookup table */
|
||||
NWidgetBase *widgets[WID_TN_END];
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
|
||||
if (child_wid->type == NWID_SPACER) continue;
|
||||
widgets[((NWidgetCore*)child_wid)->index] = child_wid;
|
||||
}
|
||||
@ -1461,6 +1457,8 @@ public:
|
||||
child_wid->current_x = button_space / (button_count - button_i);
|
||||
button_space -= child_wid->current_x;
|
||||
button_i++;
|
||||
} else {
|
||||
child_wid->current_x = child_wid->smallest_x;
|
||||
}
|
||||
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
|
||||
position += child_wid->current_x;
|
||||
@ -1481,9 +1479,6 @@ public:
|
||||
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
|
||||
if (child_wid->type == NWID_SPACER) continue;
|
||||
if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
|
||||
|
||||
child_wid->Draw(w);
|
||||
}
|
||||
}
|
||||
@ -1493,9 +1488,6 @@ public:
|
||||
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
|
||||
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
if (child_wid->type == NWID_SPACER) continue;
|
||||
if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
|
||||
|
||||
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
|
||||
if (nwid != nullptr) return nwid;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user