ListBoxes make use of a ListBoxRenderer. The default ListBoxRenderer simply displays an item’s string representation. To make your own ListBoxRenderer create a class that has a render_item() method that accepts the item to be rendered and returns a widget to render.
Here is an simple example of using the ListBox widget:
class MySys(bgui.System):
def lb_click(self, lb):
print(lb.selected)
def __init__(self):
bgui.System.__init__(self)
items = ["One", "Two", 4, 4.6]
self.frame = bgui.Frame(self, 'window', border=2, size=[0.5, 0.5],
options=bgui.BGUI_DEFAULT|bgui.BGUI_CENTERED)
self.lb = bgui.ListBox(self.frame, "lb", items=items, padding=0.05, size=[0.9, 0.9], pos=[0.05, 0.05])
self.lb.on_click = self.lb_click
# ... rest of __init__
Widget for displaying a list of data
Parameters: |
|
---|
Add the animation to the list of currently running animations
Parameters: | animation – The animation |
---|
The widget’s children
Whether or not the widget should accept events
The list of items to display in the ListBox
Move a widget to a new position over a number of frames
Parameters: |
|
---|
The widget’s name
The widget’s on_active callback
The widget’s on_click callback
The widget’s on_hover callback
The widget’s on_mouse_enter callback
The widget’s on_mouse_exit callback
The widget’s on_release callback
The amount of extra spacing to put between items
The widget’s parent
The widget’s position
The ListBoxRenderer to use to display items
The widget’s size
A reference to the system object
Whether or not the widget is visible
The widget’s z-index. Widget’s with a higher z-index are drawn over those that have a lower z-index
Base class for rendering an item in a ListBox
Parameters: | listbox – the listbox the renderer will be used with (used for parenting) |
---|
Creates and returns a bgui.label.Label representation of the supplied item
Parameters: | item – the item to be rendered |
---|---|
Return type: | bgui.label.Label |