The Battle for Wesnoth  1.19.0+dev
tab_container.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2024
3  by Subhraman Sarkar (babaissarkar) <suvrax@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 
16 #pragma once
17 
19 #include "gui/widgets/listbox.hpp"
21 
22 namespace gui2
23 {
24 
25 namespace implementation
26 {
27 struct 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 
38 public:
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 
53  unsigned get_tab_count() {
54  return builders_.size();
55  }
56 private:
57  /**
58  * Possible states of the widget.
59  *
60  * Note the order of the states must be the same as defined in settings.hpp.
61  */
62  enum state_t {
65  };
66 
67  /**
68  * Current state of the widget.
69  *
70  * The state of the widget determines what to render and how the widget
71  * reacts to certain 'events'.
72  */
74 
75  std::vector<std::shared_ptr<builder_grid>> builders_;
76  std::vector<widget_data> list_items_;
77 
78  /**
79  * Finishes the building initialization of the widget.
80  *
81  * @param generator Generator for the list
82  */
83  void finalize(std::unique_ptr<generator_base> generator);
84 
85  /**
86  * Contains a pointer to the generator.
87  */
89 
90  /** Get the listbox inside which the tabs are shown */
92 
93  void add_tab_entry(const widget_data row);
94 
95  void change_selection();
96 
97  void finalize_listbox();
98 
99  void set_items(std::vector<widget_data> list_items)
100  {
101  list_items_ = list_items;
102  }
103 
104  void set_builders(std::vector<std::shared_ptr<builder_grid>> builders) {
105  builders_ = builders;
106  }
107 
108 public:
109  /** Static type getter that does not rely on the widget being constructed. */
110  static const std::string& type();
111 
112 private:
113  /* **** ***** ***** inherited ****** **** */
114 
115  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
116  virtual const std::string& get_control_type() const override;
117 
118 };
119 
120 // }---------- DEFINITION ---------{
121 
123 {
124  explicit tab_container_definition(const config& cfg);
125 
127  {
128  explicit resolution(const config& cfg);
129 
131  };
132 };
133 
134 // }---------- BUILDER -----------{
135 
136 namespace implementation
137 {
138 
140 {
141  explicit builder_tab_container(const config& cfg);
142 
144 
145  virtual std::unique_ptr<widget> build() const override;
146 
147  std::vector<std::shared_ptr<builder_grid>> builders;
148 
149  std::vector<widget_data> list_items;
150 };
151 
152 } // namespace implementation
153 
154 // }------------ END --------------
155 
156 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A generic container base class.
Abstract base class for the generator.
Definition: generator.hpp:39
Basic template class to generate new items.
The listbox class.
Definition: listbox.hpp:43
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.
state_t
Possible states of the widget.
virtual unsigned get_state() const override
Returns the id of the state.
void finalize(std::unique_ptr< generator_base > generator)
Finishes the building initialization of the widget.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
generator_base * generator_
Contains a pointer to the generator.
virtual bool get_active() const override
Gets the active state of the styled_widget.
virtual void set_self_active(const bool active) override
Helper for set_active.
bool can_wrap() const override
See widget::can_wrap.
std::vector< std::shared_ptr< builder_grid > > builders_
void add_tab_entry(const widget_data row)
void select_tab(unsigned index)
void set_items(std::vector< widget_data > list_items)
void set_builders(std::vector< std::shared_ptr< builder_grid >> builders)
std::vector< widget_data > list_items_
listbox & get_internal_list()
Get the listbox inside which the tabs are shown.
unsigned get_tab_count()
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
tab_container(const implementation::builder_tab_container &builder)
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:34
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
virtual std::unique_ptr< widget > build() const=0
virtual std::unique_ptr< widget > build() const override
std::vector< std::shared_ptr< builder_grid > > builders
tab_container_definition(const config &cfg)