The Battle for Wesnoth  1.15.11+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::dialogs::drop_down_menu Class Reference

Used by the menu_button widget. More...

#include <drop_down_menu.hpp>

Inheritance diagram for gui2::dialogs::drop_down_menu:

Classes

struct  entry_data
 

Public Member Functions

 drop_down_menu (styled_widget *parent, const std::vector< config > &items, int selected_item, bool keep_open)
 Menu was invoked from a widget (currently a [multi]menu_button). More...
 
 drop_down_menu (SDL_Rect button_pos, const std::vector< config > &items, int selected_item, bool use_markup, bool keep_open)
 Menu was invoked manually. More...
 
int selected_item () const
 
boost::dynamic_bitset get_toggle_states () const
 If a toggle button widget is present, returns the toggled state of each row's button. More...
 
- Public Member Functions inherited from gui2::dialogs::modal_dialog
 modal_dialog ()
 
virtual ~modal_dialog ()
 
bool show (const unsigned auto_close_time=0)
 Shows the window. More...
 
windowget_window () const
 Returns a pointer to the dialog's window. More...
 
int get_retval () const
 Returns the cached window exit code. More...
 
void set_retval (int retval)
 Convenience wrapper to set the window's exit code. More...
 
void set_always_save_fields (const bool always_save_fields)
 
void set_restore (const bool restore)
 
void set_allow_plugin_skip (const bool allow_plugin_skip)
 
void set_show_even_without_video (const bool show_even_without_video)
 

Private Member Functions

virtual const std::string & window_id () const override
 The id of the window to build. More...
 
virtual void pre_show (window &window) override
 Actions to be taken before showing the window. More...
 
virtual void post_show (window &window) override
 Actions to be taken after the window has been shown. More...
 
void mouse_up_callback (bool &, bool &, const point &coordinate)
 
void mouse_down_callback ()
 

Private Attributes

styled_widgetparent_
 The widget that invoked this dialog, if applicable. More...
 
std::vector< entry_dataitems_
 Configuration of each row. More...
 
SDL_Rect button_pos_
 The screen location of the menu_button button that triggered this droplist. More...
 
int selected_item_
 
bool use_markup_
 
bool keep_open_
 Whether to keep this dialog open after a click occurs not handled by special exceptions such as scrollbars and toggle buttons. More...
 
bool mouse_down_happened_
 When menu is invoked on a long-touch timer, a following mouse-up event will close it. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gui2::dialogs::modal_dialog
field_boolregister_bool (const std::string &id, const bool mandatory, const std::function< bool()> callback_load_value=nullptr, const std::function< void(bool)> callback_save_value=nullptr, const std::function< void(widget &)> callback_change=nullptr, const bool initial_fire=false)
 Creates a new boolean field. More...
 
field_boolregister_bool (const std::string &id, const bool mandatory, bool &linked_variable, const std::function< void(widget &)> callback_change=nullptr, const bool initial_fire=false)
 Creates a new boolean field. More...
 
field_integerregister_integer (const std::string &id, const bool mandatory, const std::function< int()> callback_load_value=nullptr, const std::function< void(int)> callback_save_value=nullptr)
 Creates a new integer field. More...
 
field_integerregister_integer (const std::string &id, const bool mandatory, int &linked_variable)
 Creates a new integer field. More...
 
field_textregister_text (const std::string &id, const bool mandatory, const std::function< std::string()> callback_load_value=nullptr, const std::function< void(const std::string &)> callback_save_value=nullptr, const bool capture_focus=false)
 Creates a new text field. More...
 
field_textregister_text (const std::string &id, const bool mandatory, std::string &linked_variable, const bool capture_focus=false)
 Creates a new text field. More...
 
field_labelregister_label (const std::string &id, const bool mandatory, const std::string &text, const bool use_markup=false)
 Registers a new styled_widget as a label. More...
 
field_labelregister_image (const std::string &id, const bool mandatory, const std::string &filename)
 Registers a new styled_widget as image. More...
 
- Protected Attributes inherited from gui2::dialogs::modal_dialog
std::unique_ptr< windowwindow_
 The window object build for this dialog. More...
 

Detailed Description

Used by the menu_button widget.

Definition at line 34 of file drop_down_menu.hpp.

Constructor & Destructor Documentation

◆ drop_down_menu() [1/2]

gui2::dialogs::drop_down_menu::drop_down_menu ( styled_widget parent,
const std::vector< config > &  items,
int  selected_item,
bool  keep_open 
)

Menu was invoked from a widget (currently a [multi]menu_button).

Its position and markup settings will be derived from there.

Definition at line 84 of file drop_down_menu.cpp.

References gui2::dialogs::modal_dialog::set_restore().

◆ drop_down_menu() [2/2]

gui2::dialogs::drop_down_menu::drop_down_menu ( SDL_Rect  button_pos,
const std::vector< config > &  items,
int  selected_item,
bool  use_markup,
bool  keep_open 
)

Menu was invoked manually.

Position and markup settings must be provided here.

Definition at line 96 of file drop_down_menu.cpp.

References gui2::dialogs::modal_dialog::set_restore().

Member Function Documentation

◆ get_toggle_states()

boost::dynamic_bitset gui2::dialogs::drop_down_menu::get_toggle_states ( ) const

If a toggle button widget is present, returns the toggled state of each row's button.

Definition at line 250 of file drop_down_menu.cpp.

References gui2::listbox::get_item_count(), gui2::listbox::get_row_grid(), gui2::dialogs::modal_dialog::get_window(), and i.

Referenced by selected_item(), and gui2::multimenu_button::signal_handler_notify_changed().

◆ mouse_down_callback()

void gui2::dialogs::drop_down_menu::mouse_down_callback ( )
private

Definition at line 154 of file drop_down_menu.cpp.

References mouse_down_happened_.

Referenced by pre_show().

◆ mouse_up_callback()

void gui2::dialogs::drop_down_menu::mouse_up_callback ( bool &  ,
bool &  ,
const point coordinate 
)
private

◆ post_show()

void gui2::dialogs::drop_down_menu::post_show ( window window)
overrideprivatevirtual

Actions to be taken after the window has been shown.

At this point the registered fields already stored their values (if the OK has been pressed).

Parameters
windowThe window which has been shown.

Reimplemented from gui2::dialogs::modal_dialog.

Definition at line 245 of file drop_down_menu.cpp.

References selected_item_.

◆ pre_show()

void gui2::dialogs::drop_down_menu::pre_show ( window window)
overrideprivatevirtual

◆ selected_item()

int gui2::dialogs::drop_down_menu::selected_item ( ) const
inline

◆ window_id()

virtual const std::string& gui2::dialogs::drop_down_menu::window_id ( ) const
overrideprivatevirtual

The id of the window to build.

Implements gui2::dialogs::modal_dialog.

Member Data Documentation

◆ button_pos_

SDL_Rect gui2::dialogs::drop_down_menu::button_pos_
private

The screen location of the menu_button button that triggered this droplist.

Note: we don't adjust the location of this dialog to when resizing the window. Instead this dialog automatically closes itself on resizing.

Definition at line 87 of file drop_down_menu.hpp.

Referenced by pre_show().

◆ items_

std::vector<entry_data> gui2::dialogs::drop_down_menu::items_
private

Configuration of each row.

Definition at line 80 of file drop_down_menu.hpp.

Referenced by pre_show().

◆ keep_open_

bool gui2::dialogs::drop_down_menu::keep_open_
private

Whether to keep this dialog open after a click occurs not handled by special exceptions such as scrollbars and toggle buttons.

Definition at line 97 of file drop_down_menu.hpp.

Referenced by mouse_up_callback().

◆ mouse_down_happened_

bool gui2::dialogs::drop_down_menu::mouse_down_happened_
private

When menu is invoked on a long-touch timer, a following mouse-up event will close it.

This flag prevents that: the menu will only be closed on a mouse-up that follows a mouse-down.

Definition at line 103 of file drop_down_menu.hpp.

Referenced by mouse_down_callback(), and mouse_up_callback().

◆ parent_

styled_widget* gui2::dialogs::drop_down_menu::parent_
private

The widget that invoked this dialog, if applicable.

Definition at line 77 of file drop_down_menu.hpp.

Referenced by pre_show().

◆ selected_item_

int gui2::dialogs::drop_down_menu::selected_item_
private

Definition at line 89 of file drop_down_menu.hpp.

Referenced by post_show(), pre_show(), and selected_item().

◆ use_markup_

bool gui2::dialogs::drop_down_menu::use_markup_
private

Definition at line 91 of file drop_down_menu.hpp.

Referenced by pre_show().


The documentation for this class was generated from the following files: