The Battle for Wesnoth  1.15.12+dev
theme_list.cpp
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 
16 
18 #include "gui/widgets/listbox.hpp"
19 #include "gui/widgets/settings.hpp"
20 #include "gui/widgets/window.hpp"
21 #include "theme.hpp"
22 
23 namespace gui2::dialogs
24 {
25 
26 REGISTER_DIALOG(theme_list)
27 
28 theme_list::theme_list(const std::vector<theme_info>& themes, int selection)
29  : index_(selection), themes_(themes)
30 {
31 }
32 
34 {
35  listbox& list = find_widget<listbox>(&window, "themes", false);
36  window.keyboard_capture(&list);
37 
38  for(const auto & t : themes_)
39  {
40  std::map<std::string, string_map> data;
41  string_map column;
42 
43  std::string theme_name = t.name;
44  if(theme_name.empty()) {
45  theme_name = t.id;
46  }
47 
48  column["label"] = theme_name;
49  data.emplace("name", column);
50  column["label"] = t.description;
51  data.emplace("description", column);
52 
53  list.add_row(data);
54  }
55 
56  if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
57  list.select_row(index_);
58  }
59 
60  index_ = -1;
61 }
62 
64 {
65  if(get_retval() != retval::OK) {
66  return;
67  }
68 
69  listbox& list = find_widget<listbox>(&window, "themes", false);
70  index_ = list.get_selected_row();
71 }
72 } // namespace dialogs
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:34
This file contains the window object, this object is a top level container which has the event manage...
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: theme_list.cpp:63
STL namespace.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:276
std::vector< theme_info > themes_
Definition: theme_list.hpp:58
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:251
The listbox class.
Definition: listbox.hpp:42
This file contains the settings handling of the widget library.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: theme_list.cpp:33
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:132
Definitions related to theme-support.
std::map< std::string, t_string > string_map
Definition: widget.hpp:26
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:67
int get_retval() const
Returns the cached window exit code.
double t
Definition: astarsearch.cpp:64
Dialog was closed with the OK button.
Definition: retval.hpp:34
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64