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>
26 const SGVec2i LayoutItem::MAX_SIZE( SGLimits<int>::max(),
27 SGLimits<int>::max() );
29 //----------------------------------------------------------------------------
30 LayoutItem::LayoutItem():
39 //----------------------------------------------------------------------------
40 LayoutItem::~LayoutItem()
45 //----------------------------------------------------------------------------
46 SGVec2i LayoutItem::sizeHint() const
48 if( _flags & SIZE_HINT_DIRTY )
50 _size_hint = sizeHintImpl();
51 _flags &= ~SIZE_HINT_DIRTY;
57 //----------------------------------------------------------------------------
58 SGVec2i LayoutItem::minimumSize() const
60 if( _flags & MINIMUM_SIZE_DIRTY )
62 _min_size = minimumSizeImpl();
63 _flags &= ~MINIMUM_SIZE_DIRTY;
69 //----------------------------------------------------------------------------
70 SGVec2i LayoutItem::maximumSize() const
72 if( _flags & MAXIMUM_SIZE_DIRTY )
74 _max_size = maximumSizeImpl();
75 _flags &= ~MAXIMUM_SIZE_DIRTY;
81 //----------------------------------------------------------------------------
82 bool LayoutItem::hasHeightForWidth() const
87 //----------------------------------------------------------------------------
88 int LayoutItem::heightForWidth(int w) const
93 //------------------------------------------------------------------------------
94 int LayoutItem::minimumHeightForWidth(int w) const
96 return heightForWidth(w);
99 //----------------------------------------------------------------------------
100 void LayoutItem::setVisible(bool visible)
103 _flags &= ~EXPLICITLY_HIDDEN;
105 _flags |= EXPLICITLY_HIDDEN;
107 setVisibleInternal(visible);
110 //----------------------------------------------------------------------------
111 bool LayoutItem::isVisible() const
113 return _flags & VISIBLE;
116 //----------------------------------------------------------------------------
117 bool LayoutItem::isExplicitlyHidden() const
119 return _flags & EXPLICITLY_HIDDEN;
122 //----------------------------------------------------------------------------
123 void LayoutItem::invalidate()
125 _flags |= SIZE_INFO_DIRTY;
129 //----------------------------------------------------------------------------
130 void LayoutItem::invalidateParent()
132 LayoutItemRef parent = _parent.lock();
134 parent->invalidate();
137 //----------------------------------------------------------------------------
138 void LayoutItem::setGeometry(const SGRecti& geom)
143 //----------------------------------------------------------------------------
144 SGRecti LayoutItem::geometry() const
149 //----------------------------------------------------------------------------
150 void LayoutItem::setCanvas(const CanvasWeakPtr& canvas)
155 //----------------------------------------------------------------------------
156 CanvasPtr LayoutItem::getCanvas() const
158 return _canvas.lock();
161 //----------------------------------------------------------------------------
162 void LayoutItem::setParent(const LayoutItemWeakRef& parent)
165 LayoutItemRef parent_ref = parent.lock();
166 setCanvas(parent_ref ? parent_ref->_canvas : CanvasWeakPtr());
168 setVisibleInternal(!parent_ref || parent_ref->isVisible());
171 //----------------------------------------------------------------------------
172 LayoutItemRef LayoutItem::getParent() const
174 return _parent.lock();
177 //----------------------------------------------------------------------------
178 SGVec2i LayoutItem::sizeHintImpl() const
183 //----------------------------------------------------------------------------
184 SGVec2i LayoutItem::minimumSizeImpl() const
189 //----------------------------------------------------------------------------
190 SGVec2i LayoutItem::maximumSizeImpl() const
195 //----------------------------------------------------------------------------
196 void LayoutItem::setVisibleInternal(bool visible)
198 LayoutItemRef parent = getParent();
199 if( isExplicitlyHidden() || (parent && !parent->isVisible()) )
202 if( isVisible() == visible )
212 visibilityChanged(visible);
215 //----------------------------------------------------------------------------
216 void LayoutItem::callSetVisibleInternal(LayoutItem* item, bool visible)
218 item->setVisibleInternal(visible);
221 } // namespace canvas
222 } // namespace simgear