Scrollable

class tanmatsu.widgets.Scrollable(*args, scroll_direction: int = 1, **kwargs)

Bases: Widget

A widget that can scroll. Does nothing else. Widgets that need to scroll should inherit from this class.

Parameters

scroll_direction (int) – Must be either NONE, VERTICAL, HORIZONTAL, or BOTH. Defaults to VERTICAL.

The layout function of a descendant of this widget should look like:

def layout(self, *args, **kwargs):
    super().layout(*args, **kwargs)

    content_size = <calculate content size>

    self.layout_scrollbar(content_size)
    self.scroll()
NONE = 0

Not scrollable at all.

VERTICAL = 1

Scrollable vertically.

HORIZONTAL = 2

Scrollable horizontally.

BOTH = 3

Scrollable in both directions.

layout_scrollbar(content_size: Dimensions)

Layout the scrollbar. Must be called before scroll(), inside the layout function of descendants of this class.

property scrollable: bool
Getter

Get whether the widget is scrollable or not. I.e., whether the scroll direction ≠ Scrollable.NONE.

property scroll_direction: int
Getter

Get the scroll direction.

Setter

Set the scroll direction.

scroll(delta_x: int = 0, delta_y: int = 0)

Scroll the widget by the specified deltas. Must be called after layout_scrollbar(), inside the layout function of descendants of this class.