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

A simple one-column listbox with OK and Cancel buttons. More...

#include <simple_item_selector.hpp>

Inheritance diagram for gui2::dialogs::simple_item_selector:

Public Types

typedef std::vector< std::string > list_type
 

Public Member Functions

 simple_item_selector (const std::string &title, const std::string &message, const list_type &items, bool title_uses_markup=false, bool message_uses_markup=false)
 
int selected_index () const
 Returns the selected item index after displaying. More...
 
void set_selected_index (int index)
 Sets the initially selected item index (-1 by default). More...
 
void set_ok_label (const std::string &s)
 Sets the caption for the OK button. More...
 
const std::string & ok_label () const
 
void set_cancel_label (const std::string &s)
 Sets the caption for the Cancel button. More...
 
const std::string & cancel_label () const
 
void set_single_button (bool value)
 Sets whether the Cancel button should be hidden or not. More...
 
bool single_button () const
 
- 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...
 

Private Attributes

int index_
 
bool single_button_
 
list_type items_
 
std::string ok_label_
 
std::string cancel_label_
 

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

A simple one-column listbox with OK and Cancel buttons.

Key Type MandatoryDescription
title label yes Dialog title label.
message control yes Text label displaying a description or instructions.
listbox listbox yes Listbox displaying user choices.
item control yes Widget which shows a listbox item label.
ok button yes OK button.
cancel button yes Cancel button.

Definition at line 37 of file simple_item_selector.hpp.

Member Typedef Documentation

◆ list_type

typedef std::vector<std::string> gui2::dialogs::simple_item_selector::list_type

Definition at line 40 of file simple_item_selector.hpp.

Constructor & Destructor Documentation

◆ simple_item_selector()

gui2::dialogs::simple_item_selector::simple_item_selector ( const std::string &  title,
const std::string &  message,
const list_type items,
bool  title_uses_markup = false,
bool  message_uses_markup = false 
)

Definition at line 31 of file simple_item_selector.cpp.

Member Function Documentation

◆ cancel_label()

const std::string& gui2::dialogs::simple_item_selector::cancel_label ( ) const
inline

Definition at line 78 of file simple_item_selector.hpp.

References cancel_label_.

◆ ok_label()

const std::string& gui2::dialogs::simple_item_selector::ok_label ( ) const
inline

Definition at line 68 of file simple_item_selector.hpp.

References ok_label_.

◆ post_show()

void gui2::dialogs::simple_item_selector::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 84 of file simple_item_selector.cpp.

References gui2::dialogs::modal_dialog::get_retval(), index_, gui2::OK, and single_button_.

◆ pre_show()

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

Actions to be taken before showing the window.

At this point the registered fields are registered and initialized with their initial values.

Parameters
windowThe window to be shown.

Reimplemented from gui2::dialogs::modal_dialog.

Definition at line 46 of file simple_item_selector.cpp.

References gui2::listbox::add_row(), cancel_label_, gui2::listbox::get_item_count(), index_, gui2::widget::invisible, items_, ok_label_, gui2::listbox::select_row(), gui2::styled_widget::set_label(), and single_button_.

◆ selected_index()

int gui2::dialogs::simple_item_selector::selected_index ( ) const
inline

Returns the selected item index after displaying.

Returns
-1 if the dialog was canceled.

Definition at line 52 of file simple_item_selector.hpp.

References index_.

Referenced by events::console_handler::do_choose_level(), wb::manager::options_dlg(), gui2::dialogs::mp_create_game::post_show(), and turn_info::process_network_data().

◆ set_cancel_label()

void gui2::dialogs::simple_item_selector::set_cancel_label ( const std::string &  s)
inline

Sets the caption for the Cancel button.

Definition at line 74 of file simple_item_selector.hpp.

References cancel_label_, and s.

◆ set_ok_label()

void gui2::dialogs::simple_item_selector::set_ok_label ( const std::string &  s)
inline

Sets the caption for the OK button.

Definition at line 64 of file simple_item_selector.hpp.

References ok_label_, and s.

◆ set_selected_index()

void gui2::dialogs::simple_item_selector::set_selected_index ( int  index)
inline

Sets the initially selected item index (-1 by default).

Definition at line 58 of file simple_item_selector.hpp.

References utf8::index(), and index_.

Referenced by events::console_handler::do_choose_level().

◆ set_single_button()

void gui2::dialogs::simple_item_selector::set_single_button ( bool  value)
inline

Sets whether the Cancel button should be hidden or not.

Definition at line 84 of file simple_item_selector.hpp.

References single_button_.

Referenced by gui2::dialogs::mp_create_game::post_show(), and turn_info::process_network_data().

◆ single_button()

bool gui2::dialogs::simple_item_selector::single_button ( ) const
inline

Definition at line 88 of file simple_item_selector.hpp.

References single_button_.

◆ window_id()

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

The id of the window to build.

Implements gui2::dialogs::modal_dialog.

Member Data Documentation

◆ cancel_label_

std::string gui2::dialogs::simple_item_selector::cancel_label_
private

Definition at line 99 of file simple_item_selector.hpp.

Referenced by cancel_label(), pre_show(), and set_cancel_label().

◆ index_

int gui2::dialogs::simple_item_selector::index_
private

Definition at line 94 of file simple_item_selector.hpp.

Referenced by post_show(), pre_show(), selected_index(), and set_selected_index().

◆ items_

list_type gui2::dialogs::simple_item_selector::items_
private

Definition at line 97 of file simple_item_selector.hpp.

Referenced by pre_show().

◆ ok_label_

std::string gui2::dialogs::simple_item_selector::ok_label_
private

Definition at line 99 of file simple_item_selector.hpp.

Referenced by ok_label(), pre_show(), and set_ok_label().

◆ single_button_

bool gui2::dialogs::simple_item_selector::single_button_
private

Definition at line 96 of file simple_item_selector.hpp.

Referenced by post_show(), pre_show(), set_single_button(), and single_button().


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