Skip to content

Class UiElement

Namespace: Apogee.UI
Assembly: Apogee.UI.dll

An element of a document (a div, a text node, a whole document) as scripts hold it. The object is a handle: it names the element without keeping it alive, so one whose element has been destroyed (its document was closed, an ancestor was destroyed) is false and every call on it does nothing or answers "none". An element made with or belongs to the object that holds it until it is put in a tree with or ; an element nobody ever put in a tree is destroyed when the script lets go of it, and one in a tree lives as long as the tree does. Elements are made, moved and changed here.

public sealed class UiElement : EngineObject

Inheritance

object ← EngineObject ← UiElement

Inherited Members

EngineObject.IsAdopted, EngineObject.Handle, EngineObject.IsDestroyed, EngineObject.Class, EngineObject.Adopt(), EngineObject.TryGet(SlotHandle, out EngineObject), EngineObject.Destroy(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Properties

ChildCount

The number of elements and text nodes directly inside.

public int ChildCount { get; }

Property Value

int

Class

What the registry knows about this object's class.

public override ClassInfo Class { get; }

Property Value

ClassInfo

ClassName

The classes, separated by spaces: what the style rules (.card) match.

public string ClassName { get; set; }

Property Value

string

Document

The document the element is in (a document is its own).

public UiElement? Document { get; }

Property Value

UiElement?

Id

The element's id (the id attribute; ids are unique in a document).

public string Id { get; set; }

Property Value

string

InnerRml

The RML of what is inside the element; setting it replaces the children.

public string InnerRml { get; set; }

Property Value

string

IsAlive

Whether the element still exists.

public bool IsAlive { get; }

Property Value

bool

IsVisible

Whether it can be seen: not display: none or visibility: hidden, itself or any element above it.

public bool IsVisible { get; }

Property Value

bool

Parent

The element it is in, or nothing for a document or an element in no tree.

public UiElement? Parent { get; }

Property Value

UiElement?

Tag

The tag (div, body), or empty for a dead element.

public string Tag { get; }

Property Value

string

Text

The text of a text node (made with ); empty for any other element.

public string Text { get; set; }

Property Value

string

Methods

AddStyle(string)

Adds style rules (RCSS) to the document this element is in, on top of its own.

public bool AddStyle(string rcss)

Parameters

rcss string

Returns

bool

Append(UiElement)

Puts child, made by or taken out by , last in this element, which owns it from then on. False if it is already in a tree.

public bool Append(UiElement child)

Parameters

child UiElement

Returns

bool

Blur()

public void Blur()

ById(string)

The element with this id in or below this one.

public UiElement? ById(string id)

Parameters

id string

Returns

UiElement?

Child(int)

public UiElement? Child(int index)

Parameters

index int

Returns

UiElement?

Click()

Clicks the element as if the pointer had.

public void Click()

Close()

Unloads the document: everything in it is destroyed. Call it on the document.

public void Close()

Closest(string)

The nearest element, this one included and going up, that a selector (.card, #menu, div.row) matches.

public UiElement? Closest(string selector)

Parameters

selector string

Returns

UiElement?

Contains(UiElement)

Whether other is this element or inside it.

public bool Contains(UiElement other)

Parameters

other UiElement

Returns

bool

CreateElement(string)

A new element with the tag (div, span, input...) in this element's document, in no tree yet.

public UiElement? CreateElement(string tag)

Parameters

tag string

Returns

UiElement?

CreateText(string)

A new text node in this element's document, in no tree yet.

public UiElement? CreateText(string text)

Parameters

text string

Returns

UiElement?

DestroyElement()

Destroys the element with everything inside it, out of its tree. Every object that names it is dead afterwards.

public void DestroyElement()

Focus()

public bool Focus()

Returns

bool

GetAttribute(string)

public string? GetAttribute(string name)

Parameters

name string

Returns

string?

HasAttribute(string)

public bool HasAttribute(string name)

Parameters

name string

Returns

bool

HasPseudoClass(string)

public bool HasPseudoClass(string name)

Parameters

name string

Returns

bool

Hide()

public void Hide()

InsertBefore(UiElement, UiElement?)

The same, before before, a child of this element (or last, when it is nothing).

public bool InsertBefore(UiElement child, UiElement? before = null)

Parameters

child UiElement

before UiElement?

Returns

bool

Listen(string, ScriptFunction, bool)

Calls handler with a whenever an event of this type (click, mousedown, keydown, change, focus...) reaches the element on its way up from what was hit, or, with capture, on its way down. Returns a number for . The listener goes when the element does.

public long Listen(string type, ScriptFunction handler, bool capture = false)

Parameters

type string

handler ScriptFunction

capture bool

Returns

long

OnDestroyed()

protected override void OnDestroyed()

Rect()

The element's border box on the screen in pixels, as the last update laid it out: x, y, width, height.

public (float X, float Y, float Width, float Height) Rect()

Returns

(float X, float Y, float Width, float Height)

Remove(UiElement)

Takes a child out of this element. It is the script's again: put it somewhere else, or let go of it to destroy it.

public bool Remove(UiElement child)

Parameters

child UiElement

Returns

bool

RemoveAttribute(string)

public void RemoveAttribute(string name)

Parameters

name string

RemoveProperty(string)

public void RemoveProperty(string name)

Parameters

name string

ScrollIntoView(bool)

public void ScrollIntoView(bool alignWithTop = true)

Parameters

alignWithTop bool

SetAttribute(string, string)

public void SetAttribute(string name, string value)

Parameters

name string

value string

SetProperty(string, string)

Sets an inline style (set_property("width", "120px")); false when the name or the value is not valid RCSS.

public bool SetProperty(string name, string value)

Parameters

name string

value string

Returns

bool

SetPseudoClass(string, bool)

public void SetPseudoClass(string name, bool on)

Parameters

name string

on bool

Show()

Makes the document visible (and it starts to be drawn and to take input).

public void Show()

Unlisten(long)

Takes back a listener of this element (the number returned); the same as .

public bool Unlisten(long token)

Parameters

token long

Returns

bool