neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
grid_layout.hpp
Go to the documentation of this file.
1// grid_layout.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
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 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <map>
24#include <boost/pool/pool_alloc.hpp>
25#include "layout.hpp"
26#include "vertical_layout.hpp"
27#include "horizontal_layout.hpp"
28
29namespace neogfx
30{
31 class grid_layout : public layout
32 {
34 public:
35 struct cell_unoccupied : std::logic_error { cell_unoccupied() : std::logic_error("neogfx::grid_layout::cell_unoccupied") {} };
36 public:
37 typedef uint32_t cell_coordinate;
40 private:
41 struct row_major;
42 struct column_major;
43 typedef std::map<cell_coordinates, i_layout_item*, std::less<cell_coordinates>, neolib::fast_pool_allocator<std::pair<const cell_coordinates, i_layout_item*>>> cell_list;
44 typedef std::vector<std::pair<cell_coordinates, cell_coordinates>> span_list;
45 public:
53 public:
59 i_layout_item& add(i_layout_item& aItem) override;
63 i_spacer& add_spacer() override;
64 i_spacer& add_spacer_at(layout_item_index aPosition) override;
65 virtual i_spacer& add_spacer_at_position(cell_coordinate aRow, cell_coordinate aColumn);
74 void remove_all() override;
75 public:
76 void invalidate(bool aDeferLayout = true) override;
77 public:
78 size minimum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
79 size maximum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
80 public:
82 public:
83 void set_spacing(optional_size const& aSpacing, bool aUpdateLayout = true) override;
84 grid_layout& add_span(cell_coordinate aRowFrom, cell_coordinate aColumnFrom, uint32_t aRows, uint32_t aColumns);
86 void set_alignment(optional_alignment const& aAlignment, bool aUpdateLayout = true) override;
87 public:
88 void layout_items(const point& aPosition, const size& aSize) override;
89 public:
90 const cell_coordinates& cursor() const;
91 protected:
92 void remove(item_list::iterator aItem);
93 private:
94 uint32_t visible_rows() const;
95 bool is_row_visible(uint32_t aRow) const;
96 uint32_t visible_columns() const;
97 bool is_column_visible(uint32_t aColumn) const;
98 size::dimension_type row_minimum_size(cell_coordinate aRow, optional_size const& aAvailableSpace = optional_size{}) const;
99 size::dimension_type column_minimum_size(cell_coordinate aColumn, optional_size const& aAvailableSpace = optional_size{}) const;
100 size::dimension_type row_maximum_size(cell_coordinate aRow, optional_size const& aAvailableSpace = optional_size{}) const;
101 size::dimension_type column_maximum_size(cell_coordinate aColumn, optional_size const& aAvailableSpace = optional_size{}) const;
102 void increment_cursor();
103 horizontal_layout& row_layout(cell_coordinate aRow);
104 span_list::const_iterator find_span(const cell_coordinates& aCell) const;
105 void init();
106 // helpers
107 public:
108 using layout::add;
109 using layout::add_at;
110 template <typename ItemType>
112 {
113 return static_cast<ItemType&>(add_item_at_position(aRow, aColumn, to_abstract(static_pointer_cast<i_layout_item>(aItem))));
114 }
115 template <typename ItemType>
117 {
118 return static_cast<ItemType&>(add_item_at_position(aRow, aColumn, to_abstract(static_pointer_cast<i_layout_item>(aItem))));
119 }
120
121 template <typename WidgetT>
123 {
124 return static_cast<WidgetT&>(widget_at_position(aRow, aColumn));
125 }
126 private:
127 cell_list iCells;
128 cell_dimensions iDimensions;
129 cell_coordinates iCursor;
130 span_list iSpans;
131 vertical_layout iRowLayout;
132 std::vector<ref_ptr<horizontal_layout>> iRows;
133 };
134}
i_spacer & add_spacer() override
cell_coordinates dimensions() const
grid_layout(cell_coordinate aRows, cell_coordinate aColumns, neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
grid_layout & set_dimensions(cell_coordinate aRows, cell_coordinate aColumns)
i_layout_item & item_at_position(cell_coordinate aRow, cell_coordinate aColumn)
grid_layout(i_widget &aParent, cell_coordinate aRows, cell_coordinate aColumns, neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
cell_coordinates item_position(const i_layout_item &aItem) const
ItemType & add_item_at_position(cell_coordinate aRow, cell_coordinate aColumn, ref_ptr< ItemType > const &aItem)
grid_layout(i_widget &aParent, neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
virtual i_layout_item & add_item_at_position(cell_coordinate aRow, cell_coordinate aColumn, i_ref_ptr< i_layout_item > const &aItem)
basic_size< cell_coordinate > cell_dimensions
i_layout const & layout_at_position(cell_coordinate aRow, cell_coordinate aColumn) const
ItemType & add_item_at_position(cell_coordinate aRow, cell_coordinate aColumn, i_ref_ptr< ItemType > const &aItem)
i_layout & layout_at_position(cell_coordinate aRow, cell_coordinate aColumn)
basic_point< cell_coordinate > cell_coordinates
void remove(item_list::iterator aItem)
i_spacer & add_spacer_at(layout_item_index aPosition) override
i_layout_item const & item_at_position(cell_coordinate aRow, cell_coordinate aColumn) const
void layout_items(const point &aPosition, const size &aSize) override
WidgetT & widget_at_position(cell_coordinate aRow, cell_coordinate aColumn)
void set_alignment(optional_alignment const &aAlignment, bool aUpdateLayout=true) override
void invalidate(bool aDeferLayout=true) override
size minimum_size(optional_size const &aAvailableSpace=optional_size{}) const override
grid_layout & add_span(const cell_coordinates &aFrom, const cell_coordinates &aTo)
virtual void remove_item_at_position(cell_coordinate aRow, cell_coordinate aColumn)
bool is_item_at_position(cell_coordinate aRow, cell_coordinate aColumn) const
i_widget const & widget_at_position(cell_coordinate aRow, cell_coordinate aColumn) const
void set_spacing(optional_size const &aSpacing, bool aUpdateLayout=true) override
void remove_all() override
grid_layout(neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
i_widget & widget_at_position(cell_coordinate aRow, cell_coordinate aColumn)
i_layout_item & add(i_layout_item &aItem) override
virtual i_layout_item & add_item_at_position(cell_coordinate aRow, cell_coordinate aColumn, i_layout_item &aItem)
virtual i_spacer & add_spacer_at_position(cell_coordinate aRow, cell_coordinate aColumn)
cell_coordinate rows() const
grid_layout(i_layout &aParent, cell_coordinate aRows, cell_coordinate aColumns, neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
i_layout_item & add(i_ref_ptr< i_layout_item > const &aItem) override
size maximum_size(optional_size const &aAvailableSpace=optional_size{}) const override
grid_layout(i_layout &aParent, neogfx::alignment aAlignment=neogfx::alignment::Center|neogfx::alignment::VCenter)
const cell_coordinates & cursor() const
cell_coordinate columns() const
grid_layout & add_span(cell_coordinate aRowFrom, cell_coordinate aColumnFrom, uint32_t aRows, uint32_t aColumns)
void invalidate_combined_transformation() override
i_layout_item & add_at(layout_item_index aPosition, i_layout_item &aItem) override
ItemType & add()
Definition i_layout.hpp:292
uint32_t layout_item_index
Definition i_layout.hpp:35
optional< size > optional_size
boost::fast_pool_allocator< T, boost::default_user_allocator_new_delete, boost::details::pool::null_mutex, NextSize > fast_pool_allocator
#define meta_object(...)
Definition i_object.hpp:28