InfoBox
- class pygamepopup.components.InfoBox(title, element_grid, width=400, element_linked=None, position=None, has_close_button=True, title_color=(255, 255, 255, 255), background_path=None, close_button_text=None, close_button_background_path=None, close_button_background_hover_path=None, visible_on_background=True, has_vertical_separator=False, identifier='')
This class is defining any kind of popup that can be found in the app.
It can be used to represent the interface of a menu, or a simple text message. Some elements can be buttons, that will react to user clicks (see the button component for more information).
- Keyword Arguments:
title (str) – the title of the infoBox
element_grid (list[list[BoxElement]]) – a grid containing the components that should be rendered by the infoBox
width (int) – the width of the infoBox, defaults to DEFAULT_POPUP_WIDTH
element_linked (pygame.Rect) – the pygame Rect of the element linked to this infoBox, the infoBox will be displayed beside the element if provided
position (Position) – the static position of the infoBox, if not provided position would be computed basing on
screen (element linked or) –
has_close_button (bool) – whether a close button should be added at the bottom or not, defaults to True
title_color (pygame.Color) – the color of the title
background_path (str) – the path corresponding to the image that should be the sprite of the infoBox
close_button_text (str) – the text that will be shown on close button
close_button_background_path (str) – the path to the image corresponding to the sprite of the close button if there should be one
close_button_background_hover_path (str) – the path to the image corresponding to the sprite of the close button when it is hovered if there should be one
visible_on_background (bool) – whether the popup is visible on background or not, defaults to True
has_vertical_separator (bool) – whether there should be a line splitting the infoBox in two at middle width or not, defaults to False
identifier (str) – a string permitting to identify the menu among others if needed
- title
the title of the infoBox
- Type:
str
- element_linked
the pygame Rect of the element linked to this infoBox if there is one
- Type:
- has_close_button
whether the infoBox has a close button or not
- Type:
bool
- title_color
the color of the title
- Type:
- element_grid
the grid containing the components that should be rendered by the infoBox
- Type:
list[list[BoxElement]
- buttons
the sequence of buttons of the infoBox, including the close button if present
- Type:
Sequence[Button]
- sprite
the pygame Surface corresponding to the sprite of the infoBox
- Type:
- visible_on_background
whether the popup is visible on background or not
- Type:
bool
- identifier
a string permitting to identify the menu among others if needed
- Type:
str
- click(position)
Handle the triggering of a click event.
- Returns:
- the data corresponding to the action that should be done if the click was done
on a button, else None.
- Return type:
Optional[Callable]
- Keyword Arguments:
position (Position) – the position of the mouse
- determine_elements_position()
Compute the position of each element and update it if needed.
- determine_position(screen)
Compute the position of the infoBox to be beside the linked element.
If no element is linked to the infoBox, the position will be determined at display time according to the screen.
- Returns:
the computed position.
- Return type:
Optional[Position]
- Keyword Arguments:
screen (pygame.Surface) – The screen on which the infoBox is rendered.
- display(screen)
Display the infoBox and all its elements.
- Keyword Arguments:
screen (pygame.Surface) – the screen on which the displaying should be done
- find_buttons()
Search in all elements for buttons.
- Returns:
the sequence of buttons.
- Return type:
Sequence[Button]
- init_elements()
Initialize the graphical elements associated to the formal data that the infoBox should represent.
- Returns:
the elements in a 2D structure corresponding to the relative position of each element.
- init_render(screen, close_button_callback=None)
Initialize the rendering of the popup.
Compute it size and its position according to the given screen. Determine the position of each component.
- Keyword Arguments:
screen (pygame.Surface) – the screen on which the popup is
close_button_callback (Callable) – the callback that should be executed when clicking on the close button if there is any