ScrolledWindow
open class ScrolledWindow : Bin, ScrolledWindowProtocol
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.
GtkScrolledWindow’s implementation of gtk_container_add()
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_container_add()
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:
(C Language Example):
GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
GtkWidget *child_widget = gtk_button_new ();
// GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically
// add a GtkViewport.
gtk_container_add (GTK_CONTAINER (scrolled_window),
child_widget);
// Either of these will result in child_widget being unparented:
gtk_container_remove (GTK_CONTAINER (scrolled_window),
child_widget);
// or
gtk_container_remove (GTK_CONTAINER (scrolled_window),
gtk_bin_get_child (GTK_BIN (scrolled_window)));
Unless GtkScrolledWindow:policy
is 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 GtkScrolledWindow:hadjustment
and GtkScrolledWindow: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
GtkScrolledWindow: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 GtkScrolledWindow::edge-overshot
signal.
If no mouse device is present, the scrollbars will overlayed 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 GtkScrolledWindow:overlay-scrolling
property.
CSS nodes
GtkScrolledWindow has a main CSS node with name scrolledwindow.
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.
The ScrolledWindow
type acts as a reference-counted owner of an underlying GtkScrolledWindow
instance.
It provides the methods that can operate on this data type through ScrolledWindowProtocol
conformance.
Use ScrolledWindow
as a strong reference or owner of a GtkScrolledWindow
instance.
-
Designated initialiser from the underlying `C` data type.
This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the
ScrolledWindow
instance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkScrolledWindow>)
Parameters
op
pointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkScrolledWindow>)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a non-mutating
gpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)
Parameters
op
gpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkScrolledWindow>?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkScrolledWindow>?)
Parameters
op
pointer to the underlying object
-
Designated initialiser from the underlying
C
data type. Will retainGtkScrolledWindow
. i.e., ownership is transferred to theScrolledWindow
instance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkScrolledWindow>)
Parameters
op
pointer to the underlying object
-
Reference intialiser for a related type that implements
ScrolledWindowProtocol
Will retainGtkScrolledWindow
.Declaration
Swift
@inlinable public init<T>(scrolledWindow other: T) where T : ScrolledWindowProtocol
Parameters
other
an instance of a related type that implements
ScrolledWindowProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init<T>(cPointer p: UnsafeMutablePointer<T>)
Parameters
cPointer
pointer to the underlying object
-
Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)
Parameters
cPointer
pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init(raw p: UnsafeRawPointer)
Parameters
p
raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init(retainingRaw raw: UnsafeRawPointer)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable public required init(raw p: UnsafeMutableRawPointer)
Parameters
p
mutable raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable required public init(retainingRaw raw: UnsafeMutableRawPointer)
Parameters
raw
mutable raw pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init(opaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ScrolledWindowProtocol
.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Creates a new scrolled window.
The two arguments are the scrolled window’s adjustments; these will be shared with the scrollbars and the child widget to keep the bars in sync with the child. Usually you want to pass
nil
for the adjustments, which will cause the scrolled window to create them for you.Declaration
Swift
@inlinable public init<AdjustmentT>(hadjustment: AdjustmentT?, vadjustment: AdjustmentT?) where AdjustmentT : AdjustmentProtocol
-
Convenience constructor
Declaration
Swift
@inlinable convenience init<T>(vAdjustment: T!) where T : AdjustmentProtocol
Parameters
vAdjustment
optional vertical adjustment
-
Convenience constructor with a nil adjustment
Declaration
Swift
@inlinable convenience init(vAdjustment: AdjustmentRef? = nil)
Parameters
vAdjustment
optional vertical adjustment