The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
theme_list.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2014 - 2025
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
20#include "theme.hpp"
21
22namespace gui2::dialogs
23{
24
25REGISTER_DIALOG(theme_list)
26
27theme_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_) {
41 { "name", {
42 { "label", t.name.empty() ? t_string(t.id) : t.name }
43 }},
44 { "description", {
45 { "label", t.description }
46 }},
47 });
48 }
49
50 if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
51 list.select_row(index_);
52 }
53
54 index_ = -1;
55}
56
58{
59 if(get_retval() != retval::OK) {
60 return;
61 }
62
63 listbox& list = find_widget<listbox>("themes");
64 index_ = list.get_selected_row();
65}
66} // namespace dialogs
double t
Abstract base class for all modal dialogs.
virtual void post_show() override
Actions to be taken after the window has been shown.
virtual void pre_show() override
Actions to be taken before showing the window.
std::vector< theme_info > themes_
The listbox class.
Definition listbox.hpp:41
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:92
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition listbox.cpp:267
int get_selected_row() const
Returns the first selected row.
Definition listbox.cpp:290
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition listbox.cpp:153
void keyboard_capture(widget *widget)
Definition window.cpp:1197
int get_retval()
Definition window.hpp:394
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::map< std::string, widget_item > widget_data
Definition widget.hpp:36
@ OK
Dialog was closed with the OK button.
Definition retval.hpp:35
STL namespace.
Definitions related to theme-support.