The Battle for Wesnoth  1.19.4+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_active_tab_index() {
55  }
56 
57  unsigned get_tab_count() const {
58  return builders_.size();
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  }
72 private:
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  */
78  enum state_t {
81  };
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 
91  std::vector<std::shared_ptr<builder_grid>> builders_;
92  std::vector<widget_data> list_items_;
93 
94  /**
95  * Finishes the building initialization of the widget.
96  *
97  * @param generator Generator for the list
98  */
99  void finalize(std::unique_ptr<generator_base> generator);
100 
101  /**
102  * Contains a pointer to the generator.
103  */
105 
106  /** Get the listbox inside which the tabs are shown */
108 
109  void add_tab_entry(const widget_data row);
110 
111  void change_selection();
112 
113  void finalize_listbox();
114 
115 public:
116  /** Static type getter that does not rely on the widget being constructed. */
117  static const std::string& type();
118 
119 private:
120  /* **** ***** ***** inherited ****** **** */
121 
122  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
123  virtual const std::string& get_control_type() const override;
124 
125 };
126 
127 // }---------- DEFINITION ---------{
128 
130 {
131  explicit tab_container_definition(const config& cfg);
132 
134  {
135  explicit resolution(const config& cfg);
136 
138  };
139 };
140 
141 // }---------- BUILDER -----------{
142 
143 namespace implementation
144 {
145 
147 {
148  explicit builder_tab_container(const config& cfg);
149 
151 
152  virtual std::unique_ptr<widget> build() const override;
153 
154  std::vector<std::shared_ptr<builder_grid>> builders;
155 
156  std::vector<widget_data> list_items;
157 };
158 
159 } // namespace implementation
160 
161 // }------------ END --------------
162 
163 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
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.
Basic template class to generate new items.
Base container class.
Definition: grid.hpp:32
The listbox class.
Definition: listbox.hpp:43
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:267
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.
const grid * get_tab_grid(unsigned i) const
generator_base * generator_
Contains a pointer to the generator.
virtual bool get_active() const override
Gets the active state of the styled_widget.
unsigned get_tab_count() const
grid * get_tab_grid(unsigned i)
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)
std::vector< widget_data > list_items_
listbox & get_internal_list()
Get the listbox inside which the tabs are shown.
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)
unsigned get_active_tab_index()
std::size_t i
Definition: function.cpp:1023
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.
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)