The Battle for Wesnoth  1.17.0-dev
grid.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 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 
16 #pragma once
17 
18 #include "gui/widgets/widget.hpp"
19 
20 #include <cassert>
21 
22 namespace gui2
23 {
24 
25 /**
26  * Base container class.
27  *
28  * This class holds a number of widgets and their wanted layout parameters. It
29  * also layouts the items in the grid and handles their drawing.
30  */
31 class grid : public widget
32 {
33  friend class debug_layout_graph;
34  friend struct grid_implementation;
35 
36 public:
37  explicit grid(const unsigned rows = 0, const unsigned cols = 0);
38 
39  /** Delete the copy constructor. */
40  grid(const grid&) = delete;
41 
42  /** Delete the move assignment operator. */
43  grid& operator=(const grid&) = delete;
44 
45  virtual ~grid();
46 
47  /***** ***** ***** ***** LAYOUT FLAGS ***** ***** ***** *****/
48  static const unsigned VERTICAL_SHIFT = 0;
49  static const unsigned VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT;
50  static const unsigned VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT;
51  static const unsigned VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT;
52  static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT;
53  static const unsigned VERTICAL_MASK = 7 << VERTICAL_SHIFT;
54 
55  static const unsigned HORIZONTAL_SHIFT = 3;
56  static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT;
57  static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT;
58  static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT;
59  static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT;
60  static const unsigned HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT;
61 
62  static const unsigned BORDER_TOP = 1 << 6;
63  static const unsigned BORDER_BOTTOM = 1 << 7;
64  static const unsigned BORDER_LEFT = 1 << 8;
65  static const unsigned BORDER_RIGHT = 1 << 9;
66  static const unsigned BORDER_ALL = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT;
67 
68  /***** ***** ***** ***** ROW COLUMN MANIPULATION ***** ***** ***** *****/
69 
70  /**
71  * Adds a row to end of the grid.
72  *
73  * @param count Number of rows to add, should be > 0.
74  *
75  * @returns The row number of the first row added.
76  */
77  unsigned add_row(const unsigned count = 1);
78 
79  /**
80  * Sets the grow factor for a row.
81  *
82  * @todo refer to a page with the layout manipulation info.
83  *
84  * @param row The row to modify.
85  * @param factor The grow factor.
86  */
87  void set_row_grow_factor(const unsigned row, const unsigned factor)
88  {
89  assert(row < row_grow_factor_.size());
90  row_grow_factor_[row] = factor;
91  set_is_dirty(true);
92  }
93 
94  /**
95  * Sets the grow factor for a column.
96  *
97  * @todo refer to a page with the layout manipulation info.
98  *
99  * @param column The column to modify.
100  * @param factor The grow factor.
101  */
102  void set_column_grow_factor(const unsigned column, const unsigned factor)
103  {
104  assert(column < col_grow_factor_.size());
105  col_grow_factor_[column] = factor;
106  set_is_dirty(true);
107  }
108 
109  /***** ***** ***** ***** CHILD MANIPULATION ***** ***** ***** *****/
110 
111  /**
112  * Sets a child in the grid.
113  *
114  * When the child is added to the grid the grid 'owns' the widget.
115  * The widget is put in a cell, and every cell can only contain 1 widget if
116  * the wanted cell already contains a widget, that widget is freed and
117  * removed.
118  *
119  * @param widget The widget to put in the grid.
120  * @param row The row of the cell.
121  * @param col The column of the cell.
122  * @param flags The flags for the widget in the cell.
123  * @param border_size The size of the border for the cell, how the
124  * border is applied depends on the flags.
125  */
126  void set_child(widget* widget,
127  const unsigned row,
128  const unsigned col,
129  const unsigned flags,
130  const unsigned border_size);
131 
132  /**
133  * Exchanges a child in the grid.
134  *
135  * It replaced the child with a certain id with the new widget but doesn't
136  * touch the other settings of the child.
137  *
138  * @param id The id of the widget to free.
139  * @param w The widget to put in the grid.
140  * @param recurse Do we want to decent into the child grids.
141  * @param new_parent The new parent for the swapped out widget.
142  *
143  * returns The widget which got removed (the parent of
144  * the widget is cleared). If no widget found
145  * and thus not replace nullptr will returned.
146  */
147  std::unique_ptr<widget> swap_child(const std::string& id,
148  widget* w,
149  const bool recurse,
150  widget* new_parent = nullptr);
151 
152  /**
153  * Removes and frees a widget in a cell.
154  *
155  * @param row The row of the cell.
156  * @param col The column of the cell.
157  */
158  void remove_child(const unsigned row, const unsigned col);
159 
160  /**
161  * Removes and frees a widget in a cell by it's id.
162  *
163  * @param id The id of the widget to free.
164  * @param find_all If true if removes all items with the id,
165  * otherwise it stops after removing the first
166  * item (or once all children have been tested).
167  */
168  void remove_child(const std::string& id, const bool find_all = false);
169 
170  /**
171  * Activates all children.
172  *
173  * If a child inherits from styled_widget or is a grid it will call
174  * set_active() for the child otherwise it ignores the widget.
175  *
176  * @param active Parameter for set_active.
177  */
178  void set_active(const bool active);
179 
180  /** Returns the widget in the selected cell. */
181  const widget* get_widget(const unsigned row, const unsigned col) const
182  {
183  return get_child(row, col).get_widget();
184  }
185 
186  /** Returns the widget in the selected cell. */
187  widget* get_widget(const unsigned row, const unsigned col)
188  {
189  return get_child(row, col).get_widget();
190  }
191 
192  virtual bool can_mouse_focus() const override { return false; }
193  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
194 
195  /** See @ref widget::layout_initialize. */
196  virtual void layout_initialize(const bool full_initialization) override;
197 
198  /**
199  * Tries to reduce the width of a container.
200  *
201  * See @ref layout_algorithm for more information.
202  *
203  * @param maximum_width The wanted maximum width.
204  */
205  void reduce_width(const unsigned maximum_width);
206 
207  /** See @ref widget::request_reduce_width. */
208  virtual void request_reduce_width(const unsigned maximum_width) override;
209 
210  /** See @ref widget::demand_reduce_width. */
211  virtual void demand_reduce_width(const unsigned maximum_width) override;
212 
213  /**
214  * Tries to reduce the height of a container.
215  *
216  * See @ref layout_algorithm for more information.
217  *
218  * @param maximum_height The wanted maximum height.
219  */
220  void reduce_height(const unsigned maximum_height);
221 
222  /** See @ref widget::request_reduce_height. */
223  virtual void request_reduce_height(const unsigned maximum_height) override;
224 
225  /** See @ref widget::demand_reduce_height. */
226  virtual void demand_reduce_height(const unsigned maximum_height) override;
227 
228  /**
229  * Recalculates the best size.
230  *
231  * This is used for scrollbar containers when they try to update their
232  * contents size before falling back to the 'global' invalidate_layout.
233  *
234  * @returns The newly calculated size.
235  */
237 
238  /**
239  * Modifies the widget alignment data of a child cell containing a specific widget.
240  *
241  * @param widget The widget whose cell to modify.
242  * @param set_flag The alignment flag to set.
243  * @param mode_mask Whether to affect horizontal or vertical alignment.
244  * Use either HORIZONTAL_MASK or VERTICAL_MASK
245  */
246  void set_child_alignment(widget* widget, unsigned set_flag, unsigned mode_mask);
247 
248 private:
249  /** See @ref widget::calculate_best_size. */
250  virtual point calculate_best_size() const override;
251 
252  /**
253  * Attempts to lay out the grid without laying out the entire window.
254  */
255  void request_placement(dispatcher& dispatcher, const event::ui_event event, bool& handled, bool& halt);
256 
257 public:
258  /** See @ref widget::can_wrap. */
259  virtual bool can_wrap() const override;
260 
261 public:
262  /** See @ref widget::place. */
263  virtual void place(const point& origin, const point& size) override;
264 
265  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
266 
267  /** See @ref widget::set_origin. */
268  virtual void set_origin(const point& origin) override;
269 
270  /** See @ref widget::set_visible_rectangle. */
271  virtual void set_visible_rectangle(const SDL_Rect& rectangle) override;
272 
273  /** See @ref widget::layout_children. */
274  virtual void layout_children() override;
275 
276  /** See @ref widget::child_populate_dirty_list. */
277  virtual void
279  const std::vector<widget*>& call_stack) override;
280 
281  /** See @ref widget::find_at. */
282  virtual widget* find_at(const point& coordinate,
283  const bool must_be_active) override;
284 
285  /** See @ref widget::find_at. */
286  virtual const widget* find_at(const point& coordinate,
287  const bool must_be_active) const override;
288 
289  /** See @ref widget::find. */
290  widget* find(const std::string& id, const bool must_be_active) override;
291 
292  /** See @ref widget::find. */
293  const widget* find(const std::string& id,
294  const bool must_be_active) const override;
295 
296  /** See @ref widget::has_widget. */
297  virtual bool has_widget(const widget& widget) const override;
298 
299  /** See @ref widget::disable_click_dismiss. */
300  bool disable_click_dismiss() const override;
301 
302  /** See @ref widget::create_walker. */
303  virtual iteration::walker_base* create_walker() override;
304 
305  /***** ***** ***** setters / getters for members ***** ****** *****/
306 
307  void set_rows(const unsigned rows);
308  unsigned int get_rows() const
309  {
310  return rows_;
311  }
312 
313  void set_cols(const unsigned cols);
314  unsigned int get_cols() const
315  {
316  return cols_;
317  }
318 
319  /**
320  * Wrapper to set_rows and set_cols.
321  *
322  * @param rows Parameter to call set_rows with.
323  * @param cols Parameter to call set_cols with.
324  */
325  void set_rows_cols(const unsigned rows, const unsigned cols);
326 
327 private:
328  /** Child item of the grid. */
329  class child
330  {
331  friend struct grid_implementation;
332 
333  public:
334  // Fixme make a class where we can store some properties in the cache
335  // regarding size etc.
336  child() : flags_(0), border_size_(0), widget_(nullptr)
337  {
338  }
339 
340  /**
341  * Move constructor.
342  *
343  * This is necessary in order that the child objects be moved instead
344  * of copied when the grid's child vector is resized. std::vector will
345  * utilize a move constructor as long as a non-throwing one is provided.
346  */
347  child(child&&) noexcept = default;
348 
349  /** Returns the best size for the cell. */
350  point get_best_size() const;
351 
352  /**
353  * Places the widget in the cell.
354  *
355  * @param origin The origin (x, y) for the widget.
356  * @param size The size for the widget.
357  */
358  void place(point origin, point size);
359 
360  /** Forwards @ref grid::layout_initialize to the cell. */
361  void layout_initialize(const bool full_initialization);
362 
363  /** Returns the can_wrap for the cell. */
364  bool can_wrap() const
365  {
366  return widget_ ? widget_->can_wrap() : false;
367  }
368 
369  /** Returns the id of the widget/ */
370  const std::string& id() const;
371 
372  unsigned get_flags() const
373  {
374  return flags_;
375  }
376 
377  void set_flags(const unsigned flags)
378  {
379  flags_ = flags;
380  }
381 
382  unsigned get_border_size() const
383  {
384  return border_size_;
385  }
386 
387  void set_border_size(const unsigned border_size)
388  {
389  border_size_ = border_size;
390  }
391 
392  const widget* get_widget() const
393  {
394  return widget_.get();
395  }
396 
397  widget* get_widget()
398  {
399  return widget_.get();
400  }
401 
402  void set_widget(widget* widget)
403  {
404  widget_.reset(widget);
405  }
406 
407  /**
408  * Releases widget from ownership by this child and returns it in the
409  * form of a new unique_ptr. widget_ will be null after this is called.
410  */
411  std::unique_ptr<widget> free_widget()
412  {
413  return std::exchange(widget_, nullptr);
414  }
415 
416  private:
417  /** The flags for the border and cell setup. */
418  unsigned flags_;
419 
420  /**
421  * The size of the border, the actual configuration of the border
422  * is determined by the flags.
423  */
424  unsigned border_size_;
425 
426  /**
427  * Pointer to the widget.
428  *
429  * Once the widget is assigned to the grid we own the widget and it
430  * will be destroyed with the grid or @ref free_widget is called.
431  */
432  std::unique_ptr<widget> widget_;
433 
434  /** Returns the space needed for the border. */
435  point border_space() const;
436 
437  }; // class child
438 
439 public:
440  /** Iterator for the child items. */
441  class iterator
442  {
443 
444  public:
446  {
447  }
448 
450  {
451  return iterator(++itor_);
452  }
454  {
455  return iterator(--itor_);
456  }
457  widget* operator->()
458  {
459  return itor_->get_widget();
460  }
461  widget* operator*()
462  {
463  return itor_->get_widget();
464  }
465 
466  bool operator==(const iterator& i) const
467  {
468  return i.itor_ == this->itor_;
469  }
470 
471  bool operator!=(const iterator& i) const
472  {
473  return i.itor_ != this->itor_;
474  }
475 
476  private:
478  };
479 
481  {
482  return iterator(children_.begin());
483  }
485  {
486  return iterator(children_.end());
487  }
488 
489 private:
490  /** The number of grid rows. */
491  unsigned rows_;
492 
493  /** The number of grid columns. */
494  unsigned cols_;
495 
496  /***** ***** ***** ***** size caching ***** ***** ***** *****/
497 
498  /** The row heights in the grid. */
499  mutable std::vector<unsigned> row_height_;
500 
501  /** The column widths in the grid. */
502  mutable std::vector<unsigned> col_width_;
503 
504  /** The grow factor for all rows. */
505  std::vector<unsigned> row_grow_factor_;
506 
507  /** The grow factor for all columns. */
508  std::vector<unsigned> col_grow_factor_;
509 
510  /**
511  * The child items.
512  *
513  * All children are stored in a 1D vector and the formula to access a cell
514  * is: rows_ * col + row. All other vectors use the same access formula.
515  */
516  std::vector<child> children_;
517 
518  /**
519  * Gets the grid child in the specified cell.
520  *
521  * @param row The row of the cell.
522  * @param col The column of the cell.
523  *
524  * @returns A const reference to the specified grid child.
525  */
526  const grid::child& get_child(const unsigned row, const unsigned col) const
527  {
528  return children_[rows_ * col + row];
529  }
530 
531  /**
532  * Gets the grid child in the specified cell.
533  *
534  * @param row The row of the cell.
535  * @param col The column of the cell.
536  *
537  * @returns A const reference to the specified grid child.
538  */
539  grid::child& get_child(const unsigned row, const unsigned col)
540  {
541  return children_[rows_ * col + row];
542  }
543 
544  /**
545  * Gets the grid child containing the specified widget.
546  *
547  * @param w The widget to search for.
548  *
549  * @returns A pointer to the relevant grid child, or nullptr
550  * if no grid cell 'owns' the given widget.
551  */
552  grid::child* get_child(widget* w);
553 
554  /** Layouts the children in the grid. */
555  void layout(const point& origin);
556 
557  /** See @ref widget::impl_draw_children. */
558  virtual void impl_draw_children(surface& frame_buffer,
559  int x_offset,
560  int y_offset) override;
561 };
562 
563 /**
564  * Sets the single child in a grid.
565  *
566  * The function initializes the grid to 1 x 1 and adds the widget with the grow
567  * to client flags.
568  *
569  * @param grid The grid to add the child to.
570  * @param widget The widget to add as child to the grid.
571  */
573 
574 } // namespace gui2
unsigned get_flags() const
Definition: grid.hpp:372
static const unsigned BORDER_TOP
Definition: grid.hpp:62
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
Definition: grid.cpp:604
widget * operator->()
Definition: grid.hpp:457
std::vector< unsigned > row_grow_factor_
The grow factor for all rows.
Definition: grid.hpp:505
virtual void demand_reduce_width(const unsigned maximum_width) override
See widget::demand_reduce_width.
Definition: grid.cpp:272
friend class debug_layout_graph
Definition: grid.hpp:33
widget * operator*()
Definition: grid.hpp:461
iterator begin()
Definition: grid.hpp:480
void set_row_grow_factor(const unsigned row, const unsigned factor)
Sets the grow factor for a row.
Definition: grid.hpp:87
virtual bool can_wrap() const override
See widget::can_wrap.
Definition: grid.cpp:467
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: grid.cpp:682
std::unique_ptr< widget > widget_
Pointer to the widget.
Definition: grid.hpp:432
unsigned cols_
The number of grid columns.
Definition: grid.hpp:494
Child item of the grid.
Definition: grid.hpp:329
iterator(std::vector< child >::iterator itor)
Definition: grid.hpp:445
grid::child & get_child(const unsigned row, const unsigned col)
Gets the grid child in the specified cell.
Definition: grid.hpp:539
unsigned int get_rows() const
Definition: grid.hpp:308
virtual bool has_widget(const widget &widget) const override
See widget::has_widget.
Definition: grid.cpp:667
static const unsigned BORDER_ALL
Definition: grid.hpp:66
Base class for all widgets.
Definition: widget.hpp:49
static const unsigned VERTICAL_SHIFT
Definition: grid.hpp:48
iterator operator--()
Definition: grid.hpp:453
unsigned get_border_size() const
Definition: grid.hpp:382
widget * get_widget(const unsigned row, const unsigned col)
Returns the widget in the selected cell.
Definition: grid.hpp:187
bool operator!=(const iterator &i) const
Definition: grid.hpp:471
grid & operator=(const grid &)=delete
Delete the move assignment operator.
static const unsigned HORIZONTAL_MASK
Definition: grid.hpp:60
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: grid.cpp:232
bool operator==(const iterator &i) const
Definition: grid.hpp:466
point recalculate_best_size()
Recalculates the best size.
Definition: grid.cpp:416
std::vector< child >::iterator itor_
Definition: grid.hpp:477
Generic file dialog.
Definition: field-fwd.hpp:23
unsigned rows_
The number of grid rows.
Definition: grid.hpp:491
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
Definition: grid.cpp:186
Base container class.
Definition: grid.hpp:31
const grid::child & get_child(const unsigned row, const unsigned col) const
Gets the grid child in the specified cell.
Definition: grid.hpp:526
iterator operator++()
Definition: grid.hpp:449
virtual bool can_mouse_focus() const override
Whether the mouse move/click event go &#39;through&#39; this widget.
Definition: grid.hpp:192
static const unsigned HORIZONTAL_SHIFT
Definition: grid.hpp:55
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
void set_flags(const unsigned flags)
Definition: grid.hpp:377
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: grid.cpp:423
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:466
The walker abstract base class.
Definition: walker.hpp:27
Iterator for the child items.
Definition: grid.hpp:441
static const unsigned HORIZONTAL_ALIGN_RIGHT
Definition: grid.hpp:59
static const unsigned BORDER_BOTTOM
Definition: grid.hpp:63
const std::string & id() const
Returns the id of the widget/.
Definition: grid.cpp:903
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
std::vector< unsigned > col_grow_factor_
The grow factor for all columns.
Definition: grid.hpp:508
virtual ~grid()
Definition: grid.cpp:55
std::vector< unsigned > row_height_
The row heights in the grid.
Definition: grid.hpp:499
std::unique_ptr< widget > free_widget()
Releases widget from ownership by this child and returns it in the form of a new unique_ptr.
Definition: grid.hpp:411
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: grid.cpp:656
unsigned int get_cols() const
Definition: grid.hpp:314
void layout(const point &origin)
Layouts the children in the grid.
Definition: grid.cpp:972
void request_placement(dispatcher &dispatcher, const event::ui_event event, bool &handled, bool &halt)
Attempts to lay out the grid without laying out the entire window.
Definition: grid.cpp:375
void place(point origin, point size)
Places the widget in the cell.
Definition: grid.cpp:766
std::vector< child > children_
The child items.
Definition: grid.hpp:516
virtual void place(const point &origin, const point &size) override
See widget::place.
Definition: grid.cpp:480
void set_child(widget *widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
Definition: grid.cpp:70
static const unsigned VERTICAL_ALIGN_TOP
Definition: grid.hpp:50
widget * get_widget()
Definition: grid.hpp:397
std::size_t i
Definition: function.cpp:967
virtual iteration::walker_base * create_walker() override
See widget::create_walker.
Definition: grid.cpp:700
static const unsigned BORDER_RIGHT
Definition: grid.hpp:65
unsigned add_row(const unsigned count=1)
Adds a row to end of the grid.
Definition: grid.cpp:59
void reduce_width(const unsigned maximum_width)
Tries to reduce the width of a container.
Definition: grid.cpp:199
void set_widget(widget *widget)
Definition: grid.hpp:402
void layout_initialize(const bool full_initialization)
Forwards grid::layout_initialize to the cell.
Definition: grid.cpp:894
static const unsigned VERTICAL_ALIGN_CENTER
Definition: grid.hpp:51
bool can_wrap() const
Returns the can_wrap for the cell.
Definition: grid.hpp:364
static const unsigned HORIZONTAL_ALIGN_CENTER
Definition: grid.hpp:58
std::vector< unsigned > col_width_
The column widths in the grid.
Definition: grid.hpp:502
virtual void child_populate_dirty_list(window &caller, const std::vector< widget *> &call_stack) override
See widget::child_populate_dirty_list.
Definition: grid.cpp:628
Holds a 2D point.
Definition: point.hpp:24
static const unsigned VERTICAL_MASK
Definition: grid.hpp:53
void set_active(const bool active)
Activates all children.
Definition: grid.cpp:163
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
Definition: grid.hpp:56
int w
unsigned flags_
The flags for the border and cell setup.
Definition: grid.hpp:418
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
Definition: grid.hpp:49
virtual void set_origin(const point &origin) override
See widget::set_origin.
Definition: grid.cpp:587
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
Definition: grid.cpp:310
void set_single_child(grid &grid, widget *widget)
Sets the single child in a grid.
Definition: grid.cpp:1107
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
Definition: grid.cpp:723
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
Definition: grid.cpp:643
static const unsigned VERTICAL_ALIGN_BOTTOM
Definition: grid.hpp:52
void set_cols(const unsigned cols)
Definition: grid.cpp:714
unsigned border_size_
The size of the border, the actual configuration of the border is determined by the flags...
Definition: grid.hpp:424
void remove_child(const unsigned row, const unsigned col)
Removes and frees a widget in a cell.
Definition: grid.cpp:141
std::unique_ptr< widget > swap_child(const std::string &id, widget *w, const bool recurse, widget *new_parent=nullptr)
Exchanges a child in the grid.
Definition: grid.cpp:99
void set_child_alignment(widget *widget, unsigned set_flag, unsigned mode_mask)
Modifies the widget alignment data of a child cell containing a specific widget.
Definition: grid.cpp:944
virtual void demand_reduce_height(const unsigned maximum_height) override
See widget::demand_reduce_height.
Definition: grid.cpp:370
virtual void layout_children() override
See widget::layout_children.
Definition: grid.cpp:619
void set_border_size(const unsigned border_size)
Definition: grid.hpp:387
static const unsigned HORIZONTAL_ALIGN_LEFT
Definition: grid.hpp:57
void set_rows(const unsigned rows)
Definition: grid.cpp:705
void set_column_grow_factor(const unsigned column, const unsigned factor)
Sets the grow factor for a column.
Definition: grid.hpp:102
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
point border_space() const
Returns the space needed for the border.
Definition: grid.cpp:909
const widget * get_widget(const unsigned row, const unsigned col) const
Returns the widget in the selected cell.
Definition: grid.hpp:181
const widget * get_widget() const
Definition: grid.hpp:392
static const unsigned BORDER_LEFT
Definition: grid.hpp:64
grid(const unsigned rows=0, const unsigned cols=0)
Definition: grid.cpp:40
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
Helper to implement private functions without modifying the header.
point get_best_size() const
Returns the best size for the cell.
Definition: grid.cpp:741
void reduce_height(const unsigned maximum_height)
Tries to reduce the height of a container.
Definition: grid.cpp:277
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
ui_event
The event send to the dispatcher.
Definition: handler.hpp:48
iterator end()
Definition: grid.hpp:484
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See widget::impl_draw_children.
Definition: grid.cpp:994