ScrollLayout.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_ScrollLayout_H
31#define Pt_Forms_ScrollLayout_H
32
33#include <Pt/Forms/Api.h>
34#include <Pt/Forms/Layout.h>
35#include <Pt/Forms/ScrollBar.h>
36
37namespace Pt {
38
39namespace Forms {
40
65class PT_FORMS_API ScrollLayout : public Layout
66{
67 typedef Layout Base;
68
69 public:
73
76 virtual ~ScrollLayout();
77
82
85 double maximumX() const;
86
89 double maximumY() const;
90
95 void scrollX(double xpos);
96
101 void scrollY(double ypos);
102
105 double scrollPosX() const;
106
109 double scrollPosY() const;
110
114
118
123 void addItem(Control& control);
124
127 void removeItem(Control& control);
128
132
133 protected:
136 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
137
140 virtual void onLayout(const Gfx::RectF& rect);
141
142 protected:
145 virtual bool onMouseEvent(const MouseEvent& ev);
146
149 virtual bool onTouchEvent(const TouchEvent& ev);
150
153 virtual bool onScrollEvent(const ScrollEvent& ev);
154
155 private:
156 Pt::Signal<double> _scrolledX;
157 Pt::Signal<double> _scrolledY;
158 SizePolicy::Mode _hmode;
159 SizePolicy::Mode _vmode;
160 Gfx::PointF _scrollPos;
161 double _scrollByX;
162 double _scrollByY;
163 bool _enableX;
164 bool _enableY;
165 double _maxX;
166 double _maxY;
167};
168
169} // namespace
170
171} // namespace
172
173#endif // include guard
Reusable view used as application content.
Definition Control.h:107
Pointer movement or button change.
Definition MouseEvent.h:134
Scroll or wheel movement.
Definition ScrollEvent.h:51
virtual bool onMouseEvent(const MouseEvent &ev)
Forwards the mouse event to the base control.
void removeItem(Control &control)
Detaches control without destroying it.
virtual ~ScrollLayout()
Destroys the layout. Attached controls are not destroyed.
virtual bool onTouchEvent(const TouchEvent &ev)
Forwards the touch event to the base control.
double scrollPosX() const
Returns the horizontal scroll offset.
virtual void onLayout(const Gfx::RectF &rect)
Places children at their preferred size, offset by scroll.
void addItem(Control &control)
Attaches control as scrollable content.
double maximumY() const
Returns the measured content extent on the Y axis.
Pt::Signal< double > & scrolledX()
Returns the signal emitted when the horizontal offset changes.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures children and records the content extent.
ScrollLayout()
Creates an empty scroll layout.
Pt::Signal< double > & scrolledY()
Returns the signal emitted when the vertical offset changes.
void enableScrolling(bool scrollX, bool scrollY)
Enables horizontal scrolling when scrollX is true and vertical scrolling when scrollY is true.
double maximumX() const
Returns the measured content extent on the X axis.
void scrollY(double ypos)
Sets the vertical scroll offset to ypos.
void scrollX(double xpos)
Sets the horizontal scroll offset to xpos.
virtual bool onScrollEvent(const ScrollEvent &ev)
Adjusts the scroll offset from ev and returns true.
void setContentMode(SizePolicy::Mode hmode, SizePolicy::Mode vmode)
Sets the size-policy modes used to measure children.
double scrollPosY() const
Returns the vertical scroll offset.
Constraint used when measuring a control.
Definition SizePolicy.h:48
Mode
Constraint applied to one axis.
Definition SizePolicy.h:53
Touch press, move, or release.
Definition TouchEvent.h:51
Multicast Signal to call multiple slots.
Definition Signal.h:190
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33