RmlElement
Summary
Represents an element in the RmlUi DOM tree, providing DOM-like manipulation, layout inspection, styling, and event handling based on the RmlUi C++ Element API.
Remarks
Danger
All calls made within this class MUST be performed on the Master Thread. See Threads.RunLater on how to safely call this from an asynchronous thread. Failure to comply with this can cause catastrophical failures as the engine is not designed for this.
Definition
Namespace: SDT4.Managed.UI.Rml
Assembly: SDT4.Managed.UI.dll
class RmlElement
Inheritance:
Object ➔ RmlElement
Implements:
IDisposable
Fields
| Name | Type | Description |
|---|---|---|
Properties
| Name | Type | Description |
|---|---|---|
public get; Attributes |
Object | An object representing the declarations of an element’s attribute collection. Returns NamedNodeMap. Attributes are accessed in C# property naming conventions, e.g. |
public get; AttributesTyped |
NamedNodeMap | Gets the strongly typed attribute collection for this element. |
public get; Style |
Object | An object representing the declarations of an element’s style attributes. Returns RcssStyleDeclaration. Styles are accessed in C# property naming conventions, e.g. |
public get; StyleTyped |
RcssStyleDeclaration | Gets an object representing the inline RCSS style declarations of this element. |
public get; set; Id |
String? | Gets or sets the unique identifier ( |
public get; set; ClassName |
String | Gets or sets the |
public get; set; InnerRml |
String | Gets or sets the serialized RML markup contained within the element. Setting this parses the markup and replaces all child nodes. |
public get; set; InnerText |
String? | Gets or sets the raw text content of the element if this element is or wraps a text node. Returns |
public get; set; Value |
RmlVariant | Gets or sets the value of the element. For form controls (inputs, selects, etc.), this interacts with the underlying form control value; otherwise, it accesses the |
public get; set; OwnerDocument |
RmlDocument | Gets the top-level RmlDocument that contains this element. |
public get; PreviousSibling |
RmlElement | Gets the node immediately preceding this element in its parent's child list, or |
public get; NextSibling |
RmlElement | Gets the node immediately following this element in its parent's child list, or |
public get; ParentNode |
RmlElement | Gets the parent RmlElement of this element in the DOM tree, or |
public get; ChildNodes |
RmlElement[] | Gets an array containing all child elements of this element. |
public get; FirstChild |
RmlElement | Gets the first direct child element of this node, or |
public get; LastChild |
RmlElement | Gets the last direct child element of this node, or |
public get; ClassList |
DomTokenList | Gets a live DomTokenList representing the element's class attribute, allowing manipulation of individual classes (add, remove, toggle, contains). |
public get; ClientHeight |
Single | Gets the inner height of the element in pixels, including padding but excluding borders, margins, and horizontal scrollbars. |
public get; ClientLeft |
Single | Gets the width of the left border of the element in pixels. |
public get; ClientTop |
Single | Gets the width of the top border of the element in pixels. |
public get; ClientWidth |
Single | Gets the inner width of the element in pixels, including padding but excluding borders, margins, and vertical scrollbars. |
public get; OffsetHeight |
Single | Gets the height of the element in pixels, including vertical padding, borders, and scrollbars. |
public get; OffsetLeft |
Single | Gets the distance in pixels from the outer left edge of this element to the inner left edge of its RmlElement.OffsetParent. |
public get; OffsetTop |
Single | Gets the distance in pixels from the outer top edge of this element to the inner top edge of its RmlElement.OffsetParent. |
public get; OffsetWidth |
Single | Gets the width of the element in pixels, including horizontal padding, borders, and scrollbars. |
public get; OffsetParent |
RmlElement | Gets the nearest ancestor element that has a position other than static, or |
Methods
public Boolean HasAttribute(String name)
Summary:
Checks whether the element has an attribute with the given name.
Corresponds to JavaScript
Parameters:
name(String): The name of the attribute to look for.
Returns:
- Boolean:
if the attribute exists; otherwise, .
public RmlVariant GetAttribute(String name)
Summary:
Retrieves the value of an attribute by its exact case-insensitive name.
Corresponds to JavaScript
Parameters:
name(String): The attribute name (e.g.,"data-id" ,"href" ).
Returns:
- RmlVariant: An RmlVariant holding the attribute value. If the attribute does not exist, returns a variant with type RmlVariantType.None.
public Void SetAttribute(String name, RmlVariant value)
Summary:
Sets the value of an attribute on the specified element.
Corresponds to JavaScript
Parameters:
-
name(String): The attribute name. -
value(RmlVariant): The attribute value as an RmlVariant.
public Void RemoveAttribute(String name)
Summary:
Removes the attribute with the specified name from the element.
Corresponds to JavaScript
Parameters:
name(String): The name of the attribute to remove.
public Void Blur()
Summary: Removes input focus from this element.
public Boolean Focus(Boolean focusVisible)
Summary: Sets input focus to this element.
Parameters:
focusVisible(Boolean): If, forces visible focus indicators (such as focus outlines) to appear.
Returns:
- Boolean: True if the change focus request was successful
public Void Click()
Summary: Simulates a mouse click on this element, triggering click events and default actions.
public RmlElement? Closest(String selector)
Summary: Traverses this element and its ancestors up toward the document root, returning the first element that matches the specified RCSS selector.
Parameters:
selector(String): The RCSS selector query string.
Returns:
- RmlElement?: The closest matching ancestor RmlElement, or
if none matched.
public Void DispatchEvent(String type, IReadOnlyDictionary<String?, RmlVariant?>? parameters)
Summary: Dispatches a synthetic event to this node in the DOM tree.
Parameters:
-
type(String): The name of the event type to dispatch. -
parameters(IReadOnlyDictionary<String?, RmlVariant?>?): A dictionary of event parameters to pass, or null if no parameters
public Void DispatchEvent(RmlEventId type, IReadOnlyDictionary<String?, RmlVariant?>? parameters)
Summary: Dispatches a synthetic event to this node in the DOM tree.
Parameters:
-
type(RmlEventId): The strongly typed event ID to dispatch. -
parameters(IReadOnlyDictionary<String?, RmlVariant?>?): A dictionary of event parameters to pass, or null if no parameters
public Void AddEventListener(String type, RmlEventListener listener, Boolean useCapture)
Summary: Registers an event handler for a specific event type on this element by name.
Parameters:
-
type(String): The name of the event type (e.g.,"click" ,"keydown" ). -
listener(RmlEventListener): The delegate function to invoke when the event is triggered. -
useCapture(Boolean): If, the listener is added to the capture phase; otherwise, it is added to the bubble/target phase.
public Void AddEventListener(RmlEventId type, RmlEventListener listener, Boolean useCapture)
Summary: Registers an event handler for a specific event type on this element using an RmlEventId.
Parameters:
-
type(RmlEventId): The strongly typed event ID. -
listener(RmlEventListener): The delegate function to invoke when the event is triggered. -
useCapture(Boolean): If, the listener is added to the capture phase; otherwise, it is added to the bubble/target phase.
public Void RemoveEventListener(String type, RmlEventListener listener, Boolean useCapture)
Summary: Removes a previously registered event listener by event type name.
Parameters:
-
type(String): The name of the event type. -
listener(RmlEventListener): The exact delegate instance that was registered. -
useCapture(Boolean): Specifies whether the listener being removed was registered as a capturing listener.
public Void RemoveEventListener(RmlEventId type, RmlEventListener listener, Boolean useCapture)
Summary: Removes a previously registered event listener by its strongly typed event ID.
Parameters:
-
type(RmlEventId): The strongly typed event ID. -
listener(RmlEventListener): The exact delegate instance that was registered. -
useCapture(Boolean): Specifies whether the listener being removed was registered as a capturing listener.
public Void AppendChild(RmlElement element)
Summary: Inserts a node as the last child node of this element. The newly parented node must first be detached from its existing parent before being appended.
Parameters:
element(RmlElement): The element to append as a child.
public RmlElement RemoveChild(RmlElement element)
Summary: Removes a child node from the current element.
Parameters:
element(RmlElement): The child node to be removed.
Returns:
- RmlElement: The removed RmlElement. Note: This instance now owns the native handle and will destroy it when disposed.
public RmlElement? GetElementById(String id)
Summary:
Returns the descendant element with the specified
Parameters:
id(String): The case-sensitive ID of the element to locate.
Returns:
- RmlElement?: The matching RmlElement, or
if not found.
public RmlElement[] GetElementsByClassName(String names)
Summary: Retrieves an array of all descendant elements with the specified class name(s).
Parameters:
names(String): One or more space-separated class names.
Returns:
- RmlElement[]: An array of matching RmlElement instances.
public RmlElement[] GetElementsByTagName(String name)
Summary: Retrieves an array of all descendant elements with the specified tag/element name.
Parameters:
name(String): The tag name to search for (e.g.,"div" ,"button" ).
Returns:
- RmlElement[]: An array of matching RmlElement instances.
public RmlElement? QuerySelector(String selectors)
Summary: Returns the first descendant element matching the specified RCSS selector string.
Parameters:
selectors(String): A valid RCSS selector query string.
Returns:
- RmlElement?: The first matching RmlElement, or
if no match is found.
public RmlElement[] QuerySelectorAll(String selectors)
Summary: Returns an array of all descendant elements matching the specified RCSS selector string.
Parameters:
selectors(String): A valid RCSS selector query string.
Returns:
- RmlElement[]: An array containing all matched RmlElement instances.
public virtual Boolean Equals(Object? obj)
Summary: Determines whether this instance and another specified object have the same underlying native handle.
Parameters:
obj(Object?): The object to compare with the current instance.
Returns:
- Boolean:
if objis an RmlElement with an identical native handle; otherwise,.
public virtual Int32 GetHashCode()
Summary: Serves as the default hash function, hashing the underlying native handle.
Returns:
- Int32: A hash code for the current element.
public virtual String ToString()
Summary: Returns a string representation of the element, including its ID, class name, and styles.
Returns:
- String: A formatted string with element metadata.
protected virtual Void Dispose(Boolean disposing)
Summary: Releases unmanaged resources and optionally managed resources.
Parameters:
disposing(Boolean):if called from RmlElement.Dispose; if called from the finaliser.
protected virtual Void Finalize()
Summary: Finalizer for RmlElement that ensures unmanaged handles are cleaned up if owned.
public Void Dispose()
Summary: Releases all resources used by the current instance of RmlElement.
Remarks:
Danger
Do NOT call this on an RmlDocument that is loaded by a context. The result is undefined behaviour