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/Layout.h>
35 
36 namespace Pt {
37 
38 namespace Forms {
39 
40 class PT_FORMS_API FlowLayout : public Layout
41 {
42  typedef Layout Base;
43 
44  public:
45  // Horizontal use all space in row, same size for elements
46  // HorizontalCenter place elements accoring to size
47  // Vertical use all space in row, same size for elements
48  // VerticalCenter place elements accoring to size
49 
50  enum Direction
51  {
52  Left,
53  Right,
54  Top,
55  Bottom
56  };
57 
58  public:
59  explicit FlowLayout(Direction d = Left);
60 
61  virtual ~FlowLayout();
62 
63  void setDirection(Direction d);
64 
65  void setCenter(bool b);
66 
67  void setReverse(bool b);
68 
69  void addItem(Control& control);
70 
71  void removeItem(Control& control);
72 
73  protected:
74  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
75 
76  virtual void onLayout(const Gfx::RectF& rect);
77 
78  private:
79  Gfx::SizeF onMeasureHorizontal(const SizePolicy& policy);
80 
81  Gfx::SizeF onMeasureVertical(const SizePolicy& policy);
82 
83  void onLayoutLeft(const Gfx::RectF& rect, bool center);
84 
85  void onLayoutRight(const Gfx::RectF& rect, bool center);
86 
87  void onLayoutTop(const Gfx::RectF& rect, bool center);
88 
89  void onLayoutBottom(const Gfx::RectF& rect, bool center);
90 
91  private:
92  Direction _direction;
93  bool _center;
94  bool _reverse;
95 };
96 
97 } // namespace
98 
99 } // namespace
100 
101 #endif // include guard