Component - LiruJ/GuiCookie GitHub Wiki

Overview

An element may have multiple components to determine its behaviour. Components ensure that the design of elements is as modular as possible, and that behaviours can be reused across many elements.

Any class that extends Component 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 Components to see all default components available in GuiCookie.

Properties

Element

Element

The element that contains the component.

Bounds

Bounds

The bounds of the containing element.

Root

Root

The root layout that the element is part of.

StyleState

StyleStateMachine

The StyleStateMachine of the element.

Style

Style

The current style of the element.

CurrentStyleVariant

StyleVariant

The current style variant of the element.

Initialisation Functions

OnCreated()

public, virtual, void

Called after the component has been added to an element.

The element itself will not be done setting up, and its children are therefore very likely to be null, although other components will exist and can be safely saved.

OnSetup()

public, virtual, void

Called after the component's element has been fully set up.

The element's children will all exist when this function is called and can be safely saved.

OnPostSetup()

public, virtual, void

Called after OnSetup().

This can be used to access components after they have set themselves up.

Event Functions

OnSizeChanged()

protected, virtual, void

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

ValidateSizeChanged()

public, virtual, bool

Is called immediately before OnSizeChanged() and allows the component to refuse a size change.

If this function returns false, it should also set the size of the bounds to what it believes is valid.

if it is to return true, no changes are needed.

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.

Update Functions

Update(GameTime)

public, virtual, void

Called every update cycle, even if the element is disabled.

Draw Functions

Draw(IGuiCamera)

public, virtual, void

Called once per frame, as long as the element is visible.

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