Changeset - r28348:9ebffeb7fcc0
[Not reviewed]
master
0 9 0
Peter Nelson - 5 months ago 2023-12-29 14:27:04
peter1138@openttd.org
Codechange: Remove deferred nested_array initialization path. (#11640)

Having two ways (`FillNestedArray` and `SetupSmallestSize`) to initialize
`Window::nested_array` introduces confusion.

Instead, make `FillNestedArray` the canonical way, always call it, and remove
init_array from `SetupSmallestSize`.
9 files changed with 48 insertions and 83 deletions:
0 comments (0 inline, 0 general)
src/fios_gui.cpp
Show inline comments
 
@@ -323,13 +323,13 @@ public:
 
					NOT_REACHED();
 
			}
 
		}
 
		this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
 
		this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
 

	
 
		this->CreateNestedTree(true);
 
		this->CreateNestedTree();
 
		if (this->fop == SLO_LOAD && this->abstract_filetype == FT_SAVEGAME) {
 
			this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
 
		}
 

	
 
		/* Select caption string of the window. */
 
		StringID caption_string;
src/network/network_gui.cpp
Show inline comments
 
@@ -103,23 +103,23 @@ public:
 
		leaf->SetMinimalSize(14 + GetSpriteSize(SPR_LOCK, nullptr, ZOOM_LVL_OUT_4X).width
 
		                        + GetSpriteSize(SPR_BLOT, nullptr, ZOOM_LVL_OUT_4X).width, 12);
 
		leaf->SetFill(0, 1);
 
		this->Add(leaf);
 
	}
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override
 
	void SetupSmallestSize(Window *w) override
 
	{
 
		this->smallest_y = 0; // Biggest child.
 
		this->fill_x = 1;
 
		this->fill_y = 0;
 
		this->resize_x = 1; // We only resize in this direction
 
		this->resize_y = 0; // We never resize in this direction
 

	
 
		/* First initialise some variables... */
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			child_wid->SetupSmallestSize(w, init_array);
 
			child_wid->SetupSmallestSize(w);
 
			this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
 
		}
 

	
 
		/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			child_wid->current_x = child_wid->smallest_x;
src/newgrf_gui.cpp
Show inline comments
 
@@ -1620,22 +1620,22 @@ public:
 
		this->Add(this->acs);
 
		this->Add(this->inf);
 

	
 
		this->editable = true; // Temporary setting, 'real' value is set in SetupSmallestSize().
 
	}
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override
 
	void SetupSmallestSize(Window *w) override
 
	{
 
		/* Copy state flag from the window. */
 
		assert(dynamic_cast<NewGRFWindow *>(w) != nullptr);
 
		NewGRFWindow *ngw = (NewGRFWindow *)w;
 
		this->editable = ngw->editable;
 

	
 
		this->avs->SetupSmallestSize(w, init_array);
 
		this->acs->SetupSmallestSize(w, init_array);
 
		this->inf->SetupSmallestSize(w, init_array);
 
		this->avs->SetupSmallestSize(w);
 
		this->acs->SetupSmallestSize(w);
 
		this->inf->SetupSmallestSize(w);
 

	
 
		uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
 
		uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
 
		uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
 

	
 
		uint min_avs_height = this->avs->smallest_y + this->avs->padding.Vertical();
src/smallmap_gui.cpp
Show inline comments
 
@@ -1847,19 +1847,19 @@ class NWidgetSmallmapDisplay : public NW
 
public:
 
	NWidgetSmallmapDisplay() : NWidgetContainer(NWID_VERTICAL)
 
	{
 
		this->smallmap_window = nullptr;
 
	}
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override
 
	void SetupSmallestSize(Window *w) override
 
	{
 
		NWidgetBase *display = this->head;
 
		NWidgetBase *bar = display->next;
 

	
 
		display->SetupSmallestSize(w, init_array);
 
		bar->SetupSmallestSize(w, init_array);
 
		display->SetupSmallestSize(w);
 
		bar->SetupSmallestSize(w);
 

	
 
		this->smallmap_window = dynamic_cast<SmallMapWindow *>(w);
 
		assert(this->smallmap_window != nullptr);
 
		this->smallest_x = std::max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth());
 
		this->smallest_y = display->smallest_y + std::max(bar->smallest_y, smallmap_window->GetLegendHeight(smallmap_window->min_number_of_columns));
 
		this->fill_x = std::max(display->fill_x, bar->fill_x);
src/toolbar_gui.cpp
Show inline comments
 
@@ -1332,26 +1332,26 @@ public:
 
	 */
 
	bool IsButton(WidgetType type) const
 
	{
 
		return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
 
	}
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override
 
	void SetupSmallestSize(Window *w) override
 
	{
 
		this->smallest_x = 0; // Biggest child
 
		this->smallest_y = 0; // Biggest child
 
		this->fill_x = 1;
 
		this->fill_y = 0;
 
		this->resize_x = 1; // We only resize in this direction
 
		this->resize_y = 0; // We never resize in this direction
 
		this->spacers = 0;
 

	
 
		uint nbuttons = 0;
 
		/* First initialise some variables... */
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			child_wid->SetupSmallestSize(w, init_array);
 
			child_wid->SetupSmallestSize(w);
 
			this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
 
			if (this->IsButton(child_wid->type)) {
 
				nbuttons++;
 
				this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
 
			} else if (child_wid->type == NWID_SPACER) {
 
				this->spacers++;
 
@@ -1774,15 +1774,15 @@ class NWidgetMainToolbarContainer : publ
 
};
 

	
 
/** Container for the scenario editor's toolbar */
 
class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
 
	uint panel_widths[2]; ///< The width of the two panels (the text panel and date panel)
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override
 
	void SetupSmallestSize(Window *w) override
 
	{
 
		this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
 
		this->NWidgetToolbarContainer::SetupSmallestSize(w);
 

	
 
		/* Find the size of panel_widths */
 
		uint i = 0;
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
 

	
src/widget.cpp
Show inline comments
 
@@ -992,22 +992,21 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
	this->type = tp;
 
}
 

	
 
/* ~NWidgetContainer() takes care of #next and #prev data members. */
 

	
 
/**
 
 * @fn void NWidgetBase::SetupSmallestSize(Window *w, bool init_array)
 
 * @fn void NWidgetBase::SetupSmallestSize(Window *w)
 
 * Compute smallest size needed by the widget.
 
 *
 
 * The smallest size of a widget is the smallest size that a widget needs to
 
 * display itself properly. In addition, filling and resizing of the widget are computed.
 
 * The function calls #Window::UpdateWidgetSize for each leaf widget and
 
 * background widget without child with a non-negative index.
 
 *
 
 * @param w          Window owning the widget.
 
 * @param init_array Initialize the \c w->nested_array.
 
 *
 
 * @note After the computation, the results can be queried by accessing the #smallest_x and #smallest_y data members of the widget.
 
 */
 

	
 
/**
 
 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
@@ -1391,19 +1390,14 @@ void NWidgetStacked::AdjustPaddingForZoo
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->AdjustPaddingForZoom();
 
	}
 
	NWidgetContainer::AdjustPaddingForZoom();
 
}
 

	
 
void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetStacked::SetupSmallestSize(Window *w)
 
{
 
	if (this->index >= 0 && init_array) { // Fill w->nested_array[]
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 

	
 
	/* Zero size plane selected */
 
	if (this->shown_plane >= SZSP_BEGIN) {
 
		Dimension size    = {0, 0};
 
		Dimension padding = {0, 0};
 
		Dimension fill    = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
 
		Dimension resize  = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
 
@@ -1424,13 +1418,13 @@ void NWidgetStacked::SetupSmallestSize(W
 
	this->smallest_y = 0;
 
	this->fill_x = (this->head != nullptr) ? 1 : 0;
 
	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) {
 
		child_wid->SetupSmallestSize(w, init_array);
 
		child_wid->SetupSmallestSize(w);
 

	
 
		this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
 
		this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
 
		this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
 
		this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
 
		this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
 
@@ -1557,13 +1551,13 @@ void NWidgetPIPContainer::SetPIPRatio(ui
 

	
 
/** Horizontal container widget. */
 
NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
 
{
 
}
 

	
 
void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetHorizontal::SetupSmallestSize(Window *w)
 
{
 
	this->smallest_x = 0; // Sum of minimal size of all children.
 
	this->smallest_y = 0; // Biggest child.
 
	this->fill_x = 0;     // smallest non-zero child widget fill step.
 
	this->fill_y = 1;     // smallest common child fill step.
 
	this->resize_x = 0;   // smallest non-zero child widget resize step.
 
@@ -1571,13 +1565,13 @@ void NWidgetHorizontal::SetupSmallestSiz
 
	this->gaps = 0;
 

	
 
	/* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
 
	uint longest = 0; // Longest child found.
 
	uint max_vert_fill = 0; // Biggest vertical fill step.
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->SetupSmallestSize(w, init_array);
 
		child_wid->SetupSmallestSize(w);
 
		longest = std::max(longest, child_wid->smallest_x);
 
		max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
 
		this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
 
		if (child_wid->smallest_x != 0 || child_wid->fill_x != 0) this->gaps++;
 
	}
 
	if (this->gaps > 0) this->gaps--; // Number of gaps is number of widgets less one.
 
@@ -1749,13 +1743,13 @@ void NWidgetHorizontalLTR::AssignSizePos
 

	
 
/** Vertical container widget. */
 
NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
 
{
 
}
 

	
 
void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetVertical::SetupSmallestSize(Window *w)
 
{
 
	this->smallest_x = 0; // Biggest child.
 
	this->smallest_y = 0; // Sum of minimal size of all children.
 
	this->fill_x = 1;     // smallest common child fill step.
 
	this->fill_y = 0;     // smallest non-zero child widget fill step.
 
	this->resize_x = 1;   // smallest common child resize step.
 
@@ -1763,13 +1757,13 @@ void NWidgetVertical::SetupSmallestSize(
 
	this->gaps = 0;
 

	
 
	/* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
 
	uint highest = 0; // Highest child found.
 
	uint max_hor_fill = 0; // Biggest horizontal fill step.
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->SetupSmallestSize(w, init_array);
 
		child_wid->SetupSmallestSize(w);
 
		highest = std::max(highest, child_wid->smallest_y);
 
		max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
 
		this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
 
		if (child_wid->smallest_y != 0 || child_wid->fill_y != 0) this->gaps++;
 
	}
 
	if (this->gaps > 0) this->gaps--; // Number of gaps is number of widgets less one.
 
@@ -1922,13 +1916,13 @@ void NWidgetVertical::AssignSizePosition
 
NWidgetSpacer::NWidgetSpacer(int width, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
 
{
 
	this->SetMinimalSize(width, height);
 
	this->SetResize(0, 0);
 
}
 

	
 
void NWidgetSpacer::SetupSmallestSize(Window *, bool)
 
void NWidgetSpacer::SetupSmallestSize(Window *)
 
{
 
	this->smallest_x = this->min_x;
 
	this->smallest_y = this->min_y;
 
}
 

	
 
void NWidgetSpacer::FillNestedArray(NWidgetBase **, uint)
 
@@ -2018,27 +2012,22 @@ void NWidgetMatrix::SetCount(int count)
 
 */
 
void NWidgetMatrix::SetScrollbar(Scrollbar *sb)
 
{
 
	this->sb = sb;
 
}
 

	
 
void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetMatrix::SetupSmallestSize(Window *w)
 
{
 
	assert(this->head != nullptr);
 
	assert(this->head->next == nullptr);
 

	
 
	if (this->index >= 0 && init_array) { // Fill w->nested_array[]
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 

	
 
	/* Reset the widget number. */
 
	NWidgetCore *nw = dynamic_cast<NWidgetCore *>(this->head);
 
	assert(nw != nullptr);
 
	SB(nw->index, 16, 16, 0);
 
	this->head->SetupSmallestSize(w, init_array);
 
	this->head->SetupSmallestSize(w);
 

	
 
	Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
 
	Dimension size    = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
 
	Dimension fill    = {0, 0};
 
	Dimension resize  = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
 

	
 
@@ -2268,20 +2257,16 @@ void NWidgetBackground::SetPIPRatio(uint
 
void NWidgetBackground::AdjustPaddingForZoom()
 
{
 
	if (child != nullptr) child->AdjustPaddingForZoom();
 
	NWidgetCore::AdjustPaddingForZoom();
 
}
 

	
 
void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetBackground::SetupSmallestSize(Window *w)
 
{
 
	if (init_array && this->index >= 0) {
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 
	if (this->child != nullptr) {
 
		this->child->SetupSmallestSize(w, init_array);
 
		this->child->SetupSmallestSize(w);
 

	
 
		this->smallest_x = this->child->smallest_x;
 
		this->smallest_y = this->child->smallest_y;
 
		this->fill_x = this->child->fill_x;
 
		this->fill_y = this->child->fill_y;
 
		this->resize_x = this->child->resize_x;
 
@@ -2415,18 +2400,14 @@ NWidgetBase *NWidgetBackground::GetWidge
 

	
 
NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
 
{
 
	this->SetIndex(index);
 
}
 

	
 
void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetViewport::SetupSmallestSize(Window *)
 
{
 
	if (init_array && this->index >= 0) {
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 
	this->smallest_x = this->min_x;
 
	this->smallest_y = this->min_y;
 
}
 

	
 
void NWidgetViewport::Draw(const Window *w)
 
{
 
@@ -2596,18 +2577,14 @@ NWidgetScrollbar::NWidgetScrollbar(Widge
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetScrollbar::SetupSmallestSize(Window *)
 
{
 
	if (init_array && this->index >= 0) {
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 
	this->min_x = 0;
 
	this->min_y = 0;
 

	
 
	switch (this->type) {
 
		case NWID_HSCROLLBAR:
 
			this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
 
@@ -2796,19 +2773,14 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, 
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 
}
 

	
 
void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
 
void NWidgetLeaf::SetupSmallestSize(Window *w)
 
{
 
	if (this->index >= 0 && init_array) { // Fill w->nested_array[]
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 

	
 
	Dimension padding = {0, 0};
 
	Dimension size = {this->min_x, this->min_y};
 
	Dimension fill = {this->fill_x, this->fill_y};
 
	Dimension resize = {this->resize_x, this->resize_y};
 
	switch (this->type) {
 
		case WWT_EMPTY: {
src/widget_type.h
Show inline comments
 
@@ -130,13 +130,13 @@ class Scrollbar;
 
 */
 
class NWidgetBase : public ZeroedMemoryAllocator {
 
public:
 
	NWidgetBase(WidgetType tp);
 

	
 
	virtual void AdjustPaddingForZoom();
 
	virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
 
	virtual void SetupSmallestSize(Window *w) = 0;
 
	virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
 

	
 
	virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
 

	
 
	virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
 
	virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
 
@@ -457,13 +457,13 @@ class NWidgetStacked : public NWidgetCon
 
public:
 
	NWidgetStacked();
 

	
 
	void SetIndex(int index);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 

	
 
@@ -514,13 +514,13 @@ protected:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetHorizontal : public NWidgetPIPContainer {
 
public:
 
	NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
};
 

	
 
/**
 
 * Horizontal container that doesn't change the direction of the widgets for RTL languages.
 
 * @ingroup NestedWidgets
 
@@ -537,13 +537,13 @@ public:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetVertical : public NWidgetPIPContainer {
 
public:
 
	NWidgetVertical(NWidContainerFlags flags = NC_NONE);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
};
 

	
 
/**
 
 * Matrix container with implicitly equal sized (virtual) sub-widgets.
 
 * This widget must have exactly one sub-widget. After that this sub-widget
 
@@ -559,13 +559,13 @@ public:
 
	void SetIndex(int index);
 
	void SetColour(Colours colour);
 
	void SetClicked(int clicked);
 
	void SetCount(int count);
 
	void SetScrollbar(Scrollbar *sb);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
	void Draw(const Window *w) override;
 
protected:
 
@@ -589,13 +589,13 @@ private:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetSpacer : public NWidgetResizeBase {
 
public:
 
	NWidgetSpacer(int width, int height);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	void SetDirty(const Window *w) const override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
};
 
@@ -611,13 +611,13 @@ public:
 

	
 
	void Add(NWidgetBase *nwid);
 
	void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post);
 
	void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 

	
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
@@ -637,13 +637,13 @@ private:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetViewport : public NWidgetCore {
 
public:
 
	NWidgetViewport(int index);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void Draw(const Window *w) override;
 

	
 
	void InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom);
 
	void UpdateViewportCoordinates(Window *w);
 
};
 

	
 
@@ -837,13 +837,13 @@ public:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
 
public:
 
	NWidgetScrollbar(WidgetType tp, Colours colour, int index);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void Draw(const Window *w) override;
 

	
 
	static void InvalidateDimensionCache();
 
	static Dimension GetVerticalDimension();
 
	static Dimension GetHorizontalDimension();
 

	
 
@@ -857,13 +857,13 @@ private:
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetLeaf : public NWidgetCore {
 
public:
 
	NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32_t data, StringID tip);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void SetupSmallestSize(Window *w) override;
 
	void Draw(const Window *w) override;
 

	
 
	bool ButtonHit(const Point &pt);
 

	
 
	static void InvalidateDimensionCache();
 

	
src/window.cpp
Show inline comments
 
@@ -960,14 +960,14 @@ void Window::ReInit(int rx, int ry, bool
 
	/* Save current size. */
 
	int window_width  = this->width * _gui_scale / this->scale;
 
	int window_height = this->height * _gui_scale / this->scale;
 
	this->scale = _gui_scale;
 

	
 
	this->OnInit();
 
	/* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
 
	this->nested_root->SetupSmallestSize(this, false);
 
	/* Re-initialize window smallest size. */
 
	this->nested_root->SetupSmallestSize(this);
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
 
	this->width  = this->nested_root->smallest_x;
 
	this->height = this->nested_root->smallest_y;
 
	this->resize.step_width  = this->nested_root->resize_x;
 
	this->resize.step_height = this->nested_root->resize_y;
 

	
 
@@ -1376,19 +1376,14 @@ void Window::InitializeData(WindowNumber
 
	if (this->window_desc->default_pos == WDP_CENTER) this->flags |= WF_CENTERED;
 
	this->owner = INVALID_OWNER;
 
	this->nested_focus = nullptr;
 
	this->window_number = window_number;
 

	
 
	this->OnInit();
 
	/* Initialize nested widget tree. */
 
	if (this->nested_array == nullptr) {
 
		this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
		this->nested_root->SetupSmallestSize(this, true);
 
	} else {
 
		this->nested_root->SetupSmallestSize(this, false);
 
	}
 
	/* Initialize smallest size. */
 
	this->nested_root->SetupSmallestSize(this);
 
	/* Initialize to smallest size. */
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
 

	
 
	/* Further set up window properties,
 
	 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
 
	this->resize.step_width  = this->nested_root->resize_x;
 
@@ -1729,22 +1724,20 @@ static Point LocalGetWindowPlacement(con
 
 * Perform the first part of the initialization of a nested widget tree.
 
 * Construct a nested widget tree in #nested_root, and optionally fill the #nested_array array to provide quick access to the uninitialized widgets.
 
 * This is mainly useful for setting very basic properties.
 
 * @param fill_nested Fill the #nested_array (enabling is expensive!).
 
 * @note Filling the nested array requires an additional traversal through the nested widget tree, and is best performed by #FinishInitNested rather than here.
 
 */
 
void Window::CreateNestedTree(bool fill_nested)
 
void Window::CreateNestedTree()
 
{
 
	int biggest_index = -1;
 
	this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &biggest_index, &this->shade_select);
 
	this->nested_array_size = (uint)(biggest_index + 1);
 

	
 
	if (fill_nested) {
 
		this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
		this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
 
	}
 
	this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
	this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
 
}
 

	
 
/**
 
 * Perform the second part of the initialization of a nested widget tree.
 
 * @param window_number Number of the new window.
 
 */
 
@@ -1760,13 +1753,13 @@ void Window::FinishInitNested(WindowNumb
 
/**
 
 * Perform complete initialization of the #Window with nested widgets, to allow use.
 
 * @param window_number Number of the new window.
 
 */
 
void Window::InitNested(WindowNumber window_number)
 
{
 
	this->CreateNestedTree(false);
 
	this->CreateNestedTree();
 
	this->FinishInitNested(window_number);
 
}
 

	
 
/**
 
 * Empty constructor, initialization has been moved to #InitNested() called from the constructor of the derived class.
 
 * @param desc The description of the window.
src/window_gui.h
Show inline comments
 
@@ -285,13 +285,13 @@ public:
 
	virtual const struct Textbuf *GetFocusedTextbuf() const;
 
	virtual Point GetCaretPosition() const;
 
	virtual Rect GetTextBoundingRect(const char *from, const char *to) const;
 
	virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const;
 

	
 
	void InitNested(WindowNumber number = 0);
 
	void CreateNestedTree(bool fill_nested = true);
 
	void CreateNestedTree();
 
	void FinishInitNested(WindowNumber window_number = 0);
 

	
 
	template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
 
	void FinishInitNested(T number)
 
	{
 
		this->FinishInitNested(number.base());
0 comments (0 inline, 0 general)