ScrollArea

class pygame_menu.scrollarea.ScrollArea(area_width, area_height, area_color=None, extend_x=0, extend_y=0, scrollbar_color=(235, 235, 235), scrollbar_slider_color=(200, 200, 200), scrollbar_slider_pad=0, scrollbar_thick=20, scrollbars=('__pygame_menu_position_south__', '__pygame_menu_position_east__'), shadow=False, shadow_color=(0, 0, 0), shadow_offset=2, shadow_position='__pygame_menu_position_southeast__', world=None)[source]

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 x axis (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

collide(widget, event)[source]

If user event collides a widget within the scroll area respect to the relative position.

Parameters
Returns

True if collide

Return type

bool

draw(surface)[source]

Called by end user to draw state to the surface.

Parameters

surface (pygame.Surface) – Surface to render the area

Returns

None

get_hidden_height()[source]

Return the total height out of the bounds of the viewable area. Zero is returned if the world height is lower than the viewable area.

Returns

Hidden height (px)

Return type

int, float

get_hidden_width()[source]

Return the total width out of the bounds of the viewable area. Zero is returned if the world width is lower than the viewable area.

Returns

Hidden width (px)

Return type

int, float

get_menu()[source]

Return the menu reference (if exists).

Returns

Menu reference

Return type

pygame_menu.Menu, None

get_offsets()[source]

Return the offset introduced by the scrollbars in the world.

Returns

ScrollArea offset (x, y)

Return type

tuple

get_rect()[source]

Return the Rect object.

Returns

Pygame.Rect object

Return type

pygame.Rect

get_scrollbar_thickness(orientation, real=False)[source]

Return the scroll thickness of the area. If it’s hidden return zero.

Parameters
  • orientation (str) – Orientation of the scroll

  • real (bool) – If True returns the real thickness depending if it is shown or not

Returns

Thickness in px

Return type

int

get_view_rect()[source]

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

get_world_size()[source]

Return the world size.

Returns

Width, height in pixels

Return type

tuple

is_scrolling()[source]

Return true if the user is scrolling.

Returns

True if user scrolls

Return type

bool

scroll_to_rect(rect, margin=10.0)[source]

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

set_menu(menu)[source]

Set the menu reference.

Parameters

menu (pygame_menu.Menu) – Menu object

Returns

None

set_position(posx, posy)[source]

Set the position.

Parameters
Returns

None

set_world(surface)[source]

Update the scrolled surface.

Parameters

surface (pygame.Surface) – New world surface

Returns

None

to_real_position(virtual, visible=False)[source]

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

to_world_position(real)[source]

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 origin

Returns

Rect in world or position in world

Return type

pygame.Rect, tuple

update(events)[source]

Called by end user to update scroll state.

Parameters

events (list) – List of pygame events

Returns

True if updated

Return type

bool