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 
36 namespace Pt {
37 
38 namespace Forms {
39 
40 class PT_FORMS_API StackLayout : public Layout
41 {
42  public:
43  typedef Layout Base;
44  static const std::size_t NoIndex = static_cast<const std::size_t>(-1);
45 
46  public:
47  StackLayout();
48 
49  virtual ~StackLayout();
50 
51  void addItem(Control& control);
52 
53  void removeItem(Control& control);
54 
55  bool empty() const;
56 
57  std::size_t size() const;
58 
59  Control* controlAt(std::size_t n) const;
60 
61  std::size_t indexOf(Control& control) const;
62 
63  std::size_t current() const;
64 
65  void setCurrent(std::size_t n);
66 
67  Pt::Signal<std::size_t>& controlRemoved()
68  { return _controlRemoved; }
69 
70  Pt::Signal<std::size_t>& currentChanged()
71  { return _currentChanged; }
72 
73  protected:
74  virtual void onRemoveControl(Control& control);
75 
76  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
77 
78  virtual void onLayout(const Gfx::RectF& rect);
79 
80  private:
81  Pt::Signal<std::size_t> _controlRemoved;
82  Pt::Signal<std::size_t> _currentChanged;
83  std::vector<Control*> _controls;
84  std::size_t _current;
85 };
86 
87 } // namespace
88 
89 } // namespace
90 
91 #endif