1 // 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 #include "LayoutItem.hxx"
20 #include <simgear/canvas/Canvas.hxx>
27 //----------------------------------------------------------------------------
28 LayoutItem::LayoutItem():
34 //----------------------------------------------------------------------------
35 LayoutItem::~LayoutItem()
40 //----------------------------------------------------------------------------
41 SGVec2i LayoutItem::sizeHint() const
43 if( _flags & SIZE_HINT_DIRTY )
45 _size_hint = sizeHintImpl();
46 _flags &= ~SIZE_HINT_DIRTY;
52 //----------------------------------------------------------------------------
53 SGVec2i LayoutItem::minimumSize() const
55 if( _flags & MINIMUM_SIZE_DIRTY )
57 _min_size = minimumSizeImpl();
58 _flags &= ~MINIMUM_SIZE_DIRTY;
64 //----------------------------------------------------------------------------
65 SGVec2i LayoutItem::maximumSize() const
67 if( _flags & MAXIMUM_SIZE_DIRTY )
69 _max_size = maximumSizeImpl();
70 _flags &= ~MAXIMUM_SIZE_DIRTY;
76 //----------------------------------------------------------------------------
77 void LayoutItem::invalidate()
79 _flags |= SIZE_HINT_DIRTY
86 //----------------------------------------------------------------------------
87 void LayoutItem::invalidateParent()
89 LayoutItemRef parent = _parent.lock();
94 //----------------------------------------------------------------------------
95 void LayoutItem::setGeometry(const SGRecti& geom)
100 //----------------------------------------------------------------------------
101 SGRecti LayoutItem::geometry() const
106 //----------------------------------------------------------------------------
107 void LayoutItem::setCanvas(const CanvasWeakPtr& canvas)
112 //----------------------------------------------------------------------------
113 CanvasPtr LayoutItem::getCanvas() const
115 return _canvas.lock();
118 //----------------------------------------------------------------------------
119 void LayoutItem::setParent(const LayoutItemWeakRef& parent)
122 LayoutItemRef parent_ref = parent.lock();
123 setCanvas(parent_ref ? parent_ref->_canvas : CanvasWeakPtr());
126 //----------------------------------------------------------------------------
127 LayoutItemRef LayoutItem::getParent() const
129 return _parent.lock();
132 //----------------------------------------------------------------------------
133 SGVec2i LayoutItem::sizeHintImpl() const
135 return SGVec2i(16, 16);
138 //----------------------------------------------------------------------------
139 SGVec2i LayoutItem::minimumSizeImpl() const
141 return SGVec2i(0, 0);
144 //----------------------------------------------------------------------------
145 SGVec2i LayoutItem::maximumSizeImpl() const
147 return SGVec2i(SGLimits<int>::max(), SGLimits<int>::max());
150 } // namespace canvas
151 } // namespace simgear