mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Add method to replace the content of a dropdown menu.
If necessary the dropdown list window will be resized and scrollbar enabled/disabled.
This commit is contained in:
parent
ac44c001a4
commit
0ce30d05c8
|
@ -42,7 +42,7 @@ static WindowDesc _dropdown_desc(__FILE__, __LINE__,
|
||||||
struct DropdownWindow : Window {
|
struct DropdownWindow : Window {
|
||||||
WidgetID parent_button; ///< Parent widget number where the window is dropped from.
|
WidgetID parent_button; ///< Parent widget number where the window is dropped from.
|
||||||
Rect wi_rect; ///< Rect of the button that opened the dropdown.
|
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.
|
int selected_result; ///< Result value of the selected item in the list.
|
||||||
byte click_delay = 0; ///< Timer to delay selection.
|
byte click_delay = 0; ///< Timer to delay selection.
|
||||||
bool drag_mode = true;
|
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
|
* Determine width and height required to fully display a DropDownList
|
||||||
* @param list The list.
|
* @param list The list.
|
||||||
|
|
|
@ -215,4 +215,6 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID but
|
||||||
|
|
||||||
Dimension GetDropDownListDimension(const DropDownList &list);
|
Dimension GetDropDownListDimension(const DropDownList &list);
|
||||||
|
|
||||||
|
void ReplaceDropDownList(Window *parent, DropDownList &&list);
|
||||||
|
|
||||||
#endif /* WIDGETS_DROPDOWN_TYPE_H */
|
#endif /* WIDGETS_DROPDOWN_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue