Fix #11655: Crash due to NWidgetMatrix modifying widget->index. (#11657)

NWidgetMatrix modifies its child widget's index to indicate which element
is to be drawn, which now causes issues with code that does not know about
stuffing extra data into the index.

Instead, let NWidgetMatrix store the currently processing element, and
retrieve this information from the matrix widget while child widgets are
being drawn.

This means only widgets that are children of NWidgetMatrix need to know
anything about their extra data.
This commit is contained in:
2023-12-30 18:24:26 +00:00
committed by GitHub
parent 1e60734660
commit 6215e9bf77
5 changed files with 40 additions and 35 deletions

View File

@@ -564,6 +564,7 @@ public:
void SetClicked(int clicked);
void SetCount(int count);
void SetScrollbar(Scrollbar *sb);
int GetCurrentElement() const;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
@@ -574,8 +575,9 @@ public:
protected:
WidgetID index; ///< If non-negative, index in the #Window::widget_lookup.
Colours colour; ///< Colour of this widget.
int clicked; ///< The currently clicked widget.
int count; ///< Amount of valid widgets.
int clicked; ///< The currently clicked element.
int count; ///< Amount of valid elements.
int current_element; ///< The element currently being processed.
Scrollbar *sb; ///< The scrollbar we're associated with.
private:
int widget_w; ///< The width of the child widget including inter spacing.