From af41c5cb4edf51e7b2a8086cd7ebe9bfac1fe0cb Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 19 Oct 2023 19:50:43 +0100 Subject: [PATCH] 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. --- src/toolbar_gui.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 70a6ed2d21..17020c435b 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -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; }