CanvasLayout.h
1/* Copyright (C) 2025 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,
26 MA 02110-1301 USA
27*/
28
29#ifndef PT_FORMS_CANVASLAYOUT_H
30#define PT_FORMS_CANVASLAYOUT_H
31
32#include <Pt/Forms/Layout.h>
33#include <Pt/Gfx/Point.h>
34#include <Pt/Gfx/Size.h>
35#include <map>
36
37namespace Pt {
38
39namespace Forms {
40
63class PT_FORMS_API CanvasLayout : public Layout
64{
65 public:
66 typedef Layout Base;
67
71 {
72 public:
76 { }
77
80 LayoutParams(const Gfx::PointF& pos,
81 const Gfx::SizeF& size)
82 : _pos(pos)
83 , _size(size)
84 { }
85
88 const Gfx::PointF& position() const
89 { return _pos; }
90
93 const Gfx::SizeF& size() const
94 { return _size; }
95
96 private:
97 Gfx::PointF _pos;
98 Gfx::SizeF _size;
99 };
100
101 public:
105
108 virtual ~CanvasLayout();
109
114 void addItem(Control& control, const LayoutParams& params);
115
120 void addItem(Control& control,
121 const Gfx::PointF& pos,
122 const Gfx::SizeF& size);
123
126 void removeItem(Control& control);
127
128 protected:
131 virtual void onRemoveControl(Control& control);
132
135 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
136
139 virtual void onLayout(const Gfx::RectF& rect);
140
141 private:
142 typedef std::map<Control*, LayoutParams> ItemMap;
143
144 std::map<Control*, LayoutParams> _items;
145};
146
147} // namespace
148
149} // namespace
150
151#endif
Position and size of a canvas child.
Definition CanvasLayout.h:71
LayoutParams()
Creates empty parameters.
Definition CanvasLayout.h:75
const Gfx::PointF & position() const
Returns the stored position.
Definition CanvasLayout.h:88
LayoutParams(const Gfx::PointF &pos, const Gfx::SizeF &size)
Creates parameters for pos and size.
Definition CanvasLayout.h:80
const Gfx::SizeF & size() const
Returns the stored size.
Definition CanvasLayout.h:93
void removeItem(Control &control)
Detaches control without destroying it.
CanvasLayout()
Creates an empty canvas layout.
virtual void onLayout(const Gfx::RectF &rect)
Places each child at its stored position and size.
virtual void onRemoveControl(Control &control)
Removes the stored parameters for control.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the bounding box of stored child rectangles.
void addItem(Control &control, const LayoutParams &params)
Attaches control at the position and size in params.
void addItem(Control &control, const Gfx::PointF &pos, const Gfx::SizeF &size)
Attaches control at pos with size.
virtual ~CanvasLayout()
Destroys the layout. Attached controls are not destroyed.
Reusable view used as application content.
Definition Control.h:107
Constraint used when measuring a control.
Definition SizePolicy.h:48
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33