GridLayout.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_GridLayout_H
30 #define Pt_Forms_GridLayout_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/Layout.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
67 class PT_FORMS_API GridLayout : public Layout
68 {
69  public:
73  {
76  Horizontal = 0,
77 
80  Vertical = 1
81  };
82 
83  public:
86  explicit GridLayout(Orientation o = Vertical, std::size_t span = 0);
87 
90  virtual ~GridLayout();
91 
94  void setOrientation(Orientation o, std::size_t span = 0);
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 onMeasureVertical(const SizePolicy& policy);
117 
118  Gfx::SizeF onMeasureHorizontal(const SizePolicy& policy);
119 
120  void onLayoutVertical(const Gfx::SizeF& itemSize, const Gfx::RectF& rect);
121 
122  void onLayoutHorizontal(const Gfx::SizeF& itemSize, const Gfx::RectF& rect);
123 
124  private:
125  Orientation _orientation;
126  std::size_t _span;
127 };
128 
129 } // namespace
130 
131 } // namespace
132 
133 #endif // include guard
Core module.
Definition: Allocator.h:33
Orientation
Wrapping axis of the grid.
Definition: GridLayout.h:73
Arranges children in uniform wrapping cells.
Definition: GridLayout.h:68
virtual ~GridLayout()
Destroys the layout. Attached controls are not destroyed.
void removeItem(Control &control)
Detaches control without destroying it.
Size with floating-point width and height.
Definition: Size.h:47
Reusable view used as application content.
Definition: Control.h:107
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures uniform cells from the largest preferred child.
GridLayout(Orientation o=Vertical, std::size_t span=0)
Creates a grid with orientation o and wrap count span.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Rect with floating-point coordinates.
Definition: Rect.h:47
Control that arranges child controls.
Definition: Layout.h:46
virtual void onLayout(const Gfx::RectF &rect)
Places children in wrapping cells of uniform size.
void addItem(Control &control)
Attaches control as the next grid item.
void setOrientation(Orientation o, std::size_t span=0)
Sets the orientation to o and the wrap count to span.