GridSelectorο
- class pygamelib.gfx.ui.GridSelector(choices: list = None, max_height: int = None, max_width: int = None, config: UiConfig = None)ο
Bases:
object
The GridSelector is a widget that present a list of elements as a grid to the user.
It also provides the API to draw and manage the cursor and to retrieve the selected element.
Warning
In the first version of that widget, only the characters that have a length of 1 are supported. This excludes some UTF8 characters and most of the emojis.
- __init__(choices: list = None, max_height: int = None, max_width: int = None, config: UiConfig = None) None ο
- Parameters:
Example:
choices = ["@","#","$","%","&","*","[","]"] grid_selector = GridSelector(choices, 10, 30, conf) screen.place(grid_selector, 10, 10) screen.update()
Methods
__init__
([choices,Β max_height,Β max_width,Β ...])- param choices:
A list of choices to present to the user. The elements of the
Returns the currently selected sprixel.
Move the selection cursor one row down.
Move the selection cursor one column to the left.
Move the selection cursor one column to the right.
Move the selection cursor one row up.
Returns the number of items per page.
nb_pages
()Returns the number of pages.
Change the current page to the one immediately down (current_page + 1).
page_up
()Change the current page to the one immediately up (current_page - 1).
render_to_buffer
(buffer,Β row,Β column,Β ...)Render the object from the display buffer to the frame buffer.
Attributes
Get and set the list of choices, it has to be a list of
Sprixel
or str.Get and set the currently selected item's index (the current choice), it needs to be an int.
Get and set the current page of the grid selector, it needs to be an int.
Get and set the maximum height of the grid selector, it needs to be an int.
Get and set the maximum width of the grid selector, it needs to be an int.
- property current_choice: intο
Get and set the currently selected itemβs index (the current choice), it needs to be an int. Use
current_sprixel()
to get the actual current item.
- property current_page: intο
Get and set the current page of the grid selector, it needs to be an int.
- cursor_down() None ο
Move the selection cursor one row down.
- cursor_left() None ο
Move the selection cursor one column to the left.
- cursor_right() None ο
Move the selection cursor one column to the right.
- cursor_up() None ο
Move the selection cursor one row up.
- items_per_page() int ο
Returns the number of items per page.
- property max_height: intο
Get and set the maximum height of the grid selector, it needs to be an int.
- property max_width: intο
Get and set the maximum width of the grid selector, it needs to be an int.
- nb_pages() int ο
Returns the number of pages.
- page_down() None ο
Change the current page to the one immediately down (current_page + 1).
- page_up() None ο
Change the current page to the one immediately up (current_page - 1).
- render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) None ο
Render the object from the display buffer to the frame buffer.
This method is automatically called by
pygamelib.engine.Screen.render()
.- Parameters:
buffer (numpy.array) β A screen buffer to render the item into.
row (int) β The row to render in.
column (int) β The column to render in.
height (int) β The total height of the display buffer.
width (int) β The total width of the display buffer.