class GUIElement

Base class for all GUI elements.

Provides general functionality such as element size/position, as well as handling child/parent relationships.

Public

Constructors

GUIElement

GUIElement() = default

GUIElement

GUIElement(const GUISizeConstraints &sizeConstraints)

Methods

~GUIElement

virtual ~GUIElement() noexcept = default

SetPosition

void SetPosition(GUILogicalUnit x, GUILogicalUnit y)

Sets element position relative to parent GUI panel.

Values should be provided in logical pixel units.

Be aware that this value will be ignored if GUI element is part of a layout since then the layout controls its placement.

SetPosition

void SetPosition(const GUILogicalPoint &position)

Sets element position relative to parent GUI panel.

Values should be provided in logical pixel units.

Be aware that this value will be ignored if GUI element is part of a layout since then the layout controls its placement.

SetWidth

void SetWidth(GUILogicalUnit width)

Sets fixed element width.

Value should be in logical pixel units.

SetFlexibleWidth

void SetFlexibleWidth(GUILogicalUnit minWidth = 0, GUILogicalUnit maxWidth = 0)

Sets flexible element width.

Element will be resized according to its contents and parent layout but will always stay within the provided range. If maximum width is zero, the element is allowed to expand as much as it needs. Values should be in logical pixel units.

SetHeight

void SetHeight(GUILogicalUnit height)

Sets fixed element height.

Value should be in logical pixel units.

SetFlexibleHeight

void SetFlexibleHeight(GUILogicalUnit minHeight = 0, GUILogicalUnit maxHeight = 0)

Sets flexible element height.

Element will be resized according to its contents and parent layout but will always stay within the provided range. If maximum height is zero, the element is allowed to expand as much as it needs. Values provided should be in logical pixel units.

SetSize

void SetSize(const GUILogicalSize &size)

Sets fixed width and height of a GUI element.

Values provided should be in logical pixel units.

ResetSizeConstraints

virtual void ResetSizeConstraints()

Resets element size constraints to their initial values dictated by the element's style.

SetScale

void SetScale(float scale)

Sets the scale of the GUI element.

Note that scale will not affect the size of this GUI element, but will rather scale all of its contents.

SetHidden

void SetHidden(bool hidden)

Hides or shows this element and recursively applies the same state to all the child elements.

This will not remove the element from the layout, the room for it will still be reserved but it just won't be visible.

SetActive

void SetActive(bool active)

Activates or deactives this element and recursively applies the same state to all the child elements.

This has the same effect as setVisible(), but when disabled it will also remove the element from the layout, essentially having the same effect is if you destroyed the element.

SetDisabled

void SetDisabled(bool disabled)

Disables or enables the element.

Disabled elements cannot be interacted with and have a faded out appearance.

GetLayoutCalculatedSize

const GUILogicalSize &GetLayoutCalculatedSize() const

Returns width/height of the GUI element.

This will be the fixed width/height if set by the user, or automatically determined by the layout update pass if not fixed. Size is provided in logical pixel units.

Always returns value calculated by last layout update. This means out of date value may be returned if the layout has been dirtied since then.

CalculateSizeInLayout

GUILogicalSize CalculateSizeInLayout() const

Returns width/height of the GUI element.

This will be the fixed width/height if set by the user, or automatically determined by the layout update pass if not fixed. Size is provided in logical pixel units.

CalculatePositionRelativeTo

GUILogicalPoint CalculatePositionRelativeTo(GUIElement *relativeTo = nullptr) const

Calculates position of the GUI element, relative to the provided parent element (or parent panel if null).

The value is provided in logical pixel units.

relativeTo
Parent element of the provided element relative to which to return the position. If null the position relative to parent panel is returned. Behavior is undefined if provided parent is not a parent of the element.

CalculateAbsoluteBoundsRelativeTo

GUIPhysicalArea CalculateAbsoluteBoundsRelativeTo(GUIElement *relativeTo = nullptr)

Calculates bounds of the GUI element, relative to the provided parent element (or parent panel if null), with scaling applied.

The values are provided in physical pixel units.

relativeTo
Parent element of the provided element relative to which to return the bounds. If null the bounds relative to parent panel are returned. Behavior is undefined if provided parent is not a parent of the element.

CalculateAbsoluteBounds

GUIPhysicalArea CalculateAbsoluteBounds() const

Calculates bounds of the GUI element, relative to the parent GUI widget, with scaling applied.

The values are provided in physical pixel units.

CalculateScreenBounds

GUIPhysicalArea CalculateScreenBounds() const

Calculates bounds of the GUI element in screen space.

GetAbsoluteBounds

GUIPhysicalArea GetAbsoluteBounds() const

Returns bounds of the GUI element, relative to the parent GUI widget.

Absolute values represent the final position and size of the GUI element, affected by DPI scale, parent scale and self scale. The values are provided in physical pixel units.

Always returns value calculated by last layout update. This means out of date value may be returned if the layout has been dirtied since then.

WidgetToElementSpace

GUILogicalPoint WidgetToElementSpace(const GUIPhysicalPoint &point) const

Converts a point relative to the parent widget, into a point relative to this element.

ElementToWidgetSpace

GUIPhysicalPoint ElementToWidgetSpace(const GUILogicalPoint &point) const

Converts a point relative to this element, into a point relative to the parent widget.

WidgetToElementSpace

GUILogicalArea WidgetToElementSpace(const GUIPhysicalArea &area) const

Converts an area relative to the parent widget, into an area relative to this element.

ElementToWidgetSpace

GUIPhysicalArea ElementToWidgetSpace(const GUILogicalArea &area) const

Converts an area relative to this element, into an area relative to the parent widget.

GetAbsolutePosition

const GUIPhysicalPoint &GetAbsolutePosition() const

Returns the position of the GUI element, relative to the parent widget.

Absolute values represent the final position of the GUI element, affected by DPI scale and parent scale. The values are provided in physical pixel units.

Always returns value calculated by last layout update. This means out of date value may be returned if the layout has been dirtied since then.

GetAbsoluteScale

float GetAbsoluteScale() const

Combined local and parent scale.

Destroy

virtual void Destroy()

Destroy the element.

Removes it from parent and widget, and queues it for deletion. Element memory will be released delayed, next frame.

IsPendingDestroy

bool IsPendingDestroy() const

Checks if element is queued for deletion.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Internal

Methods

UpdateOptimalLayoutSizes

virtual void UpdateOptimalLayoutSizes()

Calculates optimal sizes of all child elements, as determined by their style and layout options.

This is performed recursively over all child elements, starting with the bottom-most child element. This should be called before UpdateLayoutRecursive().

UpdateLayout

virtual void UpdateLayout()

Calculates element positions and sizes based on their options and layout.

This is an expensive operation that requires multiple passes over all child GUI elements. The operation is performed in three passes:

  1. Optimal sizes for all elements are determined. This is done for the bottom-most child first, and then for parent elements.
  2. Layout calculations are performed for all elements, starting with the top-most element. This determines relative positions and final element size.
  3. Absolute coordinate calculations are performed for all elements, starting with the top-most element. This adds parent coordinates to the element's local coordinates, and calculates the visible area of the element (area of the element as clipped by the parent, e.g. for elements in a scroll area that might not be fully visible).

UpdateLayoutForChildren

virtual void UpdateLayoutForChildren()

Calculates sizes and relative positions for all child elements.

Should be preceded with a call to UpdateOptimalLayoutSizes().

UpdateLayoutIfDirty

void UpdateLayoutIfDirty()

Triggers a layout update immediately if the layout has been dirtied.

UpdateAbsoluteCoordinates

virtual void UpdateAbsoluteCoordinates(const GUIPhysicalPointF &parentOrigin, float parentScale, const GUIPhysicalAreaF &parentVisibleArea)

Updates the absolute coordinates of the GUI element using the currently assigned relative coordinates and the provided .

Also calculates the visible area clip rectangle and marks culled elements if they have no visible area. This should be called after updating the layout (as layout update calculates the needed relative coordinates). This may also be called independently of layout update, which is useful for scroll areas that then do not require a full layout pass to scroll their children.

parentOrigin
Absolute origin to add to the relative coordinates, in order to determine the absolute element coordinates.
parentScale
Scale of the parent GUI element.
parentVisibleArea
Absolute visible (clipped) area though which this element may be seen. This will be used for culling and clipping.

UpdateAbsoluteCoordinatesForChildren

virtual void UpdateAbsoluteCoordinatesForChildren()

Calls UpdateAbsoluteCoordinates() on all child elements.

SetLayoutData

virtual void SetLayoutData(const GUILayoutData &data)

Updates layout data that determines GUI elements relative position, size and depth in the GUI widget.

GetLayoutData

const GUILayoutData &GetLayoutData() const

Retrieves layout data that determines GUI elements relative position, size and depth in the GUI widget.

SetParent

void SetParent(GUIElement *parent)

Sets a new parent for this element.

GetChildCount

u32 GetChildCount() const

Returns number of child elements.

GetChild

GUIElement *GetChild(u32 index) const

Return the child element at the specified index.

GetVisibleChildren

virtual const TInlineArray<GUIElement *, 4> &GetVisibleChildren() const

Returns all children that can be seen through the parent's visible area (i.e. all elements that are not culled or explicitly made invisible).

Note this may return all child elements on GUI elements that do not support culling. Only well defined after layout update.

CalculateUnconstrainedOptimalSize

virtual GUILogicalSize CalculateUnconstrainedOptimalSize() const = 0

Calculates the optimal size for the GUI element, ignoring size constraints.

CalculateConstrainedOptimalSize

GUILogicalSize CalculateConstrainedOptimalSize() const

Returns the result of CalculateUnconstrainedOptimalSize() with size constrains applied.

GetSizeConstraints

const GUISizeConstraints &GetSizeConstraints() const

Returns size constraints that determine how is the GUI element allowed to be resized by the layout.

CalculateConstrainedSizeRange

virtual GUIConstrainedSizeRange CalculateConstrainedSizeRange() const

Calculates element size based on its optimal size constrained by its size constraint options.

GetConstrainedSizeRange

virtual GUIConstrainedSizeRange GetConstrainedSizeRange() const

Returns element size constrained by its size constraints.

This is different from CalculateConstrainedSize() because this method may return cached size.

GetMargins

virtual const RectOffset &GetMargins() const

Returns GUI element margins.

Margins are modified by changing element style and determines minimum distance between GUI element border and surrounding GUI elements.

GetPadding

virtual const RectOffset &GetPadding() const

Returns GUI element padding.

Padding is modified by changing element style and determines minimum distance between GUI element border and contents.

GetParent

GUIElement *GetParent() const

Returns parent GUI base element.

GetParentWidget

GUIWidget *GetParentWidget() const

Returns parent GUI widget, can be null.

IsHidden

bool IsHidden() const

Checks if element is explicitly hidden.

IsActive

bool IsActive() const

Checks if element is active or inactive.

Inactive elements are not visible, don't take up space in their parent layouts, and can't be interacted with.

IsDisabled

bool IsDisabled() const

Checks if element is disabled.

Disabled elements cannot be interacted with and have a faded out appearance.

IsCulled

bool IsCulled() const

Returns true if the element is not visible due to being culled by its parent bounds.

IsHiddenOrCulled

bool IsHiddenOrCulled() const

Checks if element is invisible.

Either due to explicitly being hidden or due to being culled by the parent.

SetHiddenRecursive

void SetHiddenRecursive(bool hidden)

Internal version of SetHidden() that doesn't modify local visibility, instead it is only meant to be called on child elements of the element whose visibility was modified.

SetActiveRecursive

void SetActiveRecursive(bool active)

Internal version of SetActive() that doesn't modify local state, instead it is only meant to be called on child elements of the element whose state was modified. @copydoc SetActive

SetDisabledRecursive

void SetDisabledRecursive(bool disabled)

Internal version of SetDisabled() that doesn't modify local state, instead it is only meant to be called on child elements of the element whose state was modified. @copydoc SetDisabled

SetCulled

void SetCulled(bool culled)

Marks the object and all children as culled.

ChangeParentWidget

virtual void ChangeParentWidget(GUIWidget *widget)

Changes the active GUI element widget.

This allows you to move an element to a different viewport, or change element style by using a widget with a different skin. You are allowed to pass null here, but elements with no parent will be unmanaged. You will be responsible for deleting them manually, and they will not render anywhere.

RegisterChildElement

virtual void RegisterChildElement(GUIElement *element)

Registers a new child element.

UnregisterChildElement

virtual void UnregisterChildElement(GUIElement *element)

Unregisters an existing child element.

MarkLayoutAsDirty

void MarkLayoutAsDirty()

Marks the element's dimensions as dirty, triggering a layout rebuild.

MarkAbsoluteCoordinatesAsDirty

void MarkAbsoluteCoordinatesAsDirty()

Marks the element's absolute coordinates as dirty.

This is usually true when the parent moves but relative positions/sizes of children remain unchanged. Or when area through which children are seen changes. Both cases are common for scroll areas.

MarkContentAsDirty

void MarkContentAsDirty()

Marks the element's contents as dirty, which causes the sprite meshes to be recreated from scratch.

MarkMeshAsDirty

void MarkMeshAsDirty()

Mark only the elements that operate directly on the sprite mesh without requiring the mesh to be recreated as dirty.

This includes position, depth and clip rectangle. This will cause the parent widget mesh to be rebuilt from its child element's meshes.

IsLayoutDirty

bool IsLayoutDirty() const

Returns true if the element requires layout update (e.g. if its optimal size has changed).

AreAbsoluteCoordinatesDirty

bool AreAbsoluteCoordinatesDirty() const

Returns true if absolute coordinates of child elements need to be updated (e.g. element is a scroll area and it has been scrolled).

MarkAsClean

void MarkAsClean()

Marks the element contents to be up to date (meaning it's processed by the GUI system).

SetQuadTreeId

void SetQuadTreeId(const SpatialTreeElementId &id)

ID of the element in a quad-tree managed by its direct parent.

Quad-tree can be used for speeding up lookup for elements containing many children.

GetQuadTreeId

const SpatialTreeElementId &GetQuadTreeId() const

GetAbsoluteClippedArea

const GUIPhysicalArea &GetAbsoluteClippedArea() const

Returns the position and size of the GUI element, relative to the parent widget.

The returned area is clipped by the visible area as specified by the parent GUI element (e.g. if the parent is a scroll area or similar, only some or none of the GUI element may be visible, if it's scrolled out of view). Provided value is in physical pixel units.

Always returns value calculated by last layout update. This means out of date value may be returned if the layout has been dirtied since then.

GetIntermediateAbsolutePosition

const GUIPhysicalPointF &GetIntermediateAbsolutePosition() const

Similar to GetAbsolutePosition(), but contains floating point data that is not rounded, useful primarily for calculating child absolute coordinates without losing precision.

GetIntermediateAbsoluteClippedArea

const GUIPhysicalAreaF &GetIntermediateAbsoluteClippedArea() const

Similar to GetAbsoluteClippedArea(), but contains floating point data that is not rounded, useful primarily for calculating child absolute coordinates without losing precision.

GetClippedAreaTranslatedRelativeToParent

GUIPhysicalArea GetClippedAreaTranslatedRelativeToParent() const

Same as GetAbsoluteClippedArea(), except the area position is made relative to this GUI element.

Protected

Methods

UpdateAbsoluteCoordinatesWithExplicitContentSize

void UpdateAbsoluteCoordinatesWithExplicitContentSize(const GUIPhysicalPointF &parentOrigin, float parentScale, const GUIPhysicalAreaF &parentVisibleArea, const GUILogicalSize &contentSize)

Same as UpdateAbsoluteCoordinates, but allows the user to provide explicit size of this GUI element's contents.

This is useful for e.g. scroll areas where the content size may be larger than the layout calculated area used by default.

UpdatePanelAndLayoutUpdateParents

void UpdatePanelAndLayoutUpdateParents()

Finds anchor and update parents and recursively assigns them to all children.

RefreshLayoutUpdateParentsForChildren

void RefreshLayoutUpdateParentsForChildren()

Refreshes update parents of all child elements.

FindLayoutUpdateParent

GUIElement *FindLayoutUpdateParent()

Finds the first parent element whose size doesn't depend on child sizes.

SetPanelParent

void SetPanelParent(GUIPanel *panelParent)

Helper method for recursion in UpdatePanelAndLayoutUpdateParents().

Sets the provided anchor parent for all children recursively. Recursion stops when a child anchor is detected.

SetLayoutUpdateParent

void SetLayoutUpdateParent(GUIElement *layoutUpdateParent)

Helper method for recursion in UpdatePanelAndLayoutUpdateParents().

Sets the provided update parent for all children recursively. Recursion stops when a child update parent is detected.

DestroyChildElements

void DestroyChildElements()

Unregisters and destroys all child elements.

Fields

mParentWidget

GUIWidget * mParentWidget

mPanelParent

GUIPanel * mPanelParent

First panel in the parent hierarchy, if any.

mLayoutUpdateParent

GUIElement * mLayoutUpdateParent

Parent on which we need to call layout update if this element's size changes.

This will be the first parent GUI element that doesn't have fixed bounds.

mParent

GUIElement * mParent

Direct parent of this element.

mChildren

TInlineArray<GUIElement *, 4> mChildren

mFlags

GUIElementInternalStateFlags mFlags

mIsPendingDestroy

bool mIsPendingDestroy

mQuadTreeId

If the parent GUI element maintains a quad tree of its children, this will be ID of the element within the quad-tree.

mSizeConstraints

GUISizeConstraints mSizeConstraints

Constraints on the element size as set by the style sheet, or set explicitly at runtime.

mScale

float mScale

Scale to apply to the GUI element and all children.

mLayoutData

GUILayoutData mLayoutData

Relative position (to parent), size, depth and other information, calculated during a layout update.

mAbsolutePosition

GUIPhysicalPoint mAbsolutePosition

Absolute position of the GUI element (relative to parent GUI widget).

Only valid after layout update

& absolute coordinate update.

mAbsoluteSize

GUIPhysicalSize mAbsoluteSize

Final size to use for the element.

Same as GUILayoutData::Size, scaled by GUI element scale.

mAbsoluteScale

float mAbsoluteScale

Combined local and parent scale.

mAbsoluteClippedArea

GUIPhysicalArea mAbsoluteClippedArea

Absolute area of the GUI element as clipped by the parent visible bounds (e.g. if a parent is a scroll area).

Only valid after layout update

& absolute coordinate update.

mIntermediateAbsolutePosition

GUIPhysicalPointF mIntermediateAbsolutePosition

mIntermediateAbsoluteClippedArea

GUIPhysicalAreaF mIntermediateAbsoluteClippedArea