1 // Align items horizontally or vertically in a box
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_BOX_LAYOUT_HXX_
20 #define SG_CANVAS_BOX_LAYOUT_HXX_
42 BoxLayout(Direction dir);
44 virtual void addItem(const LayoutItemRef& item);
46 void addItem(const LayoutItemRef& item, int stretch);
49 * Set the stretch factor of the item at position @a index to @a stretch.
51 void setStretch(size_t index, int stretch);
54 * Get the stretch factor of the item at position @a index
56 int stretch(size_t index) const;
58 virtual void setSpacing(int spacing);
59 virtual int spacing() const;
61 void setDirection(Direction dir);
62 Direction direction() const;
64 virtual void setCanvas(const CanvasWeakPtr& canvas);
68 typedef const int& (SGVec2i::*CoordGetter)() const;
69 CoordGetter _get_layout_coord, //<! getter for coordinate in layout
71 _get_fixed_coord; //<! getter for coordinate in secondary
75 bool _reverse; //<! if true, right-to-left/bottom-to-top layouting
77 mutable std::vector<ItemData> _layout_items;
78 mutable ItemData _layout_data;
80 void updateSizeHints() const;
82 virtual SGVec2i sizeHintImpl() const;
83 virtual SGVec2i minimumSizeImpl() const;
84 virtual SGVec2i maximumSizeImpl() const;
86 virtual void doLayout(const SGRecti& geom);
90 * Shortcut for creating a horizontal box layout
100 * Shortcut for creating a vertical box layout
109 } // namespace canvas
110 } // namespace simgear
113 #endif /* SG_CANVAS_BOX_LAYOUT_HXX_ */