The Battle for Wesnoth  1.17.0-dev
server_info_dialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2020 - 2021
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/widgets/label.hpp"
21 #include "gui/widgets/listbox.hpp"
23 #include "gui/widgets/window.hpp"
24 
25 namespace gui2::dialogs
26 {
27 
28 REGISTER_DIALOG(server_info)
29 
30 server_info::server_info(const std::string& info, const std::string& announcements)
31 : server_information_(info)
32 , announcements_(announcements)
33 {
34 
35 }
36 
38 {
39  find_widget<label>(&window, "server_information", false).set_label(server_information_);
40  find_widget<label>(&window, "announcements", false).set_label(announcements_);
41 
42  stacked_widget& pager = find_widget<stacked_widget>(&window, "tabs_container", false);
43  pager.select_layer(0);
44 
45  listbox& tab_bar = find_widget<listbox>(&window, "tab_bar", false);
46 
47  VALIDATE(tab_bar.get_item_count() == pager.get_layer_count(), "Tab bar and container size mismatch");
48 
50 }
51 
53 {
54  stacked_widget& pager = find_widget<stacked_widget>(get_window(), "tabs_container", false);
55  listbox& tab_bar = find_widget<listbox>(get_window(), "tab_bar", false);
56 
57  pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
58 }
59 
60 }
unsigned int get_layer_count() const
Gets the total number of layers.
logger & info()
Definition: log.cpp:89
This file contains the window object, this object is a top level container which has the event manage...
STL namespace.
window * get_window() const
Returns a pointer to the dialog&#39;s window.
The listbox class.
Definition: listbox.hpp:43
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:187
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:133
const std::string & server_information_
void select_layer(const int layer)
Selects and displays a particular layer.
const std::string & announcements_
A stacked widget holds several widgets on top of each other.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65