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 
37 namespace Pt {
38 
39 namespace Forms {
40 
65 class PT_FORMS_API ScrollLayout : public Layout
66 {
67  typedef Layout Base;
68 
69  public:
73 
76  virtual ~ScrollLayout();
77 
81  void enableScrolling(bool scrollX, bool scrollY);
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
Core module.
Definition: Allocator.h:33
Touch press, move, or release.
Definition: TouchEvent.h:51
Offsets children when content exceeds the viewport.
Definition: ScrollLayout.h:66
void enableScrolling(bool scrollX, bool scrollY)
Enables horizontal scrolling when scrollX is true and vertical scrolling when scrollY is true.
void scrollY(double ypos)
Sets the vertical scroll offset to ypos.
Scroll or wheel movement.
Definition: ScrollEvent.h:51
virtual bool onMouseEvent(const MouseEvent &ev)
Forwards the mouse event to the base control.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures children and records the content extent.
virtual void onLayout(const Gfx::RectF &rect)
Places children at their preferred size, offset by scroll.
double maximumY() const
Returns the measured content extent on the Y axis.
virtual bool onScrollEvent(const ScrollEvent &ev)
Adjusts the scroll offset from ev and returns true.
ScrollLayout()
Creates an empty scroll layout.
void scrollX(double xpos)
Sets the horizontal scroll offset to xpos.
Pt::Signal< double > & scrolledX()
Returns the signal emitted when the horizontal offset changes.
void removeItem(Control &control)
Detaches control without destroying it.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Reusable view used as application content.
Definition: Control.h:107
virtual ~ScrollLayout()
Destroys the layout. Attached controls are not destroyed.
Pt::Signal< double > & scrolledY()
Returns the signal emitted when the vertical offset changes.
void setContentMode(SizePolicy::Mode hmode, SizePolicy::Mode vmode)
Sets the size-policy modes used to measure children.
Widget that hosts controls on a paint surface.
Definition: View.h:86
double scrollPosY() const
Returns the vertical scroll offset.
Mode
Constraint applied to one axis.
Definition: SizePolicy.h:53
double scrollPosX() const
Returns the horizontal scroll offset.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Rect with floating-point coordinates.
Definition: Rect.h:47
void addItem(Control &control)
Attaches control as scrollable content.
Control that arranges child controls.
Definition: Layout.h:46
virtual bool onTouchEvent(const TouchEvent &ev)
Forwards the touch event to the base control.
Pointer movement or button change.
Definition: MouseEvent.h:134
double maximumX() const
Returns the measured content extent on the X axis.