Top |
Functions
Properties
GtkWidget * | child | Read / Write |
GtkAdjustment * | hadjustment | Read / Write / Construct |
gboolean | has-frame | Read / Write |
GtkPolicyType | hscrollbar-policy | Read / Write |
gboolean | kinetic-scrolling | Read / Write |
int | max-content-height | Read / Write |
int | max-content-width | Read / Write |
int | min-content-height | Read / Write |
int | min-content-width | Read / Write |
gboolean | overlay-scrolling | Read / Write |
gboolean | propagate-natural-height | Read / Write |
gboolean | propagate-natural-width | Read / Write |
GtkAdjustment * | vadjustment | Read / Write / Construct |
GtkPolicyType | vscrollbar-policy | Read / Write |
GtkCornerType | window-placement | Read / Write |
Signals
void | edge-overshot | Run Last |
void | edge-reached | Run Last |
void | move-focus-out | Action |
gboolean | scroll-child | Action |
Implemented Interfaces
GtkScrolledWindow implements GtkAccessible, GtkBuildable and GtkConstraintTarget.
Description
GtkScrolledWindow is a container that accepts a single child widget, makes that child scrollable using either internally added scrollbars or externally associated adjustments, and optionally draws a frame around the child.
Widgets with native scrolling support, i.e. those whose classes implement the
GtkScrollable interface, are added directly. For other types of widget, the
class GtkViewport acts as an adaptor, giving scrollability to other widgets.
gtk_scrolled_window_set_child()
intelligently
accounts for whether or not the added child is a GtkScrollable. If it isn’t,
GtkScrolledWindow wraps the child in a GtkViewport and adds that for you.
Therefore, you can just add any child widget and not worry about the details.
If gtk_scrolled_window_set_child()
has added a GtkViewport for you, you can remove
both your added child widget from the GtkViewport, and the GtkViewport
from the GtkScrolledWindow, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
GtkWidget *scrolled_window = gtk_scrolled_window_new (); GtkWidget *child_widget = gtk_button_new (); // GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically // add a GtkViewport. gtk_box_append (GTK_BOX (scrolled_window), child_widget); // Either of these will result in child_widget being unparented: gtk_box_remove (GTK_BOX (scrolled_window), child_widget); // or gtk_box_remove (GTK_BOX (scrolled_window), gtk_bin_get_child (GTK_BIN (scrolled_window))); |
Unless “hscrollbar-policy” and “vscrollbar-policy” are GTK_POLICY_NEVER or GTK_POLICY_EXTERNAL, GtkScrolledWindow adds internal GtkScrollbar widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by the “hadjustment” and “vadjustment” that are associated with the GtkScrolledWindow. See the docs on GtkScrollbar for the details, but note that the “step_increment” and “page_increment” fields are only effective if the policy causes scrollbars to be present.
If a GtkScrolledWindow doesn’t behave quite as you would like, or doesn’t have exactly the right layout, it’s very possible to set up your own scrolling with GtkScrollbar and for example a GtkGrid.
Touch support
GtkScrolledWindow has built-in support for touch devices. When a touchscreen is used, swiping will move the scrolled window, and will expose 'kinetic' behavior. This can be turned off with the “kinetic-scrolling” property if it is undesired.
GtkScrolledWindow also displays visual 'overshoot' indication when the content is pulled beyond the end, and this situation can be captured with the “edge-overshot” signal.
If no mouse device is present, the scrollbars will overlaid as narrow, auto-hiding indicators over the content. If traditional scrollbars are desired although no mouse is present, this behaviour can be turned off with the “overlay-scrolling” property.
CSS nodes
GtkScrolledWindow has a main CSS node with name scrolledwindow.
It gets a .frame style class added when “has-frame”
is TRUE
.
It uses subnodes with names overshoot and undershoot to draw the overflow and underflow indications. These nodes get the .left, .right, .top or .bottom style class added depending on where the indication is drawn.
GtkScrolledWindow also sets the positional style classes (.left, .right, .top, .bottom) and style classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering) on its scrollbars.
If both scrollbars are visible, the area where they meet is drawn with a subnode named junction.
Functions
gtk_scrolled_window_new ()
GtkWidget *
gtk_scrolled_window_new (void
);
Creates a new scrolled window.
gtk_scrolled_window_get_child ()
GtkWidget *
gtk_scrolled_window_get_child (GtkScrolledWindow *scrolled_window
);
Gets the child widget of scrolled_window
.
gtk_scrolled_window_set_child ()
void gtk_scrolled_window_set_child (GtkScrolledWindow *scrolled_window
,GtkWidget *child
);
Sets the child widget of scrolled_window
.
gtk_scrolled_window_get_hadjustment ()
GtkAdjustment *
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window
);
Returns the horizontal scrollbar’s adjustment, used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality.
gtk_scrolled_window_set_hadjustment ()
void gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window
,GtkAdjustment *hadjustment
);
Sets the GtkAdjustment for the horizontal scrollbar.
Parameters
scrolled_window |
||
hadjustment |
the GtkAdjustment to use, or |
[nullable] |
gtk_scrolled_window_get_vadjustment ()
GtkAdjustment *
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window
);
Returns the vertical scrollbar’s adjustment, used to connect the vertical scrollbar to the child widget’s vertical scroll functionality.
gtk_scrolled_window_set_vadjustment ()
void gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window
,GtkAdjustment *vadjustment
);
Sets the GtkAdjustment for the vertical scrollbar.
Parameters
scrolled_window |
||
vadjustment |
the GtkAdjustment to use, or |
[nullable] |
gtk_scrolled_window_get_hscrollbar ()
GtkWidget *
gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window
);
Returns the horizontal scrollbar of scrolled_window
.
gtk_scrolled_window_get_vscrollbar ()
GtkWidget *
gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window
);
Returns the vertical scrollbar of scrolled_window
.
gtk_scrolled_window_get_policy ()
void gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window
,GtkPolicyType *hscrollbar_policy
,GtkPolicyType *vscrollbar_policy
);
Retrieves the current policy values for the horizontal and vertical
scrollbars. See gtk_scrolled_window_set_policy()
.
gtk_scrolled_window_set_policy ()
void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window
,GtkPolicyType hscrollbar_policy
,GtkPolicyType vscrollbar_policy
);
Sets the scrollbar policy for the horizontal and vertical scrollbars.
The policy determines when the scrollbar should appear; it is a value
from the GtkPolicyType enumeration. If GTK_POLICY_ALWAYS
, the
scrollbar is always present; if GTK_POLICY_NEVER
, the scrollbar is
never present; if GTK_POLICY_AUTOMATIC
, the scrollbar is present only
if needed (that is, if the slider part of the bar would be smaller
than the trough — the display is larger than the page size).
gtk_scrolled_window_get_placement ()
GtkCornerType
gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window
);
Gets the placement of the contents with respect to the scrollbars
for the scrolled window. See gtk_scrolled_window_set_placement()
.
Returns
the current placement value.
See also gtk_scrolled_window_set_placement()
and
gtk_scrolled_window_unset_placement()
.
gtk_scrolled_window_set_placement ()
void gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window
,GtkCornerType window_placement
);
Sets the placement of the contents with respect to the scrollbars for the scrolled window.
The default is GTK_CORNER_TOP_LEFT
, meaning the child is
in the top left, with the scrollbars underneath and to the right.
Other values in GtkCornerType are GTK_CORNER_TOP_RIGHT
,
GTK_CORNER_BOTTOM_LEFT
, and GTK_CORNER_BOTTOM_RIGHT
.
See also gtk_scrolled_window_get_placement()
and
gtk_scrolled_window_unset_placement()
.
gtk_scrolled_window_unset_placement ()
void
gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window
);
Unsets the placement of the contents with respect to the scrollbars
for the scrolled window. If no window placement is set for a scrolled
window, it defaults to GTK_CORNER_TOP_LEFT
.
See also gtk_scrolled_window_set_placement()
and
gtk_scrolled_window_get_placement()
.
gtk_scrolled_window_get_has_frame ()
gboolean
gtk_scrolled_window_get_has_frame (GtkScrolledWindow *scrolled_window
);
Gets whether the scrolled window draws a frame.
See gtk_scrolled_window_set_has_frame()
.
gtk_scrolled_window_set_has_frame ()
void gtk_scrolled_window_set_has_frame (GtkScrolledWindow *scrolled_window
,gboolean has_frame
);
Changes the frame drawn around the contents of scrolled_window
.
gtk_scrolled_window_get_kinetic_scrolling ()
gboolean
gtk_scrolled_window_get_kinetic_scrolling
(GtkScrolledWindow *scrolled_window
);
Returns the specified kinetic scrolling behavior.
gtk_scrolled_window_set_kinetic_scrolling ()
void gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window
,gboolean kinetic_scrolling
);
Turns kinetic scrolling on or off.
Kinetic scrolling only applies to devices with source
GDK_SOURCE_TOUCHSCREEN
.
gtk_scrolled_window_get_overlay_scrolling ()
gboolean
gtk_scrolled_window_get_overlay_scrolling
(GtkScrolledWindow *scrolled_window
);
Returns whether overlay scrolling is enabled for this scrolled window.
gtk_scrolled_window_set_overlay_scrolling ()
void gtk_scrolled_window_set_overlay_scrolling (GtkScrolledWindow *scrolled_window
,gboolean overlay_scrolling
);
Enables or disables overlay scrolling for this scrolled window.
gtk_scrolled_window_get_min_content_width ()
int
gtk_scrolled_window_get_min_content_width
(GtkScrolledWindow *scrolled_window
);
Gets the minimum content width of scrolled_window
, or -1 if not set.
gtk_scrolled_window_set_min_content_width ()
void gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window
,int width
);
Sets the minimum width that scrolled_window
should keep visible.
Note that this can and (usually will) be smaller than the minimum
size of the content.
It is a programming error to set the minimum content width to a value greater than “max-content-width”.
gtk_scrolled_window_get_min_content_height ()
int
gtk_scrolled_window_get_min_content_height
(GtkScrolledWindow *scrolled_window
);
Gets the minimal content height of scrolled_window
, or -1 if not set.
gtk_scrolled_window_set_min_content_height ()
void gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window
,int height
);
Sets the minimum height that scrolled_window
should keep visible.
Note that this can and (usually will) be smaller than the minimum
size of the content.
It is a programming error to set the minimum content height to a value greater than “max-content-height”.
gtk_scrolled_window_get_max_content_width ()
int
gtk_scrolled_window_get_max_content_width
(GtkScrolledWindow *scrolled_window
);
Returns the maximum content width set.
gtk_scrolled_window_set_max_content_width ()
void gtk_scrolled_window_set_max_content_width (GtkScrolledWindow *scrolled_window
,int width
);
Sets the maximum width that scrolled_window
should keep visible. The
scrolled_window
will grow up to this width before it starts scrolling
the content.
It is a programming error to set the maximum content width to a value smaller than “min-content-width”.
gtk_scrolled_window_get_max_content_height ()
int
gtk_scrolled_window_get_max_content_height
(GtkScrolledWindow *scrolled_window
);
Returns the maximum content height set.
gtk_scrolled_window_set_max_content_height ()
void gtk_scrolled_window_set_max_content_height (GtkScrolledWindow *scrolled_window
,int height
);
Sets the maximum height that scrolled_window
should keep visible. The
scrolled_window
will grow up to this height before it starts scrolling
the content.
It is a programming error to set the maximum content height to a value smaller than “min-content-height”.
gtk_scrolled_window_get_propagate_natural_width ()
gboolean
gtk_scrolled_window_get_propagate_natural_width
(GtkScrolledWindow *scrolled_window
);
Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.
gtk_scrolled_window_set_propagate_natural_width ()
void gtk_scrolled_window_set_propagate_natural_width (GtkScrolledWindow *scrolled_window
,gboolean propagate
);
Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.
gtk_scrolled_window_get_propagate_natural_height ()
gboolean
gtk_scrolled_window_get_propagate_natural_height
(GtkScrolledWindow *scrolled_window
);
Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.
gtk_scrolled_window_set_propagate_natural_height ()
void gtk_scrolled_window_set_propagate_natural_height (GtkScrolledWindow *scrolled_window
,gboolean propagate
);
Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.
Types and Values
enum GtkPolicyType
Determines how the size should be computed to achieve the one of the visibility mode for the scrollbars.
Members
The scrollbar is always visible. The view size is independent of the content. |
||
The scrollbar will appear and disappear as necessary. For example, when all of a GtkTreeView can not be seen. |
||
The scrollbar should never appear. In this mode the content determines the size. |
||
Don't show a scrollbar, but don't force the size to follow the content. This can be used e.g. to make multiple scrolled windows share a scrollbar. |
enum GtkCornerType
Specifies which corner a child widget should be placed in when packed into a GtkScrolledWindow. This is effectively the opposite of where the scroll bars are placed.
Property Details
The “child”
property
“child” GtkWidget *
The child widget.
Owner: GtkScrolledWindow
Flags: Read / Write
The “hadjustment”
property
“hadjustment” GtkAdjustment *
The GtkAdjustment for the horizontal position.
Owner: GtkScrolledWindow
Flags: Read / Write / Construct
The “has-frame”
property
“has-frame” gboolean
Whether to draw a frame around the contents.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: FALSE
The “hscrollbar-policy”
property
“hscrollbar-policy” GtkPolicyType
When the horizontal scrollbar is displayed.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: GTK_POLICY_AUTOMATIC
The “kinetic-scrolling”
property
“kinetic-scrolling” gboolean
Whether kinetic scrolling is enabled or not. Kinetic scrolling
only applies to devices with source GDK_SOURCE_TOUCHSCREEN
.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: TRUE
The “max-content-height”
property
“max-content-height” int
The maximum content height of scrolled_window
, or -1 if not set.
Owner: GtkScrolledWindow
Flags: Read / Write
Allowed values: >= -1
Default value: -1
The “max-content-width”
property
“max-content-width” int
The maximum content width of scrolled_window
, or -1 if not set.
Owner: GtkScrolledWindow
Flags: Read / Write
Allowed values: >= -1
Default value: -1
The “min-content-height”
property
“min-content-height” int
The minimum content height of scrolled_window
, or -1 if not set.
Owner: GtkScrolledWindow
Flags: Read / Write
Allowed values: >= -1
Default value: -1
The “min-content-width”
property
“min-content-width” int
The minimum content width of scrolled_window
, or -1 if not set.
Owner: GtkScrolledWindow
Flags: Read / Write
Allowed values: >= -1
Default value: -1
The “overlay-scrolling”
property
“overlay-scrolling” gboolean
Whether overlay scrolling is enabled or not. If it is, the scrollbars are only added as traditional widgets when a mouse is present. Otherwise, they are overlaid on top of the content, as narrow indicators.
Note that overlay scrolling can also be globally disabled, with the “gtk-overlay-scrolling” setting.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: TRUE
The “propagate-natural-height”
property
“propagate-natural-height” gboolean
Whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.
This is useful in cases where an attempt should be made to allocate exactly enough space for the natural size of the child.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: FALSE
The “propagate-natural-width”
property
“propagate-natural-width” gboolean
Whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.
This is useful in cases where an attempt should be made to allocate exactly enough space for the natural size of the child.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: FALSE
The “vadjustment”
property
“vadjustment” GtkAdjustment *
The GtkAdjustment for the vertical position.
Owner: GtkScrolledWindow
Flags: Read / Write / Construct
The “vscrollbar-policy”
property
“vscrollbar-policy” GtkPolicyType
When the vertical scrollbar is displayed.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: GTK_POLICY_AUTOMATIC
The “window-placement”
property
“window-placement” GtkCornerType
Where the contents are located with respect to the scrollbars.
Owner: GtkScrolledWindow
Flags: Read / Write
Default value: GTK_CORNER_TOP_LEFT
Signal Details
The “edge-overshot”
signal
void user_function (GtkScrolledWindow *scrolled_window, GtkPositionType pos, gpointer user_data)
The ::edge-overshot signal is emitted whenever user initiated scrolling makes the scrolled window firmly surpass (i.e. with some edge resistance) the lower or upper limits defined by the adjustment in that orientation.
A similar behavior without edge resistance is provided by the “edge-reached” signal.
Note: The pos
argument is LTR/RTL aware, so callers should be aware too
if intending to provide behavior on horizontal edges.
Parameters
scrolled_window |
||
pos |
edge side that was hit |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “edge-reached”
signal
void user_function (GtkScrolledWindow *scrolled_window, GtkPositionType pos, gpointer user_data)
The ::edge-reached signal is emitted whenever user-initiated scrolling makes the scrolled window exactly reach the lower or upper limits defined by the adjustment in that orientation.
A similar behavior with edge resistance is provided by the “edge-overshot” signal.
Note: The pos
argument is LTR/RTL aware, so callers should be aware too
if intending to provide behavior on horizontal edges.
Parameters
scrolled_window |
||
pos |
edge side that was reached |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “move-focus-out”
signal
void user_function (GtkScrolledWindow *scrolled_window, GtkDirectionType direction_type, gpointer user_data)
The ::move-focus-out signal is a
keybinding signal which gets
emitted when focus is moved away from the scrolled window by a
keybinding. The “move-focus” signal is emitted with
direction_type
on this scrolled window’s toplevel parent in the
container hierarchy. The default bindings for this signal are
Ctrl + Tab
to move forward and Ctrl + Shift + Tab
to move backward.
Parameters
scrolled_window |
||
direction_type |
either |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “scroll-child”
signal
gboolean user_function (GtkScrolledWindow *scrolled_window, GtkScrollType scroll, gboolean horizontal, gpointer user_data)
The ::scroll-child signal is a keybinding signal which gets emitted when a keybinding that scrolls is pressed. The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself.
Parameters
scrolled_window |
||
scroll |
a GtkScrollType describing how much to scroll |
|
horizontal |
whether the keybinding scrolls the child horizontally or not |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action