OpenTTD Source 20241224-master-gf74b0cf984
|
Implementation of the dropdown widget. More...
#include "stdafx.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "dropdown_common_type.h"
#include "strings_func.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "window_gui.h"
#include "window_func.h"
#include "zoom_func.h"
#include "widgets/dropdown_widget.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | DropdownWindow |
Drop-down menu window. More... | |
Functions | |
std::unique_ptr< DropDownListItem > | MakeDropDownListDividerItem () |
std::unique_ptr< DropDownListItem > | MakeDropDownListStringItem (StringID str, int value, bool masked, bool shaded) |
std::unique_ptr< DropDownListItem > | MakeDropDownListStringItem (const std::string &str, int value, bool masked, bool shaded) |
std::unique_ptr< DropDownListItem > | MakeDropDownListIconItem (SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded) |
std::unique_ptr< DropDownListItem > | MakeDropDownListIconItem (const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded) |
std::unique_ptr< DropDownListItem > | MakeDropDownListCheckedItem (bool checked, StringID str, int value, bool masked, bool shaded) |
void | ReplaceDropDownList (Window *parent, DropDownList &&list) |
Dimension | GetDropDownListDimension (const DropDownList &list) |
Determine width and height required to fully display a DropDownList. | |
void | ShowDropDownListAt (Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist) |
Show a drop down list. | |
void | ShowDropDownList (Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist) |
Show a drop down list. | |
void | ShowDropDownMenu (Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width) |
Show a dropdown menu window near a widget of the parent window. | |
Variables | |
static constexpr NWidgetPart | _nested_dropdown_menu_widgets [] |
static WindowDesc | _dropdown_desc (WDP_MANUAL, nullptr, 0, 0, WC_DROPDOWN_MENU, WC_NONE, WDF_NO_FOCUS, _nested_dropdown_menu_widgets) |
Implementation of the dropdown widget.
Definition in file dropdown.cpp.
Dimension GetDropDownListDimension | ( | const DropDownList & | list | ) |
Determine width and height required to fully display a DropDownList.
list | The list. |
Definition at line 363 of file dropdown.cpp.
References WidgetDimensions::dropdowntext, RectPadding::Horizontal(), and WidgetDimensions::scaled.
Referenced by DropdownWindow::UpdateSizeAndPosition(), BuildVehicleWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), and VehicleListWindow::UpdateWidgetSize().
std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem | ( | bool | checked, |
StringID | str, | ||
int | value, | ||
bool | masked, | ||
bool | shaded | ||
) |
Definition at line 50 of file dropdown.cpp.
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem | ( | ) |
Definition at line 25 of file dropdown.cpp.
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem | ( | const Dimension & | dim, |
SpriteID | sprite, | ||
PaletteID | palette, | ||
StringID | str, | ||
int | value, | ||
bool | masked, | ||
bool | shaded | ||
) |
Definition at line 45 of file dropdown.cpp.
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem | ( | SpriteID | sprite, |
PaletteID | palette, | ||
StringID | str, | ||
int | value, | ||
bool | masked, | ||
bool | shaded | ||
) |
Definition at line 40 of file dropdown.cpp.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem | ( | const std::string & | str, |
int | value, | ||
bool | masked, | ||
bool | shaded | ||
) |
Definition at line 35 of file dropdown.cpp.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem | ( | StringID | str, |
int | value, | ||
bool | masked, | ||
bool | shaded | ||
) |
Definition at line 30 of file dropdown.cpp.
void ReplaceDropDownList | ( | Window * | parent, |
DropDownList && | list | ||
) |
Definition at line 352 of file dropdown.cpp.
void ShowDropDownList | ( | Window * | w, |
DropDownList && | list, | ||
int | selected, | ||
WidgetID | button, | ||
uint | width, | ||
bool | instant_close, | ||
bool | persist | ||
) |
Show a drop down list.
w | Parent window for the list. |
list | Prepopulated DropDownList. |
selected | The initially selected list item. |
button | The widget within the parent window that is used to determine the list's location. |
width | Override the minimum width determined by the selected widget and list contents. |
instant_close | Set to true if releasing mouse button should close the list regardless of where the cursor is. |
persist | Set if this dropdown should stay open after an option is selected. |
Definition at line 404 of file dropdown.cpp.
References _current_text_dir, NWidgetCore::colour, NWidgetCore::disp_flags, Window::GetWidget(), ND_DROPDOWN_ACTIVE, NWID_BUTTON_DROPDOWN, ScaleGUITrad(), NWidgetBase::SetDirty(), NWidgetCore::SetLowered(), ShowDropDownListAt(), TD_RTL, and NWidgetBase::type.
Referenced by BuildAirportWindow::OnClick(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), GenerateLandscapeWindow::OnClick(), CreateScenarioWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), IndustryCargoesWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), NetworkStartServerWindow::OnClick(), NetworkClientListWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), GameOptionsWindow::OnClick(), GameSettingsWindow::OnClick(), CompanyStationsWindow::OnClick(), StoryBookWindow::OnClick(), TextfileWindow::OnClick(), VehicleListWindow::OnClick(), PopupMainToolbarMenu(), SetDateWindow::ShowDateDropDown(), ShowDropDownMenu(), and ToolbarOptionsClick().
void ShowDropDownListAt | ( | Window * | w, |
DropDownList && | list, | ||
int | selected, | ||
WidgetID | button, | ||
Rect | wi_rect, | ||
Colours | wi_colour, | ||
bool | instant_close, | ||
bool | persist | ||
) |
Show a drop down list.
w | Parent window for the list. |
list | Prepopulated DropDownList. |
selected | The initially selected list item. |
button | The widget which is passed to Window::OnDropdownSelect and OnDropdownClose. Unless you override those functions, this should be then widget index of the dropdown button. |
wi_rect | Coord of the parent drop down button, used to position the dropdown menu. |
instant_close | Set to true if releasing mouse button should close the list regardless of where the cursor is. |
persist | Set if this dropdown should stay open after an option is selected. |
Definition at line 386 of file dropdown.cpp.
References CloseWindowByClass(), and WC_DROPDOWN_MENU.
Referenced by GSConfigWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), GameSettingsWindow::OnClick(), NetworkClientListWindow::OnClickClientAdmin(), NetworkClientListWindow::OnClickCompanyAdmin(), and ShowDropDownList().
void ShowDropDownMenu | ( | Window * | w, |
std::span< const StringID > | strings, | ||
int | selected, | ||
WidgetID | button, | ||
uint32_t | disabled_mask, | ||
uint32_t | hidden_mask, | ||
uint | width | ||
) |
Show a dropdown menu window near a widget of the parent window.
The result code of the items is their index in the strings list.
w | Parent window that wants the dropdown menu. |
strings | Menu list. |
selected | Index of initial selected item. |
button | Button widget number of the parent window w that wants the dropdown menu. |
disabled_mask | Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list). |
hidden_mask | Bitmask for hidden items (items with their bit set are not copied to the dropdown list). |
width | Minimum width of the dropdown menu. |
Definition at line 441 of file dropdown.cpp.
References HasBit(), and ShowDropDownList().
Referenced by DisplayVehicleSortDropDown(), ReplaceVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), GenerateLandscapeWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), OrdersWindow::OnClick(), CompanyStationsWindow::OnClick(), StationViewWindow::OnClick(), TownDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), and VehicleDetailsWindow::OnClick().
|
staticconstexpr |
Definition at line 55 of file dropdown.cpp.