---
title: ScrollView
description: ScrollView api.
---

import SlintProperty from '@slint/common-files/src/components/SlintProperty.astro';
import CodeSnippetMD from '@slint/common-files/src/components/CodeSnippetMD.astro';

<CodeSnippetMD imagePath="/src/assets/generated/std-widgets-scrollview.png"  imageWidth="200" imageHeight="200"  imageAlt='scrollview example'>
```slint playground
import { ScrollView } from "std-widgets.slint";
export component Example inherits Window {
    width: 200px;
    height: 200px;
    ScrollView {
        width: 200px;
        height: 200px;
        viewport-width: 300px;
        viewport-height: 300px;
        Rectangle { width: 30px; height: 30px; x: 275px; y: 50px; background: blue; }
        Rectangle { width: 30px; height: 30px; x: 175px; y: 130px; background: red; }
        Rectangle { width: 30px; height: 30px; x: 25px; y: 210px; background: yellow; }
        Rectangle { width: 30px; height: 30px; x: 98px; y: 55px; background: orange; }
    }
}
```
</CodeSnippetMD>

A Scrollview contains a viewport that is bigger than the view and can be
scrolled. It has scrollbar to interact with.

The ScrollView is scrollable if the `viewport-width` and `viewport-height` properties
are bigger than the size of the visible area.

If the ScrollView contains a layout, the default value for the `viewport-width` and
`viewport-height` is the minimum size of that layout.

## Properties

### enabled
<SlintProperty propName="enabled" typeName="bool" defaultValue="true">
Used to render the frame as disabled or enabled, but doesn't change behavior of the widget.
</SlintProperty>

### mouse-drag-pan-enabled
<SlintProperty propName="mouse-drag-pan-enabled" typeName="bool" defaultValue="true for Material style, false for all others" propertyVisibility="in">
When true, the view can be scrolled by dragging with the mouse.
</SlintProperty>

### has-focus
<SlintProperty propName="has-focus" typeName="bool" defaultValue="false" propertyVisibility="in-out">
Used to render the frame as focused or unfocused, but doesn't change the behavior of the widget.
</SlintProperty>

### viewport-width
<SlintProperty propName="viewport-width" typeName="length" propertyVisibility="in-out">
The width of the viewport of the scrollview.
</SlintProperty>

### viewport-height
<SlintProperty propName="viewport-height" typeName="length" propertyVisibility="in-out">
The height of the viewport of the scrollview.
</SlintProperty>

### viewport-x
<SlintProperty propName="viewport-x" typeName="length" propertyVisibility="in-out">
The `x` position of the scrollview relative to the viewport. This is usually a negative value.
</SlintProperty>

### viewport-y
<SlintProperty propName="viewport-y" typeName="length" propertyVisibility="in-out">
The `y` position of the scrollview relative to the viewport. This is usually a negative value.
</SlintProperty>

### visible-width
<SlintProperty propName="visible-width" typeName="length" propertyVisibility="out">
The width of the visible area of the ScrollView (not including the scrollbar)
</SlintProperty>

### visible-height
<SlintProperty propName="visible-height" typeName="length" propertyVisibility="out">
The height of the visible area of the ScrollView (not including the scrollbar)
</SlintProperty>

### vertical-scrollbar-policy
<SlintProperty propName="vertical-scrollbar-policy" typeName="enum" enumName="ScrollBarPolicy" defaultValue="as-needed">
The vertical scroll bar visibility policy.
</SlintProperty>

### horizontal-scrollbar-policy
<SlintProperty propName="horizontal-scrollbar-policy" typeName="enum" enumName="ScrollBarPolicy" defaultValue="as-needed">
The horizontal scroll bar visibility policy.
</SlintProperty>

## Callbacks

### scrolled()
Invoked when `viewport-x` or `viewport-y` is changed by a user action (dragging, scrolling).

```slint {11-14}
ScrollView {
    width: 200px;
    height: 200px;
    viewport-width: 300px;
    viewport-height: 300px;
    Rectangle { width: 30px; height: 30px; x: 275px; y: 50px; background: blue; }
    Rectangle { width: 30px; height: 30px; x: 175px; y: 130px; background: red; }
    Rectangle { width: 30px; height: 30px; x: 25px; y: 210px; background: yellow; }
    Rectangle { width: 30px; height: 30px; x: 98px; y: 55px; background: orange; }

    scrolled() => {
        debug("viewport-x: ", self.viewport-x);
        debug("viewport-y: ", self.viewport-y);
    }
}
```
