|
|
| Line 1: |
Line 1: |
| {{Librocket_API}} | | {{SCPUI moved|https://github.com/MjnMixael/SCPUI/wiki/Librocket-API-Context}} |
| ==Properties==
| |
| {| border=1 cellpadding=4 style="border-collapse: collapse"
| |
| |-
| |
| | 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:
| |
| <pre>
| |
| for document in context.documents:
| |
| ba.print(document.title)
| |
| </pre>
| |
| Or as a dictionary, looking documents up by their ID:
| |
| <pre>
| |
| document = context.documents["highscores"]
| |
| </pre>
| |
| Or accessing documents as attributes on the documents property itself:
| |
| <pre>
| |
| document = context.documents.highscores
| |
| </pre>
| |
| | |
| ==Methods==
| |
| The following methods are available.
| |
| | |
| {| border=1 cellpadding=4 style="border-collapse: collapse"
| |
| |-
| |
| | 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.
| |
| <pre>
| |
| new_context = rocket:CreateContext("hud", rocket.Vector2i(1024, 768))
| |
| </pre>
| |
| | |
| ==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.
| |
| <pre>
| |
| context = rocket.contexts["hud"]
| |
| </pre>
| |
| List all contexts
| |
| <pre>
| |
| for context in rocket.contexts:
| |
| print context.name
| |
| </pre>
| |