Changeset - r10009:58150b3a405f
[Not reviewed]
master
0 2 0
peter1138 - 16 years ago 2008-08-25 16:07:10
peter1138@openttd.org
(svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
2 files changed with 10 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/widgets/dropdown.cpp
Show inline comments
 
@@ -226,13 +226,13 @@ struct DropdownWindow : Window {
 
			this->selected_index = item;
 
			this->SetDirty();
 
		}
 
	}
 
};
 

	
 
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool instant_close)
 
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
 
{
 
	bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
 

	
 
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
 

	
 
	if (is_dropdown_menu_shown) {
 
@@ -247,23 +247,22 @@ void ShowDropDownList(Window *w, DropDow
 
	 * down list window. */
 
	const Widget *wi = &w->widget[button];
 

	
 
	/* The preferred position is just below the dropdown calling widget */
 
	int top = w->top + wi->bottom + 1;
 

	
 
	bool auto_width = (width == UINT_MAX);
 
	if (width == 0) width = wi->right - wi->left + 1;
 

	
 
	uint max_item_width = 0;
 

	
 
	if (auto_width) {
 
		/* Find the longest item in the list */
 
		width = 0;
 
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
 
			const DropDownListItem *item = *it;
 
			width = max(width, item->Width() + 5);
 
			max_item_width = max(max_item_width, item->Width() + 5);
 
		}
 
	} else if (width == 0) {
 
		width = wi->right - wi->left + 1;
 
	}
 

	
 
	/* Total length of list */
 
	int list_height = 0;
 

	
 
	for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
 
@@ -294,16 +293,18 @@ void ShowDropDownList(Window *w, DropDow
 
			int avg_height = list_height / (int)list->size();
 
			int rows = (screen_bottom - 4 - top) / avg_height;
 
			height = rows * avg_height;
 
			scroll = true;
 
			/* Add space for the scroll bar if we automatically determined
 
			 * the width of the list. */
 
			if (auto_width) width += 12;
 
			max_item_width += 12;
 
		}
 
	}
 

	
 
	if (auto_width) width = max(width, max_item_width);
 

	
 
	DropdownWindow *dw = new DropdownWindow(
 
		w->left + wi->left,
 
		top,
 
		width,
 
		height + 4,
 
		_dropdown_menu_widgets);
src/widgets/dropdown_type.h
Show inline comments
 
@@ -67,14 +67,13 @@ typedef std::list<DropDownListItem *> Dr
 
 * @param list     Prepopulated DropDownList. Will be deleted when the list is
 
 *                 closed.
 
 * @param selected The initially selected list item.
 
 * @param button   The widget within the parent window that is used to determine
 
 *                 the list's location.
 
 * @param width    Override the width determined by the selected widget.
 
 *                 If UINT_MAX then the width is determined by the widest item
 
 *                 in the list.
 
 * @param auto_width Maximum width is determined by the widest item in the list.
 
 * @param instant_close Set to true if releasing mouse button should close the
 
 *                      list regardless of where the cursor is.
 
 */
 
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool instant_close = false);
 
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
 

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