The Battle for Wesnoth  1.17.0-dev
horizontal_list.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 
16 /**
17  * @file
18  * Placement helper for the horizontal list.
19  */
20 
21 #pragma once
22 
23 #include "gui/core/placer.hpp"
24 
25 #include <vector>
26 
27 namespace gui2
28 {
29 
30 namespace implementation
31 {
32 
33 /**
34  * The placement class for a horizontal list.
35  *
36  * See @ref placer_base for more information.
37  */
39 {
40 
41 public:
42  /***** ***** Constructor, destructor, assignment. ***** *****/
43 
44  explicit placer_horizontal_list(const unsigned maximum_rows);
45 
46 
47  /***** ***** Inherited operations. ***** *****/
48 
49  virtual void initialize();
50 
51  virtual void add_item(const point& size);
52 
53  virtual point get_size() const;
54 
55  virtual point get_origin(const unsigned index) const;
56 
57 
58  /***** ***** Members. ***** *****/
59 
60 private:
61  /**
62  * The maximum number of rows to use.
63  *
64  * This value is determined by the @p parallel_items parameter of
65  * @ref placer_base::build).
66  */
67  unsigned maximum_rows_;
68 
69  /** Holds the heights of the rows. */
70  std::vector<int> rows_;
71 
72  /**
73  * Holds the column sizes
74  *
75  * The pair contains the following values:
76  * * first The origin of a column.
77  * * second The width of a column.
78  */
79  std::vector<std::pair<int, int>> columns_;
80 
81  /** The row to add an item to. */
82  unsigned row_;
83 
84  /** The column to add an item to. */
85  unsigned column_;
86 };
87 
88 } // namespace implementation
89 
90 } // namespace gui2
Base class for the placement helper.
Base class for the placement helper.
Definition: placer.hpp:51
unsigned column_
The column to add an item to.
virtual void initialize()
Initialises the placer.
virtual point get_size() const
Gets the required size of all items.
unsigned maximum_rows_
The maximum number of rows to use.
placer_horizontal_list(const unsigned maximum_rows)
virtual void add_item(const point &size)
Adds a item to be placed.
Generic file dialog.
Definition: field-fwd.hpp:23
std::vector< std::pair< int, int > > columns_
Holds the column sizes.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
virtual point get_origin(const unsigned index) const
Gets the origin for an item.
std::vector< int > rows_
Holds the heights of the rows.
The placement class for a horizontal list.
Holds a 2D point.
Definition: point.hpp:24
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:72
unsigned row_
The row to add an item to.
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.