Difference between revisions of "Librocket API Context"
From FreeSpace Wiki
(Created page with "{{Librocket_API}} ==Properties== {| border=1 cellpadding=4 style="border-collapse: collapse" |- | Lua property | Brief description | Equivalent functions |- | dimensions | Get...") |
(No difference)
|
Latest revision as of 19:09, 22 April 2023
| Librocket API references | |
|---|---|
| Elements | |
| Documents | |
| Contexts | |
| Events | |
| API Reference | |
Properties
| Lua property | Brief description | Equivalent functions |
| dimensions | Gets/sets the dimensions of the context. | GetDimensions(), SetDimensions() |
| documents | Retrieves a document within the interface. | GetDocument(), GetNumDocuments() |
| focus_element | Retrieves the context’s focus element. | GetFocusElement() |
| hover_element | Retrieves the element under the context’s cursor. | GetHoverElement() |
| root_element | Retrieves the context’s root element. | GetRootElement() |
| name | Retrieves the context’s name. | GetName() |
Retrieving documents
The documents property on the context can be referenced in several ways. For example, as an array:
for document in context.documents: ba.print(document.title)
Or as a dictionary, looking documents up by their ID:
document = context.documents["highscores"]
Or accessing documents as attributes on the documents property itself:
document = context.documents.highscores
Methods
The following methods are available.
| Luamethod | Brief description |
| AddEventListener() | Attaches an inline event listener to the root of the context. |
| AddMouseCursor() | Adds a previously-loaded mouse cursor to the document. |
| CreateDocument() | Creates a new document. |
| LoadDocument() | Loads a document from an external RML file. |
| LoadMouseCursor() | Loads a mouse cursor from an external RML file. |
| Render() | Renders the context. |
| ShowMouseCursor() | Shows or hides the mouse cursor. |
| UnloadAllDocuments() | Unloads all loaded documents within the context. |
| UnloadAllMouseCursors() | Unloads all of the context’s mouse cursors. |
| UnloadDocument() | Unloads one of the context’s documents. |
| UnloadMouseCursor() | Unloads one of the context’s cursors. |
| Update() | Updates the context. |
Creating contexts
Contexts can be created in Python with the CreateContext() function in the libRocket module. This function takes the name of the context as a string and the dimensions as an Vector2i type.
new_context = rocket:CreateContext("hud", rocket.Vector2i(1024, 768))
Accessing contexts
Existing contexts can be accessed in Lua via the contexts member on the rocket module. They can then be accessed via name or index.
context = rocket.contexts["hud"]
List all contexts
for context in rocket.contexts: print context.name