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_
30 * Align LayoutItems horizontally or vertically in a box.
32 * @see http://qt-project.org/doc/qt-4.8/qboxlayout.html#details
47 BoxLayout(Direction dir);
50 virtual void addItem(const LayoutItemRef& item);
52 void addItem( const LayoutItemRef& item,
54 uint8_t alignment = 0 );
56 void addStretch(int stretch = 0);
58 void addSpacing(int size);
60 void insertItem( int index,
61 const LayoutItemRef& item,
63 uint8_t alignment = 0 );
65 void insertStretch(int index, int stretch = 0);
67 void insertSpacing(int index, int size);
69 virtual size_t count() const;
70 virtual LayoutItemRef itemAt(size_t index);
71 virtual LayoutItemRef takeAt(size_t index);
75 * Set the stretch factor of the item at position @a index to @a stretch.
77 void setStretch(size_t index, int stretch);
80 * Set the stretch factor of the given @a item to @a stretch, if it exists
83 * @return true, if the @a item was found in the layout
85 bool setStretchFactor(const LayoutItemRef& item, int stretch);
88 * Get the stretch factor of the item at position @a index
90 int stretch(size_t index) const;
92 virtual void setSpacing(int spacing);
93 virtual int spacing() const;
95 void setDirection(Direction dir);
96 Direction direction() const;
98 virtual bool hasHeightForWidth() const;
100 virtual void setCanvas(const CanvasWeakPtr& canvas);
106 typedef const int& (SGVec2i::*CoordGetter)() const;
107 CoordGetter _get_layout_coord, //!< getter for coordinate in layout
109 _get_fixed_coord; //!< getter for coordinate in secondary
113 Direction _direction;
115 typedef std::vector<ItemData> LayoutItems;
117 mutable LayoutItems _layout_items;
118 mutable ItemData _layout_data;
120 // Cache for last height-for-width query
121 mutable int _hfw_width,
125 void updateSizeHints() const;
126 void updateWFHCache(int w) const;
128 virtual SGVec2i sizeHintImpl() const;
129 virtual SGVec2i minimumSizeImpl() const;
130 virtual SGVec2i maximumSizeImpl() const;
132 virtual int heightForWidthImpl(int w) const;
133 virtual int minimumHeightForWidthImpl(int w) const;
135 virtual void doLayout(const SGRecti& geom);
137 virtual void visibilityChanged(bool visible);
141 * Shortcut for creating a horizontal box layout
151 * Shortcut for creating a vertical box layout
160 typedef SGSharedPtr<BoxLayout> BoxLayoutRef;
162 } // namespace canvas
163 } // namespace simgear
166 #endif /* SG_CANVAS_BOX_LAYOUT_HXX_ */