## GtkViewport GtkViewport — An adapter which makes widgets scrollable |

## Functions

GtkWidget * | gtk_viewport_new ()
void | gtk_viewport_set_scroll_to_focus ()
gboolean | gtk_viewport_get_scroll_to_focus ()
void | gtk_viewport_set_child ()
GtkWidget * | gtk_viewport_get_child ()

## Properties

GtkWidget * | child | Read / Write
gboolean | scroll-to-focus | Read / Write

## Types and Values

| GtkViewport

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkWidget
                ╰── GtkViewport

## Implemented Interfaces

GtkViewport implements AtkImplementorIface, GtkBuildable, GtkConstraintTarget and GtkScrollable.

## Includes

    #include <gtk/gtk.h>

## Description

The GtkViewport widget acts as an adaptor class, implementing scrollability for child widgets that lack their own scrolling capabilities. Use GtkViewport to scroll child widgets such as GtkGrid, GtkBox, and so on.

If a widget has native scrolling abilities, such as GtkTextView, GtkTreeView or GtkIconView, it can be added to a GtkScrolledWindow with `gtk_container_add()`. If a widget does not, you must first add the widget to a GtkViewport, then add the viewport to the scrolled window. `gtk_container_add()` does this automatically if a child that does not implement GtkScrollable is added to a GtkScrolledWindow, so you can ignore the presence of the viewport.

The GtkViewport will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.

### CSS nodes

GtkViewport has a single CSS node with name viewport.

## Functions

### gtk_viewport_new ()

    GtkWidget *
    gtk_viewport_new (GtkAdjustment *hadjustment,
                      GtkAdjustment *vadjustment);

Creates a new GtkViewport with the given adjustments, or with default adjustments if none are given.

#### Parameters

hadjustment | horizontal adjustment. | [allow-none]
vadjustment | vertical adjustment. | [allow-none]

#### Returns

a new GtkViewport

### gtk_viewport_set_scroll_to_focus ()

    void
    gtk_viewport_set_scroll_to_focus (GtkViewport *viewport,
                                      gboolean scroll_to_focus);

Sets whether the viewport should automatically scroll to keep the focused child in view.

#### Parameters

viewport | a GtkViewport |
scroll_to_focus | whether to keep the focus widget scrolled to view |

### gtk_viewport_get_scroll_to_focus ()

    gboolean
    gtk_viewport_get_scroll_to_focus (GtkViewport *viewport);

Gets whether the viewport is scrolling to keep the focused child in view. See `gtk_viewport_set_scroll_to_focus()`.

#### Parameters

viewport | a GtkViewport |

#### Returns

`TRUE` if the viewport keeps the focus child scrolled to view

### gtk_viewport_set_child ()

    void
    gtk_viewport_set_child (GtkViewport *viewport,
                            GtkWidget *child);

Sets the child widget of `viewport` .

#### Parameters

viewport | a GtkViewport |
child | the child widget. | [allow-none]

### gtk_viewport_get_child ()

    GtkWidget *
    gtk_viewport_get_child (GtkViewport *viewport);

Gets the child widget of `viewport` .

#### Parameters

viewport | a GtkViewport |

#### Returns

the child widget of `viewport` .

[nullable][transfer none]

## Types and Values

### GtkViewport

    typedef struct _GtkViewport GtkViewport;

## Property Details

### The `“child”` property

      “child”                    GtkWidget *

The child widget.

Owner: GtkViewport

Flags: Read / Write

### The `“scroll-to-focus”` property

      “scroll-to-focus”          gboolean

Whether to scroll when the focus changes.

Owner: GtkViewport

Flags: Read / Write

Default value: FALSE

## See Also

GtkScrolledWindow, GtkAdjustment