Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions arcade/gui/examples/scroll_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
from arcade import Window
from arcade.gui import UIManager, UIWidget, Property, Surface, UIDummy, UIEvent, bind, \
UIMouseDragEvent, UIMouseScrollEvent, UIMouseEvent, UIBoxLayout, UIFlatButton, UIInputText
from arcade.types import Point


class UIScrollArea(UIWidget):
scroll_x = Property[float](default=0.0)
scroll_y = Property[float](default=0.0)
canvas_size = Property[Point](default=(300.0, 300.0))

scroll_speed = 1.3
invert_scroll = False

def __init__(self, *, x: float = 0, y: float = 0, width: float = 300, height: float = 300,
children: Iterable["UIWidget"] = tuple(), size_hint=None, size_hint_min=None, size_hint_max=None,
def __init__(self, *,
x: float = 0, y: float = 0, width: float = 300, height: float = 300,
children: Iterable["UIWidget"] = tuple(),
size_hint=None,
size_hint_min=None,
size_hint_max=None,
canvas_size=(300, 300),
**kwargs):
super().__init__(x=x, y=y, width=width, height=height, children=children, size_hint=size_hint,
size_hint_min=size_hint_min, size_hint_max=size_hint_max, **kwargs)
self.surface = Surface(
size=(300, 300),
size=canvas_size,
)

bind(self, "scroll_x", self.trigger_full_render)
Expand Down Expand Up @@ -72,7 +75,8 @@ def _do_render(self, surface: Surface, force=False) -> bool:

def do_render(self, surface: Surface):
self.prepare_render(surface)
width, height = self.content_size
# draw the whole surface, the scissor box, will limit the visible area on screen
width, height = self.surface.size
self.surface.position = (-self.scroll_x, -self.scroll_y)
self.surface.draw((0, 0, width, height))

Expand Down