The Battle for Wesnoth  1.15.12+dev
theme_list.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 
19 struct theme_info;
20 
21 namespace gui2::dialogs
22 {
23 
24 /**
25  * @ingroup GUIWindowDefinitionWML
26  *
27  * Dialog for selecting a GUI theme.
28  * Key |Type |Mandatory|Description
29  * ------------------|--------------|---------|-----------
30  * themes | @ref listbox |yes |Listbox displaying user choices.
31  * name | control |yes |Widget which shows a theme item name.
32  * description | control |yes |Widget which shows a theme item description.
33  */
34 class theme_list : public modal_dialog
35 {
36 public:
37  explicit theme_list(const std::vector<theme_info>& themes,
38  int selection = -1);
39 
40  /**
41  * Returns the selected item index after displaying.
42  * @return -1 if the dialog was canceled.
43  */
44  int selected_index() const
45  {
46  return index_;
47  }
48 
49  /** Sets the initially selected item index (-1 by default). */
51  {
52  index_ = index;
53  }
54 
55 private:
56  int index_;
57 
58  std::vector<theme_info> themes_;
59 
60  virtual const std::string& window_id() const override;
61 
62  virtual void pre_show(window& window) override;
63 
64  virtual void post_show(window& window) override;
65 };
66 } // namespace dialogs
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:34
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: theme_list.cpp:63
std::vector< theme_info > themes_
Definition: theme_list.hpp:58
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:50
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:44
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: theme_list.cpp:33
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
virtual const std::string & window_id() const override
The id of the window to build.
theme_list(const std::vector< theme_info > &themes, int selection=-1)
Definition: theme_list.cpp:28