Reference Manual: (offline | online) Quickstart: (offline | online)

# ui.viewport

Function: ui.viewport( | child_size=(None, None), offsets=(0.0, 0.0), style='viewport', **properties)

Displays a viewport on the screen. A viewport restricts the size of its child, and allows the child to be displayed at an offset. Viewports have two methods, set_xoffset and set_yoffset, that allow the offsets to be changed, and hence the viewport to be scrolled.

child_size - The x and y size of the area the child is asked to render. If either is None, defaults to the size of this viewport.

offsets - The x and y offsets. If an integer, this is taken as a number of pixels. If a float, a fraction of the amount by which the child is larger then the viewport.

In general, viewports are only useful when the xmaximum and ymaximum properties are specified. You'll also want to set clipping=True on the style, although this is part of the default viewport style.

The set_xoffset and set_yoffset methods take a single argument, the new value of the offset.

## Example

        python hide:
            vp = ui.viewport(xmaximum=400, ymaximum=400, xpos=100, ypos=50)
            ui.image("mainmenu.jpg")
            ui.bar(1.0, 0.0, style='scrollbar', xmaximum=400, xpos=100, ypos=452, changed=vp.set_xoffset)
            ui.bar(1.0, 0.0, style='vscrollbar', ymaximum=400, xpos=502, ypos=50, changed=vp.set_yoffset)

            ui.textbutton("Dismiss", xpos=300, xanchor=0.5, ypos=550, yanchor=0.5, clicked=ui.returns(True))
            ui.interact()

Reference Manual: (offline | online) Quickstart: (offline | online)