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"
31 * Base class for all Canvas layouts.
37 virtual void addItem(const LayoutItemRef& item) = 0;
38 virtual void setSpacing(int spacing) = 0;
39 virtual int spacing() const = 0;
42 * Get the number of items.
44 virtual size_t count() const = 0;
47 * Get the item at position @a index.
49 * If there is no such item the function must do nothing and return an
52 virtual LayoutItemRef itemAt(size_t index) = 0;
55 * Remove and get the item at position @a index.
57 * If there is no such item the function must do nothing and return an
60 virtual LayoutItemRef takeAt(size_t index) = 0;
63 * Remove the given @a item from the layout.
65 void removeItem(const LayoutItemRef& item);
73 * Get the actual geometry of this layout given the rectangle \a geom
74 * taking into account the alignment flags and size hints. For layouts,
75 * if no alignment (different to AlignFill) is set, the whole area is
76 * used. Excess space is distributed by the layouting algorithm and
77 * handled by the individual children.
79 * @param geom Area available to this layout.
80 * @return The resulting geometry for this layout.
82 virtual SGRecti alignmentRect(const SGRecti& geom) const;
87 LAST_FLAG = LayoutItem::LAST_FLAG
92 LayoutItemRef layout_item;
96 padding_orig, //!< original padding as specified by the user
97 padding, //!< padding before element (layouted)
98 size, //!< layouted size
99 stretch; //!< stretch factor
101 has_align: 1, //!< Has alignment factor set (!= AlignFill)
102 has_hfw : 1, //!< height for width
103 done : 1; //!< layouting done
105 /** Clear values (reset to default/empty state) */
108 int hfw(int w) const;
109 int mhfw(int w) const;
114 virtual void contentsRectChanged(const SGRecti& rect);
117 * Override to implement the actual layouting
119 virtual void doLayout(const SGRecti& geom) = 0;
122 * Distribute the available @a space to all @a items
124 void distribute(std::vector<ItemData>& items, const ItemData& space);
128 int _num_not_done, //!< number of children not layouted yet
129 _sum_stretch, //!< sum of stretch factors of all not yet layouted
131 _space_stretch,//!< space currently assigned to all not yet layouted
132 // stretchable children
133 _space_left; //!< remaining space not used by any child yet
137 typedef SGSharedPtr<Layout> LayoutRef;
139 } // namespace canvas
140 } // namespace simgear
143 #endif /* SG_CANVAS_LAYOUT_HXX_ */