1 // Basic class for canvas layouts
3 // Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef SG_CANVAS_LAYOUT_HXX_
20 #define SG_CANVAS_LAYOUT_HXX_
22 #include "LayoutItem.hxx"
34 virtual void addItem(const LayoutItemRef& item) = 0;
35 virtual void setSpacing(int spacing) = 0;
36 virtual int spacing() const = 0;
39 * Get the number of items.
41 virtual size_t count() const = 0;
44 * Get the item at position @a index.
46 * If there is no such item the function must do nothing and return an
49 virtual LayoutItemRef itemAt(size_t index) = 0;
52 * Remove and get the item at position @a index.
54 * If there is no such item the function must do nothing and return an
57 virtual LayoutItemRef takeAt(size_t index) = 0;
60 * Remove the given @a item from the layout.
62 void removeItem(const LayoutItemRef& item);
72 LAST_FLAG = LayoutItem::LAST_FLAG
77 LayoutItemRef layout_item;
81 padding_orig, //<! original padding as specified by the user
82 padding, //<! padding before element (layouted)
83 size, //<! layouted size
84 stretch; //<! stretch factor
86 has_hfw : 1, //<! height for width
87 done : 1; //<! layouting done
89 /** Clear values (reset to default/empty state) */
93 int mhfw(int w) const;
96 virtual void contentsRectChanged(const SGRecti& rect);
99 * Override to implement the actual layouting
101 virtual void doLayout(const SGRecti& geom) = 0;
104 * Distribute the available @a space to all @a items
106 void distribute(std::vector<ItemData>& items, const ItemData& space);
110 int _num_not_done, //<! number of children not layouted yet
111 _sum_stretch, //<! sum of stretch factors of all not yet layouted
113 _space_stretch,//<! space currently assigned to all not yet layouted
114 // stretchable children
115 _space_left; //<! remaining space not used by any child yet
119 typedef SGSharedPtr<Layout> LayoutRef;
121 } // namespace canvas
122 } // namespace simgear
125 #endif /* SG_CANVAS_LAYOUT_HXX_ */