ScrollView.h
1 /* Copyright (C) 2016 Marc Boris Duerner
2  Copyright (C) 2016 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,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_SCROLLVIEW_H
31 #define Pt_Forms_SCROLLVIEW_H
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Control.h>
35 #include <Pt/Forms/ScrollLayout.h>
36 #include <Pt/Forms/ScrollBar.h>
37 
38 namespace Pt {
39 
40 namespace Forms {
41 
69 class PT_FORMS_API ScrollView : public Control
70 {
71  typedef Control Base;
72 
73  public:
77 
80  virtual ~ScrollView();
81 
84  void setScrollBars(bool hasScrollBars);
85 
90  void setContent(Control& control);
91 
94  void setContentMode(SizePolicy::Mode horizontal,
95  SizePolicy::Mode vertical);
96 
99  void scrollX(double xpos);
100 
103  void scrollY(double ypos);
104 
107  double maximumX() const;
108 
111  double maximumY() const;
112 
113  protected:
116  void onScrollBarX(double pos);
117 
120  void onScrollBarY(double pos);
121 
124  void onScrolledX(double n);
125 
128  void onScrolledY(double n);
129 
130  protected:
133  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
134 
137  virtual void onLayout(const Gfx::RectF& rect);
138 
139  private:
140  void updateScrollBar(ScrollBar& scroll, double maxRange);
141 
142  private:
143  ScrollLayout _scrollLayout;
144  bool _hasScrollBars;
145  Control* _control;
146  ScrollBar _scrollBarX;
147  ScrollBar _scrollBarY;
148 };
149 
150 } // namespace
151 
152 } // namespace
153 
154 #endif
Viewport over larger content.
Definition: ScrollView.h:70
Core module.
Definition: Allocator.h:33
void onScrollBarX(double pos)
Scrolls the content horizontally from the horizontal bar.
Offsets children when content exceeds the viewport.
Definition: ScrollLayout.h:66
virtual void onLayout(const Gfx::RectF &rect)
Places the content and scroll bars in rect.
void scrollX(double xpos)
Scrolls the content horizontally to xpos.
Size with floating-point width and height.
Definition: Size.h:47
double maximumY() const
Returns the maximum vertical scroll offset.
virtual ~ScrollView()
Destroys the scroll view. The content control is not destroyed.
Reusable view used as application content.
Definition: Control.h:107
void setScrollBars(bool hasScrollBars)
Sets whether the view shows scroll bars.
ScrollView()
Creates an empty scroll view.
void onScrolledX(double n)
Updates the horizontal bar from the layout offset.
void setContent(Control &control)
Sets the caller-owned content to control.
Widget that hosts controls on a paint surface.
Definition: View.h:86
Position in a range shown by a handle on a track.
Definition: ScrollBar.h:76
double maximumX() const
Returns the maximum horizontal scroll offset.
void setContentMode(SizePolicy::Mode horizontal, SizePolicy::Mode vertical)
Sets how the content is measured on each axis.
Mode
Constraint applied to one axis.
Definition: SizePolicy.h:53
Constraint used when measuring a control.
Definition: SizePolicy.h:48
void scrollY(double ypos)
Scrolls the content vertically to ypos.
void onScrolledY(double n)
Updates the vertical bar from the layout offset.
Rect with floating-point coordinates.
Definition: Rect.h:47
void onScrollBarY(double pos)
Scrolls the content vertically from the vertical bar.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the content and scroll bars.