Open 3D Engine LyShine Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
UiCanvasInterface Class Referenceabstract

Inherits AZ::ComponentBus.

Public Member Functions

virtual ~UiCanvasInterface ()
 Deleting a canvas will delete all its child elements recursively and all of their components.
 
virtual const AZStd::string & GetPathname ()=0
 Get the asset ID path name of this canvas. If not loaded or saved yet this will be "".
 
virtual LyShine::CanvasId GetCanvasId ()=0
 Get the ID of this canvas. This will remain the same while this canvas is loaded.
 
virtual AZ::u64 GetUniqueCanvasId ()=0
 Get the unique ID of this canvas.
 
virtual int GetDrawOrder ()=0
 Get the draw order of this canvas. Rendering is back-to-front, so higher numbers render in front of lower numbers.
 
virtual void SetDrawOrder (int drawOrder)=0
 Set the draw order of this canvas. Rendering is back-to-front, so higher numbers render in front of lower numbers.
 
virtual bool GetKeepLoadedOnLevelUnload ()=0
 Get the flag indicating if this canvas will stay loaded through a level unload.
 
virtual void SetKeepLoadedOnLevelUnload (bool keepLoaded)=0
 Set the flag indicating if this canvas will stay loaded through a level unload.
 
virtual void RecomputeChangedLayouts ()=0
 
virtual int GetNumChildElements ()=0
 Get the number child elements of this canvas.
 
virtual AZ::Entity * GetChildElement (int index)=0
 Get the specified child element, index must be less than GetNumChildElements()
 
virtual AZ::EntityId GetChildElementEntityId (int index)=0
 Get the specified child entity Id, index must be less than GetNumChildElements()
 
virtual LyShine::EntityArray GetChildElements ()=0
 Get the child elements of this canvas.
 
virtual AZStd::vector< AZ::EntityId > GetChildElementEntityIds ()=0
 Get the child entity Ids of this canvas.
 
virtual AZ::Entity * CreateChildElement (const LyShine::NameType &name)=0
 Create a new element that is a child of the canvas, the canvas has ownership of the child.
 
virtual AZ::Entity * FindElementById (LyShine::ElementId id)=0
 Return the element on this canvas with the given id or nullptr if no match.
 
virtual AZ::Entity * FindElementByName (const LyShine::NameType &name)=0
 Return the first element on this canvas with the given name or nullptr if no match.
 
virtual AZ::EntityId FindElementEntityIdByName (const LyShine::NameType &name)=0
 Return the first element on this canvas with the given name or nullptr if no match.
 
virtual void FindElementsByName (const LyShine::NameType &name, LyShine::EntityArray &result)=0
 Find all elements on this canvas with the given name.
 
virtual AZ::Entity * FindElementByHierarchicalName (const LyShine::NameType &name)=0
 
virtual void FindElements (AZStd::function< bool(const AZ::Entity *)> predicate, LyShine::EntityArray &result)=0
 Find all elements on this canvas matching the predicate.
 
virtual AZ::Entity * PickElement (AZ::Vector2 point)=0
 
virtual LyShine::EntityArray PickElements (const AZ::Vector2 &bound0, const AZ::Vector2 &bound1)=0
 
virtual AZ::EntityId FindInteractableToHandleEvent (AZ::Vector2 point)=0
 Look for an entity with interactable component to handle an event at given point.
 
virtual bool SaveToXml (const AZStd::string &assetIdPathname, const AZStd::string &sourceAssetPathname)=0
 
virtual void FixupCreatedEntities (LyShine::EntityArray topLevelEntities, bool makeUniqueNamesAndIds, AZ::Entity *optionalInsertionPoint)=0
 
virtual void AddElement (AZ::Entity *element, AZ::Entity *parent, AZ::Entity *insertBefore)=0
 
virtual void ReinitializeElements ()=0
 
virtual AZStd::string SaveToXmlString ()=0
 
virtual AZStd::string GetUniqueChildName (AZ::EntityId parentEntityId, AZStd::string baseName, const LyShine::EntityArray *includeChildren)=0
 
virtual AZ::Entity * CloneElement (AZ::Entity *sourceEntity, AZ::Entity *parentEntity)=0
 
virtual AZ::EntityId CloneElementEntityId (AZ::EntityId sourceEntity, AZ::EntityId parentEntity, AZ::EntityId insertBefore)=0
 
virtual AZ::Entity * CloneCanvas (const AZ::Vector2 &canvasSize)=0
 
virtual void SetCanvasToViewportMatrix (const AZ::Matrix4x4 &matrix)=0
 Set the transformation from canvas space to viewport space.
 
virtual const AZ::Matrix4x4 & GetCanvasToViewportMatrix ()=0
 Get the transformation from canvas space to viewport space.
 
virtual void GetViewportToCanvasMatrix (AZ::Matrix4x4 &matrix)=0
 Get the transformation from viewport space to canvas space.
 
virtual AZ::Vector2 GetCanvasSize ()=0
 Returns the "target" size of the canvas (in pixels)
 
virtual void SetCanvasSize (const AZ::Vector2 &canvasSize)=0
 Set the authored size of the canvas (in pixels)
 
virtual void SetTargetCanvasSize (bool isInGame, const AZ::Vector2 &targetCanvasSize)=0
 
virtual AZ::Vector2 GetDeviceScale ()=0
 
virtual bool GetIsPixelAligned ()=0
 Get flag that indicates whether visual element's vertices should snap to the nearest pixel.
 
virtual void SetIsPixelAligned (bool isPixelAligned)=0
 Set flag that indicates whether visual element's vertices should snap to the nearest pixel.
 
virtual bool GetIsTextPixelAligned ()=0
 Get flag that indicates whether text should snap to the nearest pixel.
 
virtual void SetIsTextPixelAligned (bool isTextPixelAligned)=0
 Set flag that indicates whether text should snap to the nearest pixel.
 
virtual IUiAnimationSystemGetAnimationSystem ()=0
 Get the animation system for this canvas.
 
virtual bool GetEnabled ()=0
 Get flag that governs whether the canvas is enabled.
 
virtual void SetEnabled (bool enabled)=0
 Set flag that governs whether the canvas is enabled.
 
virtual bool GetIsRenderToTexture ()=0
 Get flag that controls whether the canvas is rendering to a texture.
 
virtual void SetIsRenderToTexture (bool isRenderToTexture)=0
 Set flag that controls whether the canvas is rendering to a texture.
 
virtual const AZ::Data::Asset< AZ::RPI::AttachmentImageAsset > & GetAttachmentImageAsset ()=0
 Get the attachment image that this canvas will render to.
 
virtual void SetAttachmentImageAsset (const AZ::Data::Asset< AZ::RPI::AttachmentImageAsset > &attachmentImageAsset)=0
 Set the attachment image that this canvas will render to.
 
virtual bool GetIsPositionalInputSupported ()=0
 Get flag that controls whether this canvas automatically handles positional input (mouse/touch)
 
virtual void SetIsPositionalInputSupported (bool isSupported)=0
 Set flag that controls whether this canvas automatically handles positional input (mouse/touch)
 
virtual bool GetIsConsumingAllInputEvents ()=0
 Get flag that controls whether this canvas consumes all input events while it is enabled.
 
virtual void SetIsConsumingAllInputEvents (bool isConsuming)=0
 Set flag that controls whether this canvas consumes all input events while it is enabled.
 
virtual bool GetIsMultiTouchSupported ()=0
 Get flag that controls whether this canvas automatically handles multi-touch input.
 
virtual void SetIsMultiTouchSupported (bool isSupported)=0
 Set flag that controls whether this canvas automatically handles multi-touch input.
 
virtual bool GetIsNavigationSupported ()=0
 Get flag that controls whether this canvas automatically handles navigation input (via keyboard/gamepad)
 
virtual void SetIsNavigationSupported (bool isSupported)=0
 Set flag that controls whether this canvas automatically handles navigation input (via keyboard/gamepad)
 
virtual float GetNavigationThreshold ()=0
 Get the analog (eg. thumb-stick) input value that must be exceeded before a navigation command will be processed.
 
virtual void SetNavigationThreshold (float navigationThreshold)=0
 Set the analog (eg. thumb-stick) input value that must be exceeded before a navigation command will be processed.
 
virtual AZ::u64 GetNavigationRepeatDelay ()=0
 Get the delay (milliseconds) before a held navigation command will begin repeating.
 
virtual void SetNavigationRepeatDelay (AZ::u64 navigationRepeatDelay)=0
 Set the delay (milliseconds) before a held navigation command will begin repeating.
 
virtual AZ::u64 GetNavigationRepeatPeriod ()=0
 Get the delay (milliseconds) before a held navigation command will continue repeating.
 
virtual void SetNavigationRepeatPeriod (AZ::u64 navigationRepeatPeriod)=0
 Set the delay (milliseconds) before a held navigation command will continue repeating.
 
virtual AzFramework::LocalUserId GetLocalUserIdInputFilter ()=0
 Get the local user id that is being used to filter incoming input events.
 
virtual void SetLocalUserIdInputFilter (AzFramework::LocalUserId localUserId)=0
 Set the local user id that will be used to filter incoming input events.
 
virtual bool HandleInputEvent (const AzFramework::InputChannel::Snapshot &inputSnapshot, const AZ::Vector2 *viewportPos=nullptr, AzFramework::ModifierKeyMask activeModifierKeys=AzFramework::ModifierKeyMask::None)=0
 Handle an input event for the canvas.
 
virtual bool HandleTextEvent (const AZStd::string &textUTF8)=0
 Handle a unicode text event for the canvas.
 
virtual bool HandleInputPositionalEvent (const AzFramework::InputChannel::Snapshot &inputSnapshot, AZ::Vector2 viewportPos)=0
 
virtual AZ::Vector2 GetMousePosition ()=0
 Get the mouse position of the last input event.
 
virtual AZ::EntityId GetTooltipDisplayElement ()=0
 Get the element to be displayed when hovering over an interactable.
 
virtual void SetTooltipDisplayElement (AZ::EntityId entityId)=0
 Set the element to be displayed when hovering over an interactable.
 
virtual void ForceFocusInteractable (AZ::EntityId interactableId)=0
 
virtual void ForceActiveInteractable (AZ::EntityId interactableId, bool shouldStayActive, AZ::Vector2 point)=0
 
virtual AZ::EntityId GetHoverInteractable ()=0
 Get the hover interactable.
 
virtual void ForceHoverInteractable (AZ::EntityId interactableId)=0
 
virtual void ClearAllInteractables ()=0
 
virtual void ForceEnterInputEventOnInteractable (AZ::EntityId interactableId)=0
 

Static Public Attributes

static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single
 Only one component on an entity can implement the events.
 

Member Function Documentation

◆ AddElement()

virtual void UiCanvasInterface::AddElement ( AZ::Entity *  element,
AZ::Entity *  parent,
AZ::Entity *  insertBefore 
)
pure virtual

Add an existing entity to the canvas (only for internal use from editor)

Parameters
elementThe newly created element to add to the canvas
parentThe parent element for the created element, if nullptr the root element is the parent
insertBeforeThe sibling element to place this element before, if nullptr then add as last child

◆ ClearAllInteractables()

virtual void UiCanvasInterface::ClearAllInteractables ( )
pure virtual

Clear all active interactables, and all hover interactables if last input was positional (mouse/touch). This is intended for internal use by UI components

◆ CloneCanvas()

virtual AZ::Entity * UiCanvasInterface::CloneCanvas ( const AZ::Vector2 &  canvasSize)
pure virtual

Create a clone of this canvas entity

Parameters
canvasSizeThe resolution to display the canvas at

◆ CloneElement()

virtual AZ::Entity * UiCanvasInterface::CloneElement ( AZ::Entity *  sourceEntity,
AZ::Entity *  parentEntity 
)
pure virtual

Clone an element and add it to this canvas as a child of the given parent element The entity and all its components/children are cloned and new IDs are generated NOTE: Only state that is persistent/reflected is cloned

Parameters
sourceEntityThe entity to clone
parentEntityThe parent element for the created elements, if nullptr the root element is the parent
Returns
The new entity

◆ CloneElementEntityId()

virtual AZ::EntityId UiCanvasInterface::CloneElementEntityId ( AZ::EntityId  sourceEntity,
AZ::EntityId  parentEntity,
AZ::EntityId  insertBefore 
)
pure virtual

Clone an element and add it to this canvas as a child of the given parent element The entity and all its components/children are cloned and new IDs are generated NOTE: Only state that is persistent/reflected is cloned

Parameters
sourceEntityThe entity to clone (may be from a different canvas)
parentEntityThe parent element for the created elements, if invalid the root element is the parent
insertBeforeThe child of the parent element that the new element should be inserted before, if invalid the new element is the last child element
Returns
The new entity

◆ FindElementByHierarchicalName()

virtual AZ::Entity * UiCanvasInterface::FindElementByHierarchicalName ( const LyShine::NameType name)
pure virtual

Return the element with the given hierarchical name or nullptr if no match

Parameters
name,ahierarchical name relative to the root with '/' as the separator

◆ FixupCreatedEntities()

virtual void UiCanvasInterface::FixupCreatedEntities ( LyShine::EntityArray  topLevelEntities,
bool  makeUniqueNamesAndIds,
AZ::Entity *  optionalInsertionPoint 
)
pure virtual

Initialize a set of entities that have been added to the canvas Used when instantiating a slice or for undo/redo, copy/paste

Parameters
topLevelEntities- The elements that were created
makeUniqueNamesAndIdsIf false the entity names and ElementIds in the string are kept, else unique ones are generated
insertionPointThe parent element for the created elements, if nullptr the root element is the parent

◆ ForceActiveInteractable()

virtual void UiCanvasInterface::ForceActiveInteractable ( AZ::EntityId  interactableId,
bool  shouldStayActive,
AZ::Vector2  point 
)
pure virtual

Force the active interactable for the canvas to be the given one, also set last mouse pos to point, intended for internal use by UI components

◆ ForceEnterInputEventOnInteractable()

virtual void UiCanvasInterface::ForceEnterInputEventOnInteractable ( AZ::EntityId  interactableId)
pure virtual

Generate Enter pressed/released input events on an interactable. Useful for automated testing to simulate button clicks

◆ ForceFocusInteractable()

virtual void UiCanvasInterface::ForceFocusInteractable ( AZ::EntityId  interactableId)
pure virtual

Force the active interactable for the canvas to be the given one, also force AutoActivation of interactable, intended for internal use by UI components

◆ ForceHoverInteractable()

virtual void UiCanvasInterface::ForceHoverInteractable ( AZ::EntityId  interactableId)
pure virtual

Force the hover interactable for the canvas to be the given one, this can be useful when using keyboard/gamepad navigation and the current hover interactable is deleted by a script and the script wants to specify the new hover interactable

◆ GetCanvasSize()

virtual AZ::Vector2 UiCanvasInterface::GetCanvasSize ( )
pure virtual

Returns the "target" size of the canvas (in pixels)

The target canvas size changes depending on whether you're running in the UI Editor or in-game. While in-game, we assume that the canvas size fills the screen, so the target canvas size is the size of the viewport. When using the editor, however, the target size is the "authored" size of the canvas. The canvas is authored in one resolution, but it may be displayed by the game at whatever the game resolution is set to.

◆ GetDeviceScale()

virtual AZ::Vector2 UiCanvasInterface::GetDeviceScale ( )
pure virtual

Get scale to adjust for the difference between canvas size (authored size) and the viewport size (target canvas size) when running on current device

◆ GetEnabled()

virtual bool UiCanvasInterface::GetEnabled ( )
pure virtual

Get flag that governs whether the canvas is enabled.

A canvas that's enabled will be updated and rendered each frame.

◆ GetUniqueChildName()

virtual AZStd::string UiCanvasInterface::GetUniqueChildName ( AZ::EntityId  parentEntityId,
AZStd::string  baseName,
const LyShine::EntityArray includeChildren 
)
pure virtual

Get an element name that is unique to the children of the specified parent and to an optional array of elements

Parameters
parentEntityIdThe entityId of the parent who's children's names must not match the returned name
baseNameThe name to append a unique identifier to
includedChildrenAn array of any other elements who's names must not match the returned name
Returns
Unique name that does not match the specified parent's children or the optional array of children

◆ HandleInputPositionalEvent()

virtual bool UiCanvasInterface::HandleInputPositionalEvent ( const AzFramework::InputChannel::Snapshot &  inputSnapshot,
AZ::Vector2  viewportPos 
)
pure virtual

Handle a positional input event for the canvas, this could come from a ray cast intersection for example

◆ PickElement()

virtual AZ::Entity * UiCanvasInterface::PickElement ( AZ::Vector2  point)
pure virtual

Get the front-most element whose bounds include the given point in canvas space

Returns
nullptr if no match

◆ PickElements()

virtual LyShine::EntityArray UiCanvasInterface::PickElements ( const AZ::Vector2 &  bound0,
const AZ::Vector2 &  bound1 
)
pure virtual

Get all element whose bounds intersect with the given box in canvas space

Returns
empty EntityArray if no match

◆ RecomputeChangedLayouts()

virtual void UiCanvasInterface::RecomputeChangedLayouts ( )
pure virtual

Force a layout recompute. Layouts marked for a recompute are handled on the canvas update, so this can be used if an immediate recompute is desired

◆ ReinitializeElements()

virtual void UiCanvasInterface::ReinitializeElements ( )
pure virtual

Go through all elements in the canvas and reinitialize them This is done whenever a slice asset changes and the entity context is rebuilt from the root slice asset

◆ SaveToXml()

virtual bool UiCanvasInterface::SaveToXml ( const AZStd::string &  assetIdPathname,
const AZStd::string &  sourceAssetPathname 
)
pure virtual

Save this canvas to the given path in XML

Returns
true if no error

◆ SaveToXmlString()

virtual AZStd::string UiCanvasInterface::SaveToXmlString ( )
pure virtual

Save this canvas to an XML string

Returns
the resulting string

◆ SetEnabled()

virtual void UiCanvasInterface::SetEnabled ( bool  enabled)
pure virtual

Set flag that governs whether the canvas is enabled.

A canvas that's enabled will be updated and rendered each frame.

◆ SetTargetCanvasSize()

virtual void UiCanvasInterface::SetTargetCanvasSize ( bool  isInGame,
const AZ::Vector2 &  targetCanvasSize 
)
pure virtual

Set the target size of the canvas (in pixels)

This should be called before the UpdateCanvas and RenderCanvas methods. When running in game in full screen mode the target canvas size should be set to the viewport size


The documentation for this class was generated from the following file: