ScrollArea¶
The ScrollArea class provides a scrolling view managing up to 4 scroll bars.
A scroll area is used to display the contents of a child surface (
world
). If the surface exceeds the size of the drawing surface, the view provide scroll bars so that the entire area of the child surface can be viewed.Parameters: - area_width (int, float) – Width of scrollable area (px)
- area_height (int, float) – Height of scrollable area (px)
- area_color (tuple, list,
pygame_menu.baseimage.BaseImage
, None) – Background color, it can be a color or an image - extend_x (int, float) – Px to extend the surface in yxaxis (px) from left
- extend_y (int, float) – Px to extend the surface in y axis (px) from top
- scrollbar_color (tuple, list) – Scrollbars color
- scrollbar_slider_color (tuple, list) – Color of the sliders
- scrollbar_slider_pad (int, float) – Space between slider and scrollbars borders
- scrollbar_thick (int, float) – Scrollbars thickness
- scrollbars (tuple, list) – Positions of the scrollbars
- shadow (bool) – Indicate if a shadow is drawn on each scrollbar
- shadow_color (tuple, list) – Color of the shadow
- shadow_offset (int, float) – Offset of shadow
- shadow_position (str) – Position of shadow
- world (
pygame.Surface
, None) – Surface to draw and scroll
If user event collides a widget within the scroll area respect to the relative position.
Parameters: - widget (
pygame_menu.widgets.core.widget.Widget
) – Widget - event (
pygame.event.Event
) – Pygame event
Returns: True if collide
Return type: - widget (
Called by end user to draw state to the surface.
Parameters: surface ( pygame.Surface
) – Surface to render the areaReturns: None
Return the total height out of the bounds of the the viewable area. Zero is returned if the world height is lower than the viewable area.
Returns: Hidden height (px) Return type: int, float
Return the total width out of the bounds of the the viewable area. Zero is returned if the world width is lower than the viewable area.
Returns: Hidden width (px) Return type: int, float
Return the menu reference (if exists).
Returns: Menu reference Return type: pygame_menu.Menu
, None
Return the offset introduced by the scrollbars in the world.
Returns: ScrollArea offset (x, y) Return type: tuple
Return the Rect object.
Returns: Pygame.Rect object Return type: pygame.Rect
Return the scroll thickness of the area. If it’s hidden return zero.
Parameters: Returns: Thickness in px
Return type:
Subtract width of scrollbars from area with the given size and return the viewable area.
The viewable area depends on the world size, because scroll bars may or may not be displayed.
Returns: View rect object
Return the world size.
Returns: Width, height in pixels Return type: tuple
Return true if the user is scrolling.
Returns: True if user scrolls Return type: bool
Ensure that the given rect is in the viewable area.
Parameters: - rect (
pygame.Rect
) – Rect in the world surface reference - margin (int, float) – Extra margin around the rect (px)
Returns: None
- rect (
Set the menu reference.
Parameters: menu ( pygame_menu.Menu
) – Menu objectReturns: None
Set the position.
Parameters: Returns: None
Update the scrolled surface.
Parameters: surface ( pygame.Surface
) – New world surfaceReturns: None
Return the real position/Rect according to the scroll area origin of a position/Rect in the world surface reference.
Parameters: - virtual (
pygame.Rect
, tuple, list) – Position/Rect in the world surface reference - visible (bool) – If a rect is given, return only the visible width/height
Returns: Real rect or real position
Return type: pygame.Rect
, tuple- virtual (
Return the position/Rect in the world surface reference of a real position/Rect according to the scroll area origin.
Parameters: real ( pygame.Rect
, tuple, list) – Position/Rect according scroll area originReturns: Rect in world or position in world Return type: pygame.Rect
, tuple