The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
tab_container.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 - 2025
3 by Subhraman Sarkar (babaissarkar) <sbmskmm@protonmail.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
16#pragma once
17
21
22namespace gui2
23{
24
25namespace implementation
26{
27struct builder_tab_container;
28}
29
30/**
31 * A container widget that shows one of its pages of widgets
32 * depending on which tab the user clicked.
33 */
35{
37
38public:
40
41 virtual void set_self_active(const bool active) override;
42
43 /* **** ***** ***** setters / getters for members ***** ****** **** */
44
45 virtual bool get_active() const override;
46
47 virtual unsigned get_state() const override;
48
49 bool can_wrap() const override;
50
51 void select_tab(unsigned index);
52
56
57 unsigned get_tab_count() const {
58 return tab_count_;
59 }
60
61 grid* get_tab_grid(unsigned i)
62 {
63 assert(generator_);
64 return &generator_->item(i);
65 }
66
67 const grid* get_tab_grid(unsigned i) const
68 {
69 assert(generator_);
70 return &generator_->item(i);
71 }
72private:
73 /**
74 * Possible states of the widget.
75 *
76 * Note the order of the states must be the same as defined in settings.hpp.
77 */
82
83 /**
84 * Current state of the widget.
85 *
86 * The state of the widget determines what to render and how the widget
87 * reacts to certain 'events'.
88 */
90
92
93 /**
94 * Contains a pointer to the generator.
95 */
97
98 /** Get the listbox inside which the tabs are shown */
100
101 void add_tab_entry(const widget_data& row);
102
103 void change_selection();
104
105public:
106 /** Static type getter that does not rely on the widget being constructed. */
107 static const std::string& type();
108
109 /** See @ref widget::find. */
110 virtual widget* find(const std::string_view id, const bool must_be_active) override;
111
112 /** See @ref widget::find. */
113 virtual const widget* find(const std::string_view id, const bool must_be_active) const override;
114
115private:
116 /* **** ***** ***** inherited ****** **** */
117
118 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
119 virtual const std::string& get_control_type() const override;
120
121};
122
123// }---------- DEFINITION ---------{
124
126{
127 explicit tab_container_definition(const config& cfg);
128
130 {
131 explicit resolution(const config& cfg);
132
134 };
135};
136
137// }---------- BUILDER -----------{
138
139namespace implementation
140{
141
143{
144 explicit builder_tab_container(const config& cfg);
145
147
148 virtual std::unique_ptr<widget> build() const override;
149
150 std::vector<std::shared_ptr<builder_grid>> builders;
151
152 std::vector<widget_data> list_items;
153};
154
155} // namespace implementation
156
157// }------------ END --------------
158
159} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
A generic container base class.
Abstract base class for the generator.
Definition generator.hpp:39
virtual grid & item(const unsigned index)=0
Gets the grid of an item.
Base container class.
Definition grid.hpp:32
The listbox class.
Definition listbox.hpp:41
int get_selected_row() const
Returns the first selected row.
Definition listbox.cpp:290
A container widget that shows one of its pages of widgets depending on which tab the user clicked.
state_t state_
Current state of the widget.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
state_t
Possible states of the widget.
virtual unsigned get_state() const override
Returns the id of the state.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
generator_base * generator_
Contains a pointer to the generator.
virtual bool get_active() const override
Gets the active state of the styled_widget.
virtual widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
void add_tab_entry(const widget_data &row)
unsigned get_tab_count() const
const grid * get_tab_grid(unsigned i) const
virtual void set_self_active(const bool active) override
Helper for set_active.
bool can_wrap() const override
See widget::can_wrap.
void select_tab(unsigned index)
grid * get_tab_grid(unsigned i)
listbox & get_internal_list()
Get the listbox inside which the tabs are shown.
unsigned get_active_tab_index()
Base class for all widgets.
Definition widget.hpp:55
const config * cfg
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::map< std::string, widget_item > widget_data
Definition widget.hpp:36
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual std::unique_ptr< widget > build() const=0
virtual std::unique_ptr< widget > build() const override
std::vector< std::shared_ptr< builder_grid > > builders
#define i