Box

class pygamelib.gfx.ui.Box(width: int, height: int, title: str = '', config: pygamelib.gfx.ui.UiConfig = None, fill: bool = False, filling_sprixel: pygamelib.gfx.core.Sprixel = None, title_alignment: int = 30000101)

Bases: object

A simple object to draw a box on screen.

The Box object’s looks and feel is highly configurable through the UiConfig object.

__init__(width: int, height: int, title: str = '', config: pygamelib.gfx.ui.UiConfig = None, fill: bool = False, filling_sprixel: pygamelib.gfx.core.Sprixel = None, title_alignment: int = 30000101)

The box constructor takes the following parameters.

Parameters:
  • width (int) – The width of the box.
  • height (int) – The height of the box.
  • title (str | Text) – The title of the box (encased in the top border).
  • config (UiConfig) – The configuration object.
  • fill (bool) – A tag to tell the box object to fill its inside (or not).
  • filling_sprixel (Sprixel) – If fill is True, the filling Sprixel is used to fill the inside of the box.
  • title_alignment (int) – The alignment of the title in the top bar. It is a constant from the constant module and can be ALIGN_LEFT, ALIGN_RIGHT and ALIGN_CENTER. THIS FEATURE IS NOT YET IMPLEMENTED.

Todo

Implement the title alignment.

Example:

config = UiConfig(bg_color=None)
box = Box(30, 10, 'This is a box')
screen.place(box, 20, 20)
screen.update()

Methods

__init__(width, height, title, config, fill, …) The box constructor takes the following parameters.
render_to_buffer(buffer, row, column, …) Render the box into a display buffer (not a screen buffer).

Attributes

config Get and set the config object (UiConfig).
height Get and set the height of the box, only accept int.
title Get and set the title, only accepts str or Text.
width Get and set the width of the box, only accept int.
config

Get and set the config object (UiConfig).

height

Get and set the height of the box, only accept int.

render_to_buffer(buffer, row, column, buffer_height, buffer_width) → None

Render the box into a display buffer (not a screen 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.
title

Get and set the title, only accepts str or Text.

width

Get and set the width of the box, only accept int.