Struct gtk4::ScrolledWindow[][src]

pub struct ScrolledWindow(_);
Expand description

ScrolledWindow is a container that makes its child scrollable.

It does so 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 Scrollable interface, are added directly. For other types of widget, the class Viewport acts as an adaptor, giving scrollability to other widgets. set_child() intelligently accounts for whether or not the added child is a Scrollable. If it isn’t, then it wraps the child in a Viewport. Therefore, you can just add any child widget and not worry about the details.

If set_child() has added a Viewport for you, you can remove both your added child widget from the Viewport, and the Viewport from the ScrolledWindow, like this:

⚠️ The following code is in c ⚠️

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 property::ScrolledWindow::hscrollbar-policy and property::ScrolledWindow::vscrollbar-policy are PolicyType::Never or PolicyType::External, ScrolledWindow adds internal Scrollbar widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by the property::ScrolledWindow::hadjustment and property::ScrolledWindow::vadjustment that are associated with the ScrolledWindow. See the docs on Scrollbar 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 ScrolledWindow 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 Scrollbar and for example a Grid.

Touch support

ScrolledWindow 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 property::ScrolledWindow::kinetic-scrolling property if it is undesired.

ScrolledWindow also displays visual ‘overshoot’ indication when the content is pulled beyond the end, and this situation can be captured with the signal::ScrolledWindow::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 property::ScrolledWindow::overlay-scrolling property.

CSS nodes

ScrolledWindow has a main CSS node with name scrolledwindow. It gets a .frame style class added when property::ScrolledWindow::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.

ScrolledWindow 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.

Accessibility

ScrolledWindow uses the AccessibleRole::Group role.

Implements

WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, WidgetExtManual, AccessibleExtManual

Implementations

Creates a new scrolled window.

Returns

a new scrolled window

Creates a new builder-pattern struct instance to construct ScrolledWindow objects.

This method returns an instance of ScrolledWindowBuilder which can be used to create ScrolledWindow objects.

Gets the child widget of self.

Returns

the child widget of self

Returns the horizontal scrollbar’s adjustment.

This is the adjustment used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality.

Returns

the horizontal Adjustment

Gets whether the scrolled window draws a frame.

Returns

true if the self has a frame

Returns the horizontal scrollbar of self.

Returns

the horizontal scrollbar of the scrolled window.

Returns the specified kinetic scrolling behavior.

Returns

the scrolling behavior flags.

Returns the maximum content height set.

Returns

the maximum content height, or -1

Returns the maximum content width set.

Returns

the maximum content width, or -1

Gets the minimal content height of self.

Returns

the minimal content height

Gets the minimum content width of self.

Returns

the minimum content width

Returns whether overlay scrolling is enabled for this scrolled window.

Returns

true if overlay scrolling is enabled

Gets the placement of the contents with respect to the scrollbars.

Returns

the current placement value.

Retrieves the current policy values for the horizontal and vertical scrollbars.

See set_policy().

Returns
hscrollbar_policy

location to store the policy for the horizontal scrollbar

vscrollbar_policy

location to store the policy for the vertical scrollbar

Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.

Returns

whether natural height propagation is enabled.

Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.

Returns

whether natural width propagation is enabled.

Returns the vertical scrollbar’s adjustment.

This is the adjustment used to connect the vertical scrollbar to the child widget’s vertical scroll functionality.

Returns

the vertical Adjustment

Returns the vertical scrollbar of self.

Returns

the vertical scrollbar of the scrolled window.

Sets the child widget of self.

child

the child widget

Sets the Adjustment for the horizontal scrollbar.

hadjustment

the Adjustment to use, or None to create a new one

Changes the frame drawn around the contents of self.

has_frame

whether to draw a frame around scrolled window contents

Turns kinetic scrolling on or off.

Kinetic scrolling only applies to devices with source GDK_SOURCE_TOUCHSCREEN.

kinetic_scrolling

true to enable kinetic scrolling

Sets the maximum height that self should keep visible.

The self 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 property::ScrolledWindow::min-content-height.

height

the maximum content height

Sets the maximum width that self should keep visible.

The self 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 property::ScrolledWindow::min-content-width.

width

the maximum content width

Sets the minimum height that self 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 property::ScrolledWindow::max-content-height.

height

the minimal content height

Sets the minimum width that self 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 property::ScrolledWindow::max-content-width.

width

the minimal content width

Enables or disables overlay scrolling for this scrolled window.

overlay_scrolling

whether to enable overlay scrolling

Sets the placement of the contents with respect to the scrollbars for the scrolled window.

The default is CornerType::TopLeft, meaning the child is in the top left, with the scrollbars underneath and to the right. Other values in CornerType are CornerType::TopRight, CornerType::BottomLeft, and CornerType::BottomRight.

See also placement() and unset_placement().

window_placement

position of the child window

Sets the scrollbar policy for the horizontal and vertical scrollbars.

The policy determines when the scrollbar should appear; it is a value from the PolicyType enumeration. If PolicyType::Always, the scrollbar is always present; if PolicyType::Never, the scrollbar is never present; if PolicyType::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).

hscrollbar_policy

policy for horizontal bar

vscrollbar_policy

policy for vertical bar

Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.

propagate

whether to propagate natural height

Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.

propagate

whether to propagate natural width

Sets the Adjustment for the vertical scrollbar.

vadjustment

the Adjustment to use, or None to create a new one

Unsets the placement of the contents with respect to the scrollbars.

If no window placement is set for a scrolled window, it defaults to CornerType::TopLeft.

When the horizontal scrollbar is displayed.

Use set_policy() to set this property.

When the horizontal scrollbar is displayed.

Use set_policy() to set this property.

When the vertical scrollbar is displayed.

Use set_policy() to set this property.

When the vertical scrollbar is displayed.

Use set_policy() to set this property.

Where the contents are located with respect to the scrollbars.

Where the contents are located with respect to the scrollbars.

Emitted whenever user initiated scrolling makes the scrolled window firmly surpass the limits defined by the adjustment in that orientation.

A similar behavior without edge resistance is provided by the signal::ScrolledWindow::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.

pos

edge side that was hit

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 signal::ScrolledWindow::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.

pos

edge side that was reached

Emitted when focus is moved away from the scrolled window by a keybinding.

This is a keybinding signal.

The default bindings for this signal are Ctrl + Tab to move forward and Ctrl + Shift + Tab to move backward.

direction_type

either DirectionType::TabForward or DirectionType::TabBackward

Emitted when a keybinding that scrolls is pressed.

This is a keybinding signal.

The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself.

scroll

a ScrollType describing how much to scroll

horizontal

whether the keybinding scrolls the child horizontally or not

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Same as emit but takes Value for the arguments.

Emit signal by its name.

Same as emit_by_name but takes Value for the arguments.

Emit signal with details by signal id.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.