The Battle for Wesnoth  1.17.0-dev
matrix.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 #pragma once
16 
18 #include "gui/widgets/pane.hpp"
20 
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 namespace implementation
30 {
31 struct builder_matrix;
32 }
33 
35 {
36 public:
37  state_default();
38 
39  void set_active(const bool active);
40 
41  bool get_active() const;
42 
43  unsigned get_state() const;
44 
45 protected:
46  /**
47  * Possible states of the widget.
48  *
49  * Note the order of the states must be the same as defined in settings.hpp.
50  */
51  enum state_t {
54  };
55 
56 private:
57  /**
58  * Current state of the widget.
59  *
60  * The state of the widget determines what to render and how the widget
61  * reacts to certain 'events'.
62  */
64 };
65 
66 template <class STATE>
67 class control_NEW : public styled_widget, public STATE
68 {
69 public:
71  const std::string& control_type)
72  : styled_widget(builder, control_type)
73 
74  {
75  }
76 
77  /** See @ref styled_widget::set_active. */
78  virtual void set_active(const bool active) override
79  {
80  STATE::set_active(active);
81  }
82 
83  /** See @ref styled_widget::get_active. */
84  virtual bool get_active() const override
85  {
86  return STATE::get_active();
87  }
88 
89  /** See @ref styled_widget::get_state. */
90  virtual unsigned get_state() const override
91  {
92  return STATE::get_state();
93  }
94 };
95 
97 
98 /**
99  * @ingroup GUIWidgetWML
100  *
101  * List with the matrix specific variables:
102  * Key |Type |Default |Description
103  * -------------------------|------------------------------------------------|------------|-----------
104  * vertical_scrollbar_mode | @ref guivartype_scrollbar_mode "scrollbar_mode"|initial_auto|Determines whether or not to show the scrollbar.
105  * horizontal_scrollbar_mode| @ref guivartype_scrollbar_mode "scrollbar_mode"|initial_auto|Determines whether or not to show the scrollbar.
106  */
107 class matrix : public tbase
108 {
109  friend class debug_layout_graph;
110 
111 private:
112  explicit matrix(const implementation::builder_matrix& builder);
113 
114 public:
115  static matrix* build(const implementation::builder_matrix& builder);
116 
117  /***** ***** ***** ***** Item handling. ***** ***** ****** *****/
118 
119  unsigned create_item(const std::map<std::string, string_map>& item_data,
120  const std::map<std::string, std::string>& tags);
121 
122 
123  /***** ***** ***** ***** Inherited operations. ***** ***** ****** *****/
124 
125  /** See @ref widget::place. */
126  virtual void place(const point& origin, const point& size) override;
127 
128  /** See @ref widget::layout_initialize. */
129  virtual void layout_initialize(const bool full_initialization) override;
130 
131  /** See @ref widget::impl_draw_children. */
132  virtual void impl_draw_children(surface& frame_buffer,
133  int x_offset,
134  int y_offset) override;
135 
136  /** See @ref widget::layout_children. */
137  virtual void layout_children() override;
138 
139  /** See @ref widget::child_populate_dirty_list. */
140  virtual void
141  child_populate_dirty_list(window& caller,
142  const std::vector<widget*>& call_stack) override;
143 
144  /** See @ref widget::request_reduce_width. */
145  virtual void request_reduce_width(const unsigned maximum_width) override;
146 
147  /** See @ref widget::find_at. */
148  virtual widget* find_at(const point& coordinate,
149  const bool must_be_active) override;
150 
151  /** See @ref widget::find_at. */
152  virtual const widget* find_at(const point& coordinate,
153  const bool must_be_active) const override;
154 
155  /** See @ref widget::find. */
156  widget* find(const std::string& id, const bool must_be_active) override;
157 
158  /** See @ref widget::find. */
159  const widget* find(const std::string& id,
160  const bool must_be_active) const override;
161 
162  /***** ***** ***** ***** Forwarded to pane_. ***** ***** ****** *****/
163  /**
164  * Sorts the contents of the pane.
165  *
166  * @param compare_functor The functor to use to sort the items.
167  */
168  void sort(const pane::compare_functor_t& compare_functor)
169  {
170  /********************** OUTLINE *******************/
171  pane_->sort(compare_functor);
172  }
173 
174  /**
175  * Filters the contents of the pane.
176  *
177  * if the @p filter_functor returns @c true the item shown, else it's
178  * hidden.
179  *
180  * @param filter_functor The functor to determine whether an item
181  * should be shown or hidden.
182  */
183  void filter(const pane::filter_functor_t& filter_functor)
184  {
185  /********************** OUTLINE *******************/
186  pane_->filter(filter_functor);
187  }
188 
189 private:
190  /** See @ref widget::calculate_best_size. */
191  virtual point calculate_best_size() const override;
192 
193 public:
194  /** See @ref widget::disable_click_dismiss. */
195  bool disable_click_dismiss() const override;
196 
197  /** See @ref widget::create_walker. */
198  virtual iteration::walker_base* create_walker() override;
199 
200  /**
201  * Returns a grid in the pane.
202  *
203  * @param id The id of the item whose grid to return. The
204  * id is the value returned by
205  * @ref create_item().
206  *
207  * @returns The wanted grid.
208  * @retval nullptr The id isn't associated with an item.
209  */
210  grid* get_grid(const unsigned id);
211 
212  /**
213  * Returns a grid in the pane.
214  *
215  * @param id The id of the item whose grid to return. The
216  * id is the value returned by
217  * @ref create_item().
218  *
219  * @returns The wanted grid.
220  * @retval nullptr The id isn't associated with an item.
221  */
222  const grid* get_grid(const unsigned id) const;
223 
224 private:
225  /** The grid containing our children. */
227 
228  /**
229  * Contains the pane used for adding new items to the matrix.
230  *
231  * The pane is owned by a grid in the content layer.
232  */
234 
235 public:
236  /** Static type getter that does not rely on the widget being constructed. */
237  static const std::string& type();
238 
239 private:
240  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
241  virtual const std::string& get_control_type() const override;
242 };
243 
244 // }---------- DEFINITION ---------{
245 
247 {
248 
249  explicit matrix_definition(const config& cfg);
250 
252  {
253  explicit resolution(const config& cfg);
254 
256  };
257 };
258 
259 // }---------- BUILDER -----------{
260 
261 namespace implementation
262 {
263 
265 {
266  explicit builder_matrix(const config& cfg);
267 
269 
270  virtual widget* build() const override;
271 
274 
277 
280 
282 };
283 
284 } // namespace implementation
285 
286 // }------------ END --------------
287 
288 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
List with the matrix specific variables: Key Type Default Description vertical_scrollbar_mode scroll...
Definition: matrix.hpp:107
Base class for all widgets.
Definition: widget.hpp:49
void sort(const pane::compare_functor_t &compare_functor)
Sorts the contents of the pane.
Definition: matrix.hpp:168
grid content_
The grid containing our children.
Definition: matrix.hpp:226
std::function< bool(const item &)> filter_functor_t
Definition: pane.hpp:59
void filter(const pane::filter_functor_t &filter_functor)
Filters the contents of the pane.
Definition: matrix.hpp:183
std::shared_ptr< builder_widget > builder_widget_ptr
Generic file dialog.
Definition: field-fwd.hpp:23
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: matrix.hpp:90
Base container class.
Definition: grid.hpp:31
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
control_NEW(const implementation::builder_styled_widget &builder, const std::string &control_type)
Definition: matrix.hpp:70
The walker abstract base class.
Definition: walker.hpp:27
static thread_local std::deque< std::string > call_stack
For printing error messages when WFL parsing or evaluation fails, this contains the names of the WFL ...
Definition: function.cpp:47
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: matrix.hpp:78
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition: matrix.hpp:272
A pane is a container where new members can be added and removed during run-time. ...
Definition: pane.hpp:43
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition: matrix.hpp:273
control_NEW< state_default > tbase
Definition: matrix.hpp:96
virtual bool get_active() const override
See styled_widget::get_active.
Definition: matrix.hpp:84
state_t state_
Current state of the widget.
Definition: matrix.hpp:63
Holds a 2D point.
Definition: point.hpp:24
Base class for all visible items.
std::function< bool(const item &, const item &)> compare_functor_t
Definition: pane.hpp:57
scrollbar_mode
The way to handle the showing or hiding of the scrollbar.
builder_widget_ptr builder_main
Definition: matrix.hpp:281
state_t
Possible states of the widget.
Definition: matrix.hpp:51
pane * pane_
Contains the pane used for adding new items to the matrix.
Definition: matrix.hpp:233
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.