Changeset - r28708:87001b4757db
[Not reviewed]
master
0 2 0
Peter Nelson - 6 months ago 2023-11-11 21:57:49
peter1138@openttd.org
Codechange: Add method to replace the content of a dropdown menu.

If necessary the dropdown list window will be resized and scrollbar enabled/disabled.
2 files changed with 18 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/widgets/dropdown.cpp
Show inline comments
 
@@ -42,7 +42,7 @@ static WindowDesc _dropdown_desc(__FILE_
 
struct DropdownWindow : Window {
 
	WidgetID parent_button;       ///< Parent widget number where the window is dropped from.
 
	Rect wi_rect;                 ///< Rect of the button that opened the dropdown.
 
	const DropDownList list;      ///< List with dropdown menu items.
 
	DropDownList list;            ///< List with dropdown menu items.
 
	int selected_result;          ///< Result value of the selected item in the list.
 
	byte click_delay = 0;         ///< Timer to delay selection.
 
	bool drag_mode = true;
 
@@ -303,8 +303,23 @@ struct DropdownWindow : Window {
 
			}
 
		}
 
	}
 

	
 
	void ReplaceList(DropDownList &&list)
 
	{
 
		this->list = std::move(list);
 
		this->UpdateSizeAndPosition();
 
		this->ReInit(0, 0);
 
		this->InitializePositionSize(this->position.x, this->position.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
 
		this->SetDirty();
 
	}
 
};
 

	
 
void ReplaceDropDownList(Window *parent, DropDownList &&list)
 
{
 
	DropdownWindow *ddw = dynamic_cast<DropdownWindow *>(parent->FindChildWindow(WC_DROPDOWN_MENU));
 
	if (ddw != nullptr) ddw->ReplaceList(std::move(list));
 
}
 

	
 
/**
 
 * Determine width and height required to fully display a DropDownList
 
 * @param list The list.
src/widgets/dropdown_type.h
Show inline comments
 
@@ -215,4 +215,6 @@ void ShowDropDownList(Window *w, DropDow
 

	
 
Dimension GetDropDownListDimension(const DropDownList &list);
 

	
 
void ReplaceDropDownList(Window *parent, DropDownList &&list);
 

	
 
#endif /* WIDGETS_DROPDOWN_TYPE_H */
0 comments (0 inline, 0 general)