The Battle for Wesnoth  1.17.0-dev
theme_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
17 
19 #include "gui/widgets/listbox.hpp"
20 #include "gui/widgets/settings.hpp"
21 #include "gui/widgets/window.hpp"
22 #include "theme.hpp"
23 
24 namespace gui2::dialogs
25 {
26 
27 REGISTER_DIALOG(theme_list)
28 
29 theme_list::theme_list(const std::vector<theme_info>& themes, int selection)
30  : index_(selection), themes_(themes)
31 {
32 }
33 
35 {
36  listbox& list = find_widget<listbox>(&window, "themes", false);
37  window.keyboard_capture(&list);
38 
39  for(const auto & t : themes_)
40  {
41  std::map<std::string, string_map> data;
42  string_map column;
43 
44  std::string theme_name = t.name;
45  if(theme_name.empty()) {
46  theme_name = t.id;
47  }
48 
49  column["label"] = theme_name;
50  data.emplace("name", column);
51  column["label"] = t.description;
52  data.emplace("description", column);
53 
54  list.add_row(data);
55  }
56 
57  if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
58  list.select_row(index_);
59  }
60 
61  index_ = -1;
62 }
63 
65 {
66  if(get_retval() != retval::OK) {
67  return;
68  }
69 
70  listbox& list = find_widget<listbox>(&window, "themes", false);
71  index_ = list.get_selected_row();
72 }
73 } // namespace dialogs
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:35
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:64
STL namespace.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:277
std::vector< theme_info > themes_
Definition: theme_list.hpp:59
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:252
The listbox class.
Definition: listbox.hpp:43
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:34
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:133
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:68
int get_retval() const
Returns the cached window exit code.
double t
Definition: astarsearch.cpp:65
Dialog was closed with the OK button.
Definition: retval.hpp:35
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65