From e8db1371350f360acc30663ff58d157e961ec27e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 2 Nov 2023 23:23:50 +0000 Subject: [PATCH] Codechange: Move test for Container WidgetType to helper function. --- src/widget.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index fa91b1f66d..fc50a8da7d 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -3233,6 +3233,17 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg return nwid_begin; } +/** + * Test if WidgetType is a container widget. + * @param tp WidgetType to test. + * @return True iff WidgetType is a container widget. + */ +bool IsContainerWidgetType(WidgetType tp) +{ + return tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX + || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION; +} + /** * Build a nested widget tree by recursively filling containers with nested widgets read from their parts. * @param nwid_begin Pointer to beginning of nested widget parts. @@ -3259,9 +3270,7 @@ static const NWidgetPart *MakeWidgetTree(const NWidgetPart *nwid_begin, const NW if (sub_widget == nullptr) break; /* If sub-widget is a container, recursively fill that container. */ - WidgetType tp = sub_widget->type; - if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX - || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) { + if (fill_sub && IsContainerWidgetType(sub_widget->type)) { NWidgetBase *sub_ptr = sub_widget; nwid_begin = MakeWidgetTree(nwid_begin, nwid_end, &sub_ptr, biggest_index); }