neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
layout.hpp
Go to the documentation of this file.
1// 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 <list>
24#include <boost/pool/pool_alloc.hpp>
28#include <neogfx/core/units.hpp>
34
35namespace neogfx
36{
37 class i_spacer;
38
39 class layout : public layout_item<object<i_layout>>
40 {
42 public:
43 define_declared_event(LayoutCompleted, layout_completed)
44 define_declared_event(AlignmentChanged, alignment_changed)
45 public:
46 struct item_already_added : std::logic_error { item_already_added() : std::logic_error("neogfx::layout::item_already_added") {} };
47 struct widget_is_floating : std::logic_error { widget_is_floating() : std::logic_error("neogfx::layout::widget_is_floating") {} };
48 public:
50 protected:
52 typedef std::list<item> item_list;
60 protected:
61 template <typename SpecializedPolicy>
63 template <typename Layout>
65 template <typename Layout>
66 struct row_major;
67 public:
68 layout(optional_alignment const& aAlignment = {});
69 layout(i_widget& aOwner, optional_alignment const& aAlignment = {});
70 layout(i_layout& aParent, optional_alignment const& aAlignment = {});
71 layout(const layout&) = delete;
73 public:
74 bool has_parent_layout() const final;
75 const i_layout& parent_layout() const final;
77 void set_parent_layout(i_layout* aParentLayout) final;
78 bool has_parent_widget() const final;
79 const i_widget& parent_widget() const final;
81 void set_parent_widget(i_widget* aParentWidget) final;
82 public:
83 i_layout_item& add(i_layout_item& aItem) override;
85 i_layout_item& add(i_ref_ptr<i_layout_item> const& aItem) override;
86 i_layout_item& add_at(layout_item_index aPosition, i_ref_ptr<i_layout_item> const& aItem) override;
87 void remove_at(layout_item_index aIndex) override;
88 bool remove(i_layout_item& aItem) override;
89 void remove_all() override;
90 void move_all_to(i_layout& aDestination) override;
91 layout_item_index count() const override;
92 layout_item_index index_of(const i_layout_item& aItem) const override;
93 optional_layout_item_index find(const i_layout_item& aItem) const override;
94 bool is_widget_at(layout_item_index aIndex) const override;
95 const i_layout_item& item_at(layout_item_index aIndex) const override;
98 const i_widget& get_widget_at(layout_item_index aIndex) const override;
100 const i_layout& get_layout_at(layout_item_index aIndex) const override;
102 public:
103 neogfx::margin margin() const override;
104 neogfx::padding padding() const override;
105 public:
106 layout_direction direction() const override;
107 bool has_spacing() const override;
108 size spacing() const override;
109 void set_spacing(optional_size const& aSpacing, bool aUpdateLayout = true) override;
110 bool always_use_spacing() const override;
111 void set_always_use_spacing(bool aAlwaysUseSpacing) override;
112 bool has_alignment() const override;
113 neogfx::alignment alignment() const override;
114 void set_alignment(optional_alignment const& aAlignment, bool aUpdateLayout = true) override;
115 neogfx::autoscale autoscale() const override;
116 void set_autoscale(neogfx::autoscale aAutoscale, bool aUpdateLayout = true) override;
118 bool ignore_child_visibility() const override;
119 void set_ignore_child_visibility(bool aIgnoreChildVisibility) override;
120 public:
121 using i_layout::enable;
122 void enable(bool aEnable) override;
123 bool enabled() const override;
124 bool invalidated() const override;
125 void invalidate(bool aDeferLayout = true) override;
126 void validate() override;
127 public:
128 void set_extents(const size& aExtents) override;
129 neogfx::size_policy size_policy() const override;
130 public:
131 bool device_metrics_available() const override;
132 const i_device_metrics& device_metrics() const override;
133 public:
134 void layout_as(const point& aPosition, const size& aSize) override;
135 public:
136 void fix_weightings(bool aRecalculate = true) override;
137 protected:
138 void layout_item_enabled(i_layout_item& aItem) override;
139 void layout_item_disabled(i_layout_item& aItem) override;
140 public:
141 bool visible() const override;
142 protected:
143 item_list::const_iterator cbegin() const;
144 item_list::const_iterator cend() const;
145 item_list::const_iterator begin() const;
146 item_list::const_iterator end() const;
147 item_list::iterator begin();
148 item_list::iterator end();
149 item_list::const_reverse_iterator rbegin() const;
150 item_list::const_reverse_iterator rend() const;
151 item_list::reverse_iterator rbegin();
152 item_list::reverse_iterator rend();
153 item_list::const_iterator find_item(const i_layout_item& aItem) const;
155 const item_list& items() const;
157 virtual void remove(item_list::iterator aItem);
158 uint32_t spacer_count() const;
159 uint32_t items_visible(item_type_e aItemType = static_cast<item_type_e>(ItemTypeWidget|ItemTypeLayout)) const;
160 template <typename AxisPolicy>
161 size do_minimum_size(optional_size const& aAvailableSpace) const;
162 template <typename AxisPolicy>
163 size do_maximum_size(optional_size const& aAvailableSpace) const;
164 template <typename AxisPolicy>
165 void do_layout_items(const point& aPosition, const size& aSize);
166 // helpers
167 public:
168 using i_layout::add;
169 using i_layout::add_at;
170 private:
171 i_layout* iParent;
172 mutable i_widget* iOwner;
173 mutable std::optional<const i_device_metrics*> iDeviceMetrics;
174 optional_size iSpacing;
175 bool iAlwaysUseSpacing;
176 optional_alignment iAlignment;
177 neogfx::autoscale iAutoscale;
178 visibility_constraint iChildVisibility;
179 bool iEnabled;
180 item_list iItems;
181 bool iLayoutStarted;
182 bool iInvalidated;
183 };
184}
i_layout_item & add_at(layout_item_index aPosition, i_layout_item &aItem) override
void remove_at(layout_item_index aIndex) override
visibility_constraint child_visibility() const override
item_list::const_reverse_iterator rend() const
item_list::const_reverse_iterator rbegin() const
bool enabled() const override
bool visible() const override
item_list::const_iterator end() const
bool is_widget_at(layout_item_index aIndex) const override
bool always_use_spacing() const override
void remove_all() override
optional_layout_item_index find(const i_layout_item &aItem) const override
void set_spacing(optional_size const &aSpacing, bool aUpdateLayout=true) override
const i_layout_item & item_at(layout_item_index aIndex) const override
item_list::const_iterator begin() const
const i_device_metrics & device_metrics() const override
i_layout abstract_type
Definition layout.hpp:49
void set_parent_layout(i_layout *aParentLayout) final
bool has_parent_layout() const final
void layout_item_enabled(i_layout_item &aItem) override
const i_layout & get_layout_at(layout_item_index aIndex) const override
bool has_spacing() const override
bool remove(i_layout_item &aItem) override
void layout_as(const point &aPosition, const size &aSize) override
bool has_parent_widget() const final
void fix_weightings(bool aRecalculate=true) override
ref_ptr< i_layout_item_cache > item
Definition layout.hpp:51
layout(optional_alignment const &aAlignment={})
layout(const layout &)=delete
bool invalidated() const override
const item_list & items() const
neogfx::size_policy size_policy() const override
void validate() override
void move_all_to(i_layout &aDestination) override
const i_widget & get_widget_at(layout_item_index aIndex) const override
void set_parent_widget(i_widget *aParentWidget) final
layout(i_layout &aParent, optional_alignment const &aAlignment={})
layout_item_index index_of(const i_layout_item &aItem) const override
uint32_t items_visible(item_type_e aItemType=static_cast< item_type_e >(ItemTypeWidget|ItemTypeLayout)) const
item_list::const_iterator cbegin() const
uint32_t spacer_count() const
bool ignore_child_visibility() const override
layout(i_widget &aOwner, optional_alignment const &aAlignment={})
void set_ignore_child_visibility(bool aIgnoreChildVisibility) override
const i_layout & parent_layout() const final
layout_direction direction() const override
item_list::const_iterator find_item(const i_layout_item &aItem) const
std::list< item > item_list
Definition layout.hpp:52
void layout_item_disabled(i_layout_item &aItem) override
void do_layout_items(const point &aPosition, const size &aSize)
void set_alignment(optional_alignment const &aAlignment, bool aUpdateLayout=true) override
void set_autoscale(neogfx::autoscale aAutoscale, bool aUpdateLayout=true) override
bool has_alignment() const override
void invalidate(bool aDeferLayout=true) override
layout_item_index count() const override
size spacing() const override
bool device_metrics_available() const override
void set_extents(const size &aExtents) override
size do_maximum_size(optional_size const &aAvailableSpace) const
item_list::const_iterator cend() const
size do_minimum_size(optional_size const &aAvailableSpace) const
void set_always_use_spacing(bool aAlwaysUseSpacing) override
ItemType & add()
Definition i_layout.hpp:292
const i_widget & parent_widget() const final
visibility_constraint
uint32_t layout_item_index
Definition i_layout.hpp:35
std::optional< layout_item_index > optional_layout_item_index
Definition i_layout.hpp:36
layout_direction
Definition i_layout.hpp:209
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28
#define define_declared_event(name, declName,...)
Definition event.hpp:195