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.
UiDynamicScrollBoxComponent Class Reference

#include <UiDynamicScrollBoxComponent.h>

Inherits AZ::Component, UiDynamicScrollBoxBus::Handler, UiScrollBoxNotificationBus::Handler, UiInitializationBus::Handler, UiTransformChangeNotificationBus::Handler, and UiElementNotificationBus::Handler.

Classes

struct  CachedElementInfo
 
struct  DisplayedElement
 
struct  ElementIndexInfo
 
struct  Section
 

Public Member Functions

 AZ_COMPONENT (UiDynamicScrollBoxComponent, LyShine::UiDynamicScrollBoxComponentUuid, AZ::Component)
 
void RefreshContent () override
 
void AddElementsToEnd (int numElementsToAdd, bool scrollToEndIfWasAtEnd) override
 
void RemoveElementsFromFront (int numElementsToRemove) override
 
void ScrollToEnd () override
 
int GetElementIndexOfChild (AZ::EntityId childElement) override
 
int GetSectionIndexOfChild (AZ::EntityId childElement) override
 
AZ::EntityId GetChildAtElementIndex (int index) override
 
AZ::EntityId GetChildAtSectionAndElementIndex (int sectionIndex, int index) override
 
bool GetAutoRefreshOnPostActivate () override
 
void SetAutoRefreshOnPostActivate (bool autoRefresh) override
 
AZ::EntityId GetPrototypeElement () override
 
void SetPrototypeElement (AZ::EntityId prototypeElement) override
 
bool GetElementsVaryInSize () override
 
void SetElementsVaryInSize (bool varyInSize) override
 
bool GetAutoCalculateVariableElementSize () override
 
void SetAutoCalculateVariableElementSize (bool autoCalculateSize) override
 
float GetEstimatedVariableElementSize () override
 
void SetEstimatedVariableElementSize (float estimatedSize) override
 
bool GetSectionsEnabled () override
 
void SetSectionsEnabled (bool enabled) override
 
AZ::EntityId GetPrototypeHeader () override
 
void SetPrototypeHeader (AZ::EntityId prototypeHeader) override
 
bool GetHeadersSticky () override
 
void SetHeadersSticky (bool stickyHeaders) override
 
bool GetHeadersVaryInSize () override
 
void SetHeadersVaryInSize (bool varyInSize) override
 
bool GetAutoCalculateVariableHeaderSize () override
 
void SetAutoCalculateVariableHeaderSize (bool autoCalculateSize) override
 
float GetEstimatedVariableHeaderSize () override
 
void SetEstimatedVariableHeaderSize (float estimatedSize) override
 
void OnScrollOffsetChanging (AZ::Vector2 newScrollOffset) override
 
void OnScrollOffsetChanged (AZ::Vector2 newScrollOffset) override
 
void InGamePostActivate () override
 
void OnCanvasSpaceRectChanged (AZ::EntityId entityId, const UiTransformInterface::Rect &oldRect, const UiTransformInterface::Rect &newRect) override
 
void OnUiElementBeingDestroyed () override
 

Static Public Member Functions

static void GetProvidedServices (AZ::ComponentDescriptor::DependencyArrayType &provided)
 
static void GetIncompatibleServices (AZ::ComponentDescriptor::DependencyArrayType &incompatible)
 
static void GetRequiredServices (AZ::ComponentDescriptor::DependencyArrayType &required)
 
static void Reflect (AZ::ReflectContext *context)
 

Protected Types

enum  ElementType { SectionHeader , Item , NumElementTypes }
 

Protected Member Functions

void Activate () override
 
void Deactivate () override
 
 AZ_DISABLE_COPY_MOVE (UiDynamicScrollBoxComponent)
 
void PrepareListForDisplay ()
 
AZ::Entity * GetContentEntity () const
 
AZ::EntityId ClonePrototypeElement (ElementType elementType, AZ::EntityId parentEntityId=AZ::EntityId()) const
 
bool IsPrototypeElement (AZ::EntityId entityId) const
 
bool AllPrototypeElementsValid () const
 
bool AnyPrototypeElementsNavigable () const
 
bool AnyElementTypesHaveVariableSize () const
 
bool AnyElementTypesHaveEstimatedSizes () const
 
bool AllElementTypesHaveEstimatedSizes () const
 
bool StickyHeadersEnabled () const
 
void ResizeContentToFitElements ()
 
void ResizeContentElement (float newSize) const
 
void AdjustContentSizeAndScrollOffsetByDelta (float sizeDelta, float scrollDelta) const
 
float CalculateVariableElementSize (int index)
 
float GetAndCacheVariableElementSize (int index)
 
float GetVariableElementSize (int index) const
 
int GetLastKnownAccumulatedSizeIndex (int index, int numElementsWithUnknownSizeOut[ElementType::NumElementTypes]) const
 
float GetElementOffsetAtIndex (int index) const
 
float GetFixedSizeElementOffset (int index) const
 
float GetVariableSizeElementOffset (int index) const
 
void UpdateAverageElementSize (int numAddedElements, float sizeDelta)
 
void ClearDisplayedElements ()
 
AZ::EntityId FindDisplayedElementWithIndex (int index) const
 
float GetVisibleAreaSize () const
 
bool AreAnyElementsVisible (AZ::Vector2 &visibleContentBoundsOut) const
 
void UpdateElementVisibility (bool keepAtEndIfWasAtEnd=false)
 
void CalculateVisibleElementIndices (bool keepAtEndIfWasAtEnd, const AZ::Vector2 &visibleContentBounds, int &firstVisibleElementIndexOut, int &lastVisibleElementIndexOut, int &firstDisplayedElementIndexOut, int &lastDisplayedElementIndexOut, int &firstDisplayedElementIndexWithSizeChangeOut, float &totalElementSizeChangeOut, float &scrollChangeOut)
 
void UpdateStickyHeader (int firstVisibleElementIndex, int lastVisibleElementIndex, float visibleContentBeginning)
 
int FindFirstVisibleHeaderIndex (int firstVisibleElementIndex, int lastVisibleElementIndex, int excludeIndex)
 
void FindVisibleElementIndicesForFixedSizes (const AZ::Vector2 &visibleContentBounds, int &firstVisibleElementIndexOut, int &lastVisibleElementIndexOut) const
 
int FindVisibleElementIndexToRemainInPlace (const AZ::Vector2 &visibleContentBounds) const
 
void AddExtraElementsForNavigation (int &firstDisplayedElementIndexOut, int &lastDisplayedElementIndexOut) const
 
int EstimateFirstVisibleElementIndex (const AZ::Vector2 &visibleContentBounds) const
 
int FindFirstVisibleElementIndex (int estimatedIndex, const AZ::Vector2 &visibleContentBounds, float &firstVisibleElementEndOut) const
 
void CalculateVisibleSpaceBeforeAndAfterElement (int visibleElementIndex, bool keepAtEnd, float visibleAreaBeginning, float &spaceLeftBeforeOut, float &spaceLeftAfterOut) const
 
void CalculateVisibleElementIndicesFromVisibleElementIndex (int visibleElementIndex, const AZ::Vector2 &visibleContentBound, bool keepAtEnd, int &firstVisibleElementIndexOut, int &lastVisibleElementIndexOut, int &firstDisplayedElementIndexOut, int &lastDisplayedElementIndexOut, int &firstDisplayedElementIndexWithSizeChangeOut, float &totalElementSizeChangeOut, float &scrollChangeOut)
 
float CalculateContentBeginningDeltaAfterSizeChange (float contentSizeDelta) const
 
float CalculateContentEndDeltaAfterSizeChange (float contentSizeDelta) const
 
bool IsScrolledToEnd () const
 
bool IsElementDisplayedAtIndex (int index) const
 
AZ::EntityId GetElementForDisplay (ElementType elementType)
 
AZ::EntityId GetElementForAutoSizeCalculation (ElementType elementType)
 
void DisableElementsForAutoSizeCalculation () const
 
float AutoCalculateElementSize (AZ::EntityId elementForAutoSizeCalculation) const
 
void SizeVariableElementAtIndex (AZ::EntityId element, int index) const
 
void PositionElementAtIndex (AZ::EntityId element, int index) const
 
void SetElementAnchors (AZ::EntityId element) const
 
void SetElementOffsets (AZ::EntityId element, float offset) const
 
ElementType GetElementTypeAtIndex (int index) const
 
ElementIndexInfo GetElementIndexInfoFromIndex (int index) const
 
int GetIndexFromElementIndexInfo (const ElementIndexInfo &elementIndexInfo) const
 
AZ::EntityId GetImmediateContentChildFromDescendant (AZ::EntityId childElement) const
 
bool HeadersHaveVariableSizes () const
 
bool IsValidPrototype (AZ::EntityId entityId) const
 

Protected Attributes

bool m_autoRefreshOnPostActivate
 Whether the list should refresh automatically on post activate.
 
int m_defaultNumElements
 Number of elements by default. Overridden by UiDynamicListDataBus::GetNumElements.
 
AZ::EntityId m_itemPrototypeElement
 
bool m_variableItemElementSize
 
bool m_autoCalculateItemElementSize
 
float m_estimatedItemElementSize
 
bool m_hasSections
 Whether the list is divided into sections with headers.
 
int m_defaultNumSections
 Number of sections by default. Overridden by UiDynamicListDataBus::GetNumSections.
 
AZ::EntityId m_headerPrototypeElement
 
bool m_stickyHeaders
 
bool m_variableHeaderElementSize
 
bool m_autoCalculateHeaderElementSize
 
float m_estimatedHeaderElementSize
 
AZ::EntityId m_prototypeElement [ElementType::NumElementTypes]
 The entity Ids of the prototype elements.
 
float m_prototypeElementSize [ElementType::NumElementTypes]
 
bool m_variableElementSize [ElementType::NumElementTypes]
 
bool m_autoCalculateElementSize [ElementType::NumElementTypes]
 
float m_estimatedElementSize [ElementType::NumElementTypes]
 
bool m_isPrototypeElementNavigable [ElementType::NumElementTypes]
 Whether elements in the list are navigable.
 
float m_averageElementSize
 Average element size of the elements with known sizes.
 
int m_numElementsUsedForAverage
 The number of elements used to calculate the current average.
 
float m_lastCalculatedVisibleContentOffset
 
bool m_isVertical
 Whether the list is vertical or horizontal. Determined by the scroll box.
 
AZStd::list< DisplayedElementm_displayedElements
 A list of currently displayed elements.
 
AZStd::list< AZ::EntityId > m_recycledElements [ElementType::NumElementTypes]
 A list of unused entities.
 
AZ::EntityId m_clonedElementForAutoSizeCalculation [ElementType::NumElementTypes]
 Cloned entities used to auto calculate sizes.
 
DisplayedElement m_currentStickyHeader
 The header that is currently sticky at the top or left of the visible area.
 
int m_firstDisplayedElementIndex
 First and last element indices that are being displayed (Not necessarily visible in viewport since we add an extra element for gamepad/keyboard navigation purposes)
 
int m_lastDisplayedElementIndex
 
int m_firstVisibleElementIndex
 First and last element indices that are visible in the viewport.
 
int m_lastVisibleElementIndex
 
AZStd::vector< CachedElementInfom_cachedElementInfo
 Cached element sizes. Used when elements can vary in size.
 
int m_numElements
 The virtual number of elements in the list. Includes both headers and items.
 
AZStd::vector< Sectionm_sections
 List of the sections in the list.
 
bool m_listPreparedForDisplay
 Whether the list has been set up for display.
 

Detailed Description

This component dynamically sets up scrollbox content as a horizontal or vertical list of elements that are cloned from prototype entities. Only the minimum number of entities are created for efficient scrolling, and are reused when new elements come into view. The list can consist of only items, or it can be divided into sections that include a header at the beginning of each section, followed by items that belong to that section. The meaning of "element" differs in the public and private interface, mainly for backward compatibility. In the private interface, "element" refers to a generic entry in the list which can be of different types. Currently there are two types of elements: headers and items. In the public interface however, "element" means the same thing as "item" does in the private interface, and "item" is unused (the public interface does not need to define the concept of a generic entry in the list.) Both headers and items can have fixed sizes determined by their corresponding prototype entities, or they could vary in size. If they vary in size, another option is available to indicate whether to auto calculate the sizes or request the sizes via a bus interface. There is also the option to provide an estimated size that will be used until the elements scroll into view and their real size calculated. For lists with a large number of elements, it is advisable to use the estimated size as calculating the sizes of all elements up front could be costly. When elements vary in size, a cache is maintained and the element sizes are only calculated once.

Member Data Documentation

◆ m_autoCalculateElementSize

bool UiDynamicScrollBoxComponent::m_autoCalculateElementSize[ElementType::NumElementTypes]
protected

Whether element sizes should be auto calculated or whether they should be requested. Applies when elements can vary in size

◆ m_autoCalculateHeaderElementSize

bool UiDynamicScrollBoxComponent::m_autoCalculateHeaderElementSize
protected

Whether header sizes should be auto calculated or whether they should be requested. Applies when headers can vary in size

◆ m_autoCalculateItemElementSize

bool UiDynamicScrollBoxComponent::m_autoCalculateItemElementSize
protected

Whether item sizes should be auto calculated or whether they should be requested. Applies when items can vary in size

◆ m_estimatedElementSize

float UiDynamicScrollBoxComponent::m_estimatedElementSize[ElementType::NumElementTypes]
protected

An estimated height or width for the element size. If set to greater than 0, this size will be used until an element goes into view and its real size is calculated. Applies when elements can vary in size

◆ m_estimatedHeaderElementSize

float UiDynamicScrollBoxComponent::m_estimatedHeaderElementSize
protected

An estimated height or width for the header size. If set to greater than 0, this size will be used until a header goes into view and its real size is calculated. Applies when headers can vary in size

◆ m_estimatedItemElementSize

float UiDynamicScrollBoxComponent::m_estimatedItemElementSize
protected

An estimated height or width for the item size. If set to greater than 0, this size will be used until an item goes into view and its real size is calculated. Applies when items can vary in size

◆ m_headerPrototypeElement

AZ::EntityId UiDynamicScrollBoxComponent::m_headerPrototypeElement
protected

The prototype element for the headers in the list. Used when sections are enabled

◆ m_itemPrototypeElement

AZ::EntityId UiDynamicScrollBoxComponent::m_itemPrototypeElement
protected

The prototype element for the items in the list. Used when sections are enabled

◆ m_lastCalculatedVisibleContentOffset

float UiDynamicScrollBoxComponent::m_lastCalculatedVisibleContentOffset
protected

The last calculated offset from the top or left of the content's parent (the visible area) to the top or left of the content. Used to estimate a first visible element index

◆ m_prototypeElementSize

float UiDynamicScrollBoxComponent::m_prototypeElementSize[ElementType::NumElementTypes]
protected

Stores the size of the prototype elements before they are removed from the content element's child list. Used to calculate the content size and element offsets when there is no variation in element size

◆ m_stickyHeaders

bool UiDynamicScrollBoxComponent::m_stickyHeaders
protected

Whether headers should stick to the beginning of the visible area Used when sections are enabled

◆ m_variableElementSize

bool UiDynamicScrollBoxComponent::m_variableElementSize[ElementType::NumElementTypes]
protected

Whether elements in the list can vary in size (height for vertical lists and width for horizontal lists) If false, the element size is fixed and is determined by the prototype element

◆ m_variableHeaderElementSize

bool UiDynamicScrollBoxComponent::m_variableHeaderElementSize
protected

Whether headers in the list can vary in size (height for vertical lists and width for horizontal lists) If false, the header size is fixed and is determined by the prototype element

◆ m_variableItemElementSize

bool UiDynamicScrollBoxComponent::m_variableItemElementSize
protected

Whether items in the list can vary in size (height for vertical lists and width for horizontal lists) If false, the item size is fixed and is determined by the prototype element


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