StackLayout.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,
26 MA 02110-1301 USA
27*/
28
29#ifndef Pt_Forms_StackLayout_H
30#define Pt_Forms_StackLayout_H
31
32#include <Pt/Forms/Layout.h>
33#include <Pt/Signal.h>
34#include <vector>
35
36namespace Pt {
37
38namespace Forms {
39
64class PT_FORMS_API StackLayout : public Layout
65{
66 public:
67 typedef Layout Base;
68
71 static const std::size_t NoIndex = static_cast<const std::size_t>(-1);
72
73 public:
77
80 virtual ~StackLayout();
81
87 void addItem(Control& control);
88
91 void removeItem(Control& control);
92
95 bool empty() const;
96
99 std::size_t size() const;
100
103 Control* controlAt(std::size_t n) const;
104
107 std::size_t indexOf(Control& control) const;
108
111 std::size_t current() const;
112
117 void setCurrent(std::size_t n);
118
124 { return _controlRemoved; }
125
131 { return _currentChanged; }
132
133 protected:
136 virtual void onRemoveControl(Control& control);
137
140 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
141
144 virtual void onLayout(const Gfx::RectF& rect);
145
146 private:
147 Pt::Signal<std::size_t> _controlRemoved;
148 Pt::Signal<std::size_t> _currentChanged;
149 std::vector<Control*> _controls;
150 std::size_t _current;
151};
152
153} // namespace
154
155} // namespace
156
157#endif
Reusable view used as application content.
Definition Control.h:107
Constraint used when measuring a control.
Definition SizePolicy.h:48
std::size_t indexOf(Control &control) const
Returns the index of control, or NoIndex when absent.
void removeItem(Control &control)
Detaches control without destroying it.
void setCurrent(std::size_t n)
Shows the child at index n and hides the previous child.
Control * controlAt(std::size_t n) const
Returns the child at index n, or 0 when out of range.
bool empty() const
Returns true when the stack has no children.
virtual void onLayout(const Gfx::RectF &rect)
Assigns the padded bounds to the current child.
void addItem(Control &control)
Attaches control as a hidden stack page.
virtual void onRemoveControl(Control &control)
Updates the stack after control is detached.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the largest preferred child size.
std::size_t current() const
Returns the current child index, or NoIndex when none.
static const std::size_t NoIndex
Index value that means no child is current.
Definition StackLayout.h:71
virtual ~StackLayout()
Destroys the layout. Attached controls are not destroyed.
StackLayout()
Creates an empty stack layout.
Pt::Signal< std::size_t > & controlRemoved()
Returns the signal emitted when a control is removed.
Definition StackLayout.h:123
Pt::Signal< std::size_t > & currentChanged()
Returns the signal emitted when the current index changes.
Definition StackLayout.h:130
std::size_t size() const
Returns the number of stacked children.
Multicast Signal to call multiple slots.
Definition Signal.h:190
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33