A viewport for viewing a large virtual area
PtWidget --> PtBasic --> PtContainer --> PtScrollArea
For more information, see the diagram of the widget hierarchy.
<photon/PtScrollArea.h>
A PtScrollArea widget combines one or more scrollbar widgets and an area that provides a viewport onto a virtual display area. The virtual display area is a container for other widgets. Typically, the virtual area is larger than the viewing area; the scrollbar widgets let you bring any part of the virtual area into view.
A PtScrollArea widget acts as a viewport.
Like other widgets, PtScrollArea's physical size is set with its Pt_ARG_AREA resource. The virtual size depends on its Pt_ARG_SCROLL_AREA_MAX_X and Pt_ARG_SCROLL_AREA_MAX_Y resources.
PtScrollArea's resize policy affects only its virtual size, not its physical size. Its anchors, on the other hand, affect only its physical size, with one exception: if the physical size exceeds the virtual size, the virtual size temporarily grows to fill the physical canvas.
Any anchorable children of a PtScrollArea widget will anchor to the virtual size, not the physical size.
If the virtual area's size is greater than the viewport's size, you'll need horizontal and/or vertical scrollbars to control the viewport's position. The dimensions are checked when the widget is realized to determine if scrollbars are necessary. Pt_ARG_SCROLLBAR_X_DISPLAY and Pt_ARG_SCROLLBAR_Y_DISPLAY indicate when the scrollbars should be displayed:
If the virtual area's size is significantly greater than that of the viewport (such as when a large textual document is being viewed), it's usually impractical in terms of performance and memory to use a scrolling area. This is because the widget for the virtual area keeps the entire contents of the object in memory and always renders the entire object. In these cases, you should use scrollbars and directly control which portion of the object is displayed.
When the user moves either the vertical or horizontal scrollbar to change the viewport's position, a callback may be invoked to notify the application that the viewport has been moved. You may use this to keep two related viewports synchronized with each other by monitoring both viewports and updating the position of the alternate viewport when one of them scrolls. See "Scrolling control" below.
The callbacks provided by the PtScrollArea class and their meanings are:
The scrollbars provided by the scrollable area let the user vary the position of the viewport between (0,0) and (xmax, ymax), where xmax and ymax are the maximum positions in x and y. These are equal to the virtual area's size in the specified dimension minus the viewport's size in that dimension.
The size of the handle used by the scrollbar to represent the viewport's position within the virtual area is the viewport's size relative to the virtual area's size.
The handle may be moved by incremental amounts by clicking on either of the arrow buttons in the scrollbar. You can control the increment by setting the increment resource corresponding to the scrollbar:
These specify the number of pixels to increment the viewport's position by when one of the stepper buttons in the scrollbar is pressed.
You can also update the viewport's position under program control. To move the viewport, you simply set a new position using the Pt_ARG_SCROLL_AREA_POS_X and Pt_ARG_SCROLL_AREA_POS_Y resources.
Scrollable areas always use absolute positioning for the layout of their children.
Anchors between a scrollable area and its parent will affect the scrollable area's visible area.
Children of the scrollable area are anchored to its virtual area.
The scrollable area's resize policy is applied to its virtual area. You can set the virtual area's size directly by modifying the resources associated with it. Otherwise, the area will change only under the following conditions:
OR
AND
AND
Other layouts are possible only by making another container, such as a group widget, a child of the scrollable area.
Resource | C type | Pt type | Default |
---|---|---|---|
Pt_ARG_SCROLL_AREA_FLAGS | unsigned short | Flag | 0 |
Pt_ARG_SCROLL_AREA_INCREMENT_X | unsigned short | Scalar | 10 |
Pt_ARG_SCROLL_AREA_INCREMENT_Y | unsigned short | Scalar | 10 |
Pt_ARG_SCROLL_AREA_MAX_X | unsigned short | Scalar | 0 |
Pt_ARG_SCROLL_AREA_MAX_Y | unsigned short | Scalar | 0 |
Pt_ARG_SCROLL_AREA_POS_X | unsigned short | Scalar | 0 |
Pt_ARG_SCROLL_AREA_POS_Y | unsigned short | Scalar | 0 |
Pt_ARG_SCROLLBAR_X_DISPLAY | unsigned short | Scalar | Pt_NEVER |
Pt_ARG_SCROLLBAR_X_HEIGHT | unsigned short | Scalar | 0 (use scrollbar default of 15) |
Pt_ARG_SCROLLBAR_Y_DISPLAY | unsigned short | Scalar | Pt_ALWAYS |
Pt_ARG_SCROLLBAR_Y_WIDTH | unsigned short | Scalar | 0 (use scrollbar default of 15) |
Pt_CB_SCROLLED_X | PtCallback_t * | Link | NULL |
Pt_CB_SCROLLED_Y | PtCallback_t * | Link | NULL |
C type | Pt type | Default |
---|---|---|
unsigned short | Flag | 0 |
These flags control the behavior of the scroll area. Valid bits include:
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 10 |
The number of pixels that the widget will scroll when the user clicks the horizontal arrow buttons.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 10 |
The number of pixels that the widget will scroll when the user clicks the vertical arrow buttons.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The width (in pixels) of the total scrollable area. This is the widget's virtual width. To specify the displayed portion of this scrollable area, use Pt_ARG_AREA.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The height (in pixels) of the total scrollable area. This is the widget's virtual height. To specify the displayed portion of this scrollable area, use Pt_ARG_AREA.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The horizontal position of the displayed portion of the scrollable area.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The vertical position of the displayed portion of the scrollable area.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | Pt_NEVER |
Controls the visibility of the horizontal scrollbar. Possible values:
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 (use scrollbar default of 15) |
The height (in pixels) of the horizontal scrollbar. The minimum height is 6 pixels. If this resource is set to 0, the default height of 15 pixels is used.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | Pt_ALWAYS |
Controls the visibility of the scrollbar. Possible values:
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 (use scrollbar default of 15) |
The width (in pixels) of the vertical scrollbar. The minimum width is 6 pixels. If this resource is set to 0, the default width of 15 pixels is used.
C type | Pt type | Default |
---|---|---|
PtCallback_t * | Link | NULL |
The list of callbacks that the PtScrollArea widget invokes when its scrollbars are moved.
If the widget has the Pt_CALLBACKS_ACTIVE bit set in its Pt_ARG_FLAGS resource, these callbacks are also invoked when the positions of the scrollbars are changed by a call to PtSetResources().
Each callback is passed a PtCallbackInfo_t structure that contains at least the following members:
unsigned action;
where action can be one of the following:
These callbacks should return Pt_CONTINUE.
If the widget modifies an inherited resource, the "Default override" column indicates the new value. This modification affects any subclasses of the widget.