DockingLayout.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_DockingLayout_H
31 #define Pt_Forms_DockingLayout_H
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Layout.h>
35 #include <map>
36 
37 namespace Pt {
38 
39 namespace Forms {
40 
68 class PT_FORMS_API DockingLayout : public Layout
69 {
70  typedef Layout Base;
71 
72  public:
75  enum DockMode
76  {
79  None = 0,
80 
84 
87  Top,
88 
92 
96 
99  Fill
100  };
101 
102  public:
105  explicit DockingLayout(DockMode ds = None);
106 
109  virtual ~DockingLayout();
110 
115  void addItem(Control& control, DockMode ds);
116 
119  void removeItem(Control& control);
120 
123  void setDockingStyle(Control& control, DockMode ds);
124 
125  protected:
128  virtual void onAddControl(Control& control);
129 
132  virtual void onRemoveControl(Control& control);
133 
136  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
137 
140  virtual void onLayout(const Gfx::RectF& rect);
141 
142  private:
143  std::map<Control*, DockMode> _docking;
144  DockMode _defaultDocking;
145 };
146 
147 } // namespace
148 
149 } // namespace
150 
151 #endif // include guard
Core module.
Definition: Allocator.h:33
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures docked children and leftover Fill space.
@ Bottom
Docks to the bottom edge.
Definition: DockingLayout.h:95
void setDockingStyle(Control &control, DockMode ds)
Sets the dock mode of attached control to ds.
virtual void onLayout(const Gfx::RectF &rect)
Assigns edge docks, then leftover space to Fill children.
void removeItem(Control &control)
Detaches control without destroying it.
Size with floating-point width and height.
Definition: Size.h:47
virtual void onAddControl(Control &control)
Handles attachment of control.
Reusable view used as application content.
Definition: Control.h:107
void addItem(Control &control, DockMode ds)
Attaches control with dock mode ds.
DockingLayout(DockMode ds=None)
Creates an empty docking layout.
DockMode
Edge or leftover region assigned to a child.
Definition: DockingLayout.h:76
Widget that hosts controls on a paint surface.
Definition: View.h:86
Docks children to edges and fills leftover space.
Definition: DockingLayout.h:69
Constraint used when measuring a control.
Definition: SizePolicy.h:48
@ Top
Docks to the top edge.
Definition: DockingLayout.h:87
@ Right
Docks to the right edge.
Definition: DockingLayout.h:91
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual ~DockingLayout()
Destroys the layout. Attached controls are not destroyed.
virtual void onRemoveControl(Control &control)
Removes the stored dock mode for control.
@ Left
Docks to the left edge.
Definition: DockingLayout.h:83
Control that arranges child controls.
Definition: Layout.h:46