topdownengine.ui Reference¶
BaseUIElement
¶
Base class for UI elements.
Attributes:
| Name | Type | Description |
|---|---|---|
containers |
set[UIContainer]
|
The set of all containers that contain this element. This is a managed property. |
image |
Surface
|
The surface of the element. This is a managed property. |
Source code in topdownengine\ui.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
containers
property
¶
The set of all containers that contain this element. This is a managed property.
image
property
writable
¶
The surface of the element. This is a managed property.
__init__(position, align='center', image=None)
¶
Handle a single event for all elements in this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Point
|
The position of the element. |
required |
align
|
str
|
The alignment of the element. |
'center'
|
image
|
Surface
|
The image to use for the element. |
None
|
Source code in topdownengine\ui.py
add_container(container)
¶
Add this UI element to a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
UIContainer
|
The container to add. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the container is not an instance of UIContainer. |
Source code in topdownengine\ui.py
handle_event(event)
¶
Handle a single event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event
|
The event to handle. |
required |
remove_container(container)
¶
Remove this UI element from a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
UIContainer
|
The container to remove from. |
required |
Source code in topdownengine\ui.py
remove_from_all_containers()
¶
Button
¶
Bases: BaseUIElement
Source code in topdownengine\ui.py
containers
property
¶
The set of all containers that contain this element. This is a managed property.
add_container(container)
¶
Add this UI element to a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
UIContainer
|
The container to add. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the container is not an instance of UIContainer. |
Source code in topdownengine\ui.py
is_mouse_over()
¶
remove_container(container)
¶
Remove this UI element from a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
UIContainer
|
The container to remove from. |
required |
Source code in topdownengine\ui.py
remove_from_all_containers()
¶
UIContainer
¶
Class to store a collection of UI elements.
Attributes:
| Name | Type | Description |
|---|---|---|
elements |
set[BaseUIElement]
|
The set of all elements in this container. This is a managed property. |
Source code in topdownengine\ui.py
elements
property
¶
The set of all elements in this container. This is a managed property.
__init__()
¶
add_ui_element(element)
¶
Add a UI element to this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
BaseUIElement
|
The element to add. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the element is not an instance of a subclass of BaseUIElement. |
Source code in topdownengine\ui.py
handle_event(event)
¶
Handle a single event for all elements in this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event
|
The event to handle. |
required |
remove_all_ui_elements()
¶
remove_ui_element(element)
¶
Remove a UI element from this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
BaseUIElement
|
The element to remove. |
required |
render(surface)
¶
Render all elementsto a given surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
Surface
|
The surface to render to. |
required |