FlowLayout.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27  02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_FlowLayout_H
31 #define Pt_Forms_FlowLayout_H
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Direction.h>
35 #include <Pt/Forms/Layout.h>
36 
37 namespace Pt {
38 
39 namespace Forms {
40 
71 class PT_FORMS_API FlowLayout : public Layout
72 {
73  typedef Layout Base;
74 
75  public:
79 
82  virtual ~FlowLayout();
83 
87 
90  void setCenter(bool b);
91 
94  void setReverse(bool b);
95 
100  void addItem(Control& control);
101 
104  void removeItem(Control& control);
105 
106  protected:
109  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
110 
113  virtual void onLayout(const Gfx::RectF& rect);
114 
115  private:
116  Gfx::SizeF onMeasureHorizontal(const SizePolicy& policy);
117 
118  Gfx::SizeF onMeasureVertical(const SizePolicy& policy);
119 
120  void onLayoutLeft(const Gfx::RectF& rect, bool center);
121 
122  void onLayoutRight(const Gfx::RectF& rect, bool center);
123 
124  void onLayoutTop(const Gfx::RectF& rect, bool center);
125 
126  void onLayoutBottom(const Gfx::RectF& rect, bool center);
127 
128  private:
129  Direction _direction;
130  bool _center;
131  bool _reverse;
132 };
133 
134 } // namespace
135 
136 } // namespace
137 
138 #endif // include guard
Core module.
Definition: Allocator.h:33
virtual ~FlowLayout()
Destroys the layout. Attached controls are not destroyed.
void setCenter(bool b)
Sets whether items are packed as a centered group.
@ Left
Left to right.
Definition: Direction.h:60
Size with floating-point width and height.
Definition: Size.h:47
void setDirection(Direction d)
Sets the flow direction to d and requests relayout.
Reusable view used as application content.
Definition: Control.h:107
Names a flow direction.
Definition: Direction.h:52
Arranges children in a single row or column.
Definition: FlowLayout.h:72
Widget that hosts controls on a paint surface.
Definition: View.h:86
void addItem(Control &control)
Attaches control as a flow item.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
void removeItem(Control &control)
Detaches control without destroying it.
Rect with floating-point coordinates.
Definition: Rect.h:47
Control that arranges child controls.
Definition: Layout.h:46
FlowLayout(Direction d=Direction::Left)
Creates a flow layout in direction d.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures children along the flow axis.
virtual void onLayout(const Gfx::RectF &rect)
Places children along the flow direction.
void setReverse(bool b)
Sets whether children are visited in reverse order.