Element - LiruJ/GuiCookie GitHub Wiki

Overview

A controller is a base behaviour for an element and, as the name implies, acts as a controller to bring the behaviour of an element's components together.

The Element class is the default controller for every element within GuiCookie. If a controller is not specified for an element, this class will be used.

Any class that extends Element can add the following as arguments to its constructor and GuiCookie will handle finding the relevant object:

  • GraphicsDevice
  • ContentManager
  • GameWindow
  • InputManager
  • DragAndDropManager
  • TemplateManager
  • ResourceManager
  • StyleManager
  • ComponentManager
  • ElementManager
  • Anything passed into the UIManager's CreateUIRoot function when the layout was created
  • Anything passed into the ElementManager's CreateElement functions when the element was created

See the List of Default Controllers to see all default controllers available in GuiCookie.

This class is quite large, so this page is still a work in progress.

Properties

StyleState, Style, CurrentStyleVariant

InitialisationState

Template, Attributes

Name, HasName

Tag, HasTag

Root

Bounds

Parent

BlocksMouse

Enabled, Visible, EnabledAndVisible

ChildCount, HasChildren

Signals

OnChildAdded<Element>

OnChildRemoved<Element>

OnEnabled

OnDisabled

Initialisation Functions

OnCreated()

public, virtual, void

This is called immediately after the element was created and Component.OnCreated() has been called for each component.

Child elements will not exist at this point, although all attributes will be available and all components will at the very least exist.

OnFullSetup()

public, virtual, void

This is called after OnCreated(), meaning that the children of the element will at least exist and will have called OnCreated(). This is mostly useful for getting access to child elements, although none of them would have called OnFullSetup() yet, so may not have fully set up.

OnPostFullSetup()

public, virtual, void

This is called immediately after OnFullSetup(), meaning that every child of the element should be more or less set up. This is useful if a child's child is needed.

Event Functions

OnPositionChanged()

protected, virtual, void

OnSizeChanged()

protected, virtual, void

Is called immediately after the element's size was changed.

OnStyleChanged()

public, virtual, void

Is called when the element's StyleStateMachine's Style was changed.

OnDestroyed()

protected, virtual, void

Is called immediately before the element is removed from the layout.

Note that it is incredibly important to set any references to the element to null so that C#'s garbage collector can clean it up. The element will be removed from the layout, but cannot unset itself anywhere else.

Child Functions

ContainsChild(Element)

public, bool

Returns true if the element contains the given element; otherwise false.

GetChild<T>()

public, T

Returns the first child element that is of the given type T, or null if no such child exists.

GetInterfacedChild<T>()

public, T

Returns the first child element that implements the given type T, or null if no such child exists or the given type is not an interface.

TryGetInterfacedChild<T>(out T)

public, bool

Finds the first child element that implements the given type T and sets the out parameter to it. Returns true if the element was found; otherwise false.

GetChildByName(string, bool)

public, Element

Finds and returns the child element with the given name. If the given boolean value is true, then each child element will be recursively searched for an element with the given name. If no child exists with the given name, null is returned.

If the given name is null or empty, an ArgumentException will be thrown.

This function searches recursively breadth-first.

GetChildByName<T>(string, bool)

public, T

Calls the GetChildByName function, but casts the result to the given type T before returning.

GetInterfacedChildByName<T>(string, bool)

public, T

Calls the GetChildByName function and casts the result to the given T. Returns null if no child was found, or the given T was not an interface.

TryGetInterfacedChildByName<T>(string, out T, bool)

public, bool

Finds the first child element with the given name that implements the given type T and sets the out parameter to it. Returns true if the element was found; otherwise false.

GetChildByIndex(int)

public, Element

Finds and returns the child at the given index. This will throw an IndexOutOfRangeException if the index is out of range.

GetChildByIndex<T>(int)

public, T

Calls the GetChildByIndex(int) function and returns the result cast to the given type T.

AddChild(Element)

public, bool

Adds the given element as a child, returning true if the addition was a success; otherwise false.

Note that for performance reasons, there are no checks to ensure validity of the element hierarchy as a whole. This means that it is possible to add an element as a child of one of its grandchildren. Care should be taken to ensure this does not happen.

RemoveChild(Element)

public, bool

Removes the given element from a child, returning true if the removal was a success; otherwise false.

Collection Functions

Destroy()

public, void

GetEnumerator()

public, IEnumerator<Element>

Component Functions

GetComponent<T>()

public, T

TryGetComponent<T>(out T)

public, bool

GetInterfacedComponent<T>()

public, T

TryGetInterfacedComponent<T>(out T)

public, bool

UpdateComponents(GameTime)

protected, void

Update Functions

Update(GameTime)

public, void

LateUpdate(GameTime)

public, void

Draw Functions

Draw(IGuiCamera)

public, void

⚠️ **GitHub.com Fallback** ⚠️