From a1eefaecd520368b7133a4d88c049b810cbb3274 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 27 Aug 2023 12:14:34 +0100 Subject: [PATCH] NWidgetStacked: Allow treating planes independentally for layout --- src/widget.cpp | 10 ++++++++-- src/widget_type.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index 9be5f982d4..523c604e49 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1360,7 +1360,10 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array) this->fill_y = (this->head != nullptr) ? 1 : 0; this->resize_x = (this->head != nullptr) ? 1 : 0; this->resize_y = (this->head != nullptr) ? 1 : 0; - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { + int plane = 0; + for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) { + if (this->independent_planes && plane != this->shown_plane) continue; + child_wid->SetupSmallestSize(w, init_array); this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal()); @@ -1379,7 +1382,10 @@ void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint if (this->shown_plane >= SZSP_BEGIN) return; - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { + int plane = 0; + for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) { + if (this->independent_planes && plane != this->shown_plane) continue; + uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing); 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); diff --git a/src/widget_type.h b/src/widget_type.h index 1affc39040..788803507d 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -481,6 +481,7 @@ public: int shown_plane; ///< Plane being displayed (for #NWID_SELECTION only). int index; ///< If non-negative, index in the #Window::nested_array. + bool independent_planes = false; ///< If true, treat planes as independent for layout purposes. }; /** Nested widget container flags, */