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);
48 void addStretch(int stretch = 0);
50 void addSpacing(int size);
52 void insertItem(int index, const LayoutItemRef& item, int stretch = 0);
54 void insertStretch(int index, int stretch = 0);
56 void insertSpacing(int index, int size);
58 virtual size_t count() const;
59 virtual LayoutItemRef itemAt(size_t index);
60 virtual LayoutItemRef takeAt(size_t index);
64 * Set the stretch factor of the item at position @a index to @a stretch.
66 void setStretch(size_t index, int stretch);
69 * Get the stretch factor of the item at position @a index
71 int stretch(size_t index) const;
73 virtual void setSpacing(int spacing);
74 virtual int spacing() const;
76 void setDirection(Direction dir);
77 Direction direction() const;
79 virtual bool hasHeightForWidth() const;
80 virtual int heightForWidth(int w) const;
81 virtual int minimumHeightForWidth(int w) const;
83 virtual void setCanvas(const CanvasWeakPtr& canvas);
89 typedef const int& (SGVec2i::*CoordGetter)() const;
90 CoordGetter _get_layout_coord, //<! getter for coordinate in layout
92 _get_fixed_coord; //<! getter for coordinate in secondary
98 typedef std::vector<ItemData> LayoutItems;
100 mutable LayoutItems _layout_items;
101 mutable ItemData _layout_data;
103 // Cache for last height-for-width query
104 mutable int _hfw_width,
108 void updateSizeHints() const;
109 void updateWFHCache(int w) const;
111 virtual SGVec2i sizeHintImpl() const;
112 virtual SGVec2i minimumSizeImpl() const;
113 virtual SGVec2i maximumSizeImpl() const;
115 virtual void doLayout(const SGRecti& geom);
119 * Shortcut for creating a horizontal box layout
129 * Shortcut for creating a vertical box layout
138 typedef SGSharedPtr<BoxLayout> BoxLayoutRef;
140 } // namespace canvas
141 } // namespace simgear
144 #endif /* SG_CANVAS_BOX_LAYOUT_HXX_ */