The Battle for Wesnoth  1.19.7+dev
vertical_list.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2024
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 vertical 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 vertical list.
35  *
36  * See @ref placer_base for more information.
37  */
39 {
40 public:
41  /***** ***** Constructor, destructor, assignment. ***** *****/
42 
43  explicit placer_vertical_list(const unsigned maximum_columns);
44 
45 
46  /***** ***** Inherited operations. ***** *****/
47 
48  virtual void initialize();
49 
50  virtual void add_item(const point& size);
51 
52  virtual point get_size() const;
53 
54  virtual point get_origin(const unsigned index) const;
55 
56 
57  /***** ***** Members. ***** *****/
58 
59 private:
60  /**
61  * The maximum number of columns to use.
62  *
63  * This value is determined by the @p parallel_items parameter of
64  * @ref placer_base::build).
65  */
66  unsigned maximum_columns_;
67 
68  /**
69  * Holds the row sizes
70  *
71  * The pair contains the following values:
72  * * first The origin of a row.
73  * * second The height of a row.
74  */
75  std::vector<std::pair<int, int>> rows_;
76 
77  /** Holds the widths of the columns. */
78  std::vector<int> columns_;
79 
80  /** The row to add an item to. */
81  unsigned row_;
82 
83  /** The column to add an item to. */
84  unsigned column_;
85 };
86 
87 } // namespace implementation
88 
89 } // namespace gui2
The placement class for a vertical list.
std::vector< std::pair< int, int > > rows_
Holds the row sizes.
std::vector< int > columns_
Holds the widths of the columns.
unsigned row_
The row to add an item to.
virtual void add_item(const point &size)
Adds a item to be placed.
virtual point get_origin(const unsigned index) const
Gets the origin for an item.
virtual void initialize()
Initialises the placer.
unsigned column_
The column to add an item to.
unsigned maximum_columns_
The maximum number of columns to use.
virtual point get_size() const
Gets the required size of all items.
placer_vertical_list(const unsigned maximum_columns)
Base class for the placement helper.
Definition: placer.hpp:52
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
Base class for the placement helper.
Holds a 2D point.
Definition: point.hpp:25