The Battle for Wesnoth  1.19.5+dev
theme_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 
18 #include "gui/widgets/listbox.hpp"
19 #include "gui/widgets/window.hpp"
20 #include "theme.hpp"
21 
22 namespace gui2::dialogs
23 {
24 
25 REGISTER_DIALOG(theme_list)
26 
27 theme_list::theme_list(const std::vector<theme_info>& themes, int selection)
28  : modal_dialog(window_id())
29  , index_(selection)
30  , themes_(themes)
31 {
32 }
33 
35 {
36  listbox& list = find_widget<listbox>("themes");
37  keyboard_capture(&list);
38 
39  for(const auto & t : themes_)
40  {
42  widget_item 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>("themes");
71  index_ = list.get_selected_row();
72 }
73 } // namespace dialogs
double t
Definition: astarsearch.cpp:63
Abstract base class for all modal dialogs.
int get_retval() const
Returns the cached window exit code.
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: theme_list.cpp:64
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: theme_list.cpp:34
std::vector< theme_info > themes_
Definition: theme_list.hpp:49
The listbox class.
Definition: listbox.hpp:43
grid & add_row(const widget_item &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:58
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:242
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:267
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:123
void keyboard_capture(widget *widget)
Definition: window.cpp:1207
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(editor_edit_unit)
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
std::string_view data
Definition: picture.cpp:178
Definitions related to theme-support.