1 ///@file Basic element for layouting canvas elements
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_ITEM_HXX_
20 #define SG_CANVAS_LAYOUT_ITEM_HXX_
22 #include <simgear/canvas/canvas_fwd.hxx>
23 #include <simgear/math/SGMath.hxx>
24 #include <simgear/math/SGRect.hxx>
25 #include <simgear/misc/stdint.hxx>
26 #include <simgear/structure/SGWeakReferenced.hxx>
27 #include <simgear/structure/SGSharedPtr.hxx>
34 typedef SGSharedPtr<LayoutItem> LayoutItemRef;
35 typedef SGWeakPtr<LayoutItem> LayoutItemWeakRef;
38 * Base class for all layouting elements. Specializations either implement a
39 * layouting algorithm or a widget.
42 public virtual SGVirtualWeakReferenced
46 static const SGVec2i MAX_SIZE;
49 virtual ~LayoutItem();
52 * Get the preferred size of this item.
54 SGVec2i sizeHint() const;
57 * Get the minimum amount of the space this item requires.
59 SGVec2i minimumSize() const;
62 * Get the maximum amount of space this item can use.
64 SGVec2i maximumSize() const;
66 virtual bool hasHeightForWidth() const;
67 virtual int heightForWidth(int w) const;
68 virtual int minimumHeightForWidth(int w) const;
71 * Mark all cached data as invalid and require it to be recalculated.
73 virtual void invalidate();
76 * Mark all cached data of parent item as invalid (if it is known)
78 void invalidateParent();
81 * Set position and size of this element. For layouts this triggers a
82 * recalculation of the layout.
84 virtual void setGeometry(const SGRecti& geom);
87 * Get position and size of this element.
89 virtual SGRecti geometry() const;
92 * Set the canvas this item is attached to.
94 virtual void setCanvas(const CanvasWeakPtr& canvas);
97 * Get the canvas this item is attached to.
99 CanvasPtr getCanvas() const;
102 * Set the parent layout item (usually this is a layout).
104 void setParent(const LayoutItemWeakRef& parent);
107 * Get the parent layout.
109 LayoutItemRef getParent() const;
118 MINIMUM_SIZE_DIRTY = SIZE_HINT_DIRTY << 1,
119 MAXIMUM_SIZE_DIRTY = MINIMUM_SIZE_DIRTY << 1,
120 SIZE_INFO_DIRTY = SIZE_HINT_DIRTY
122 | MAXIMUM_SIZE_DIRTY,
123 LAST_FLAG = MAXIMUM_SIZE_DIRTY
126 CanvasWeakPtr _canvas;
127 LayoutItemWeakRef _parent;
131 mutable uint32_t _flags;
132 mutable SGVec2i _size_hint,
136 virtual SGVec2i sizeHintImpl() const;
137 virtual SGVec2i minimumSizeImpl() const;
138 virtual SGVec2i maximumSizeImpl() const;
142 } // namespace canvas
143 } // namespace simgear
145 #endif /* SG_CANVAS_LAYOUT_ITEM_HXX_ */