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

Inherits AZ::Component, UiVisualBus::Handler, UiRenderBus::Handler, UiTextBus::Handler, UiClickableTextBus::Handler, UiAnimateEntityBus::Handler, UiTransformChangeNotificationBus::Handler, UiLayoutCellDefaultBus::Handler, FontNotificationBus::Handler, LanguageChangeNotificationBus::Handler, UiCanvasPixelAlignmentNotificationBus::Handler, and TextureAtlasNamespace::TextureAtlasNotificationBus::Handler.

Classes

struct  DrawBatch
 
struct  DrawBatchLine
 A single line of text that can be composed of multiple DrawBatch objects. More...
 
struct  DrawBatchLines
 
struct  InlineImage
 An inline image to be displayed within the text. More...
 
struct  LineOffsets
 Simple container for left/right AZ::Vector2 offsets. More...
 

Public Types

using FontEffectComboBoxVec = AZStd::vector< AZStd::pair< unsigned int, AZStd::string > >
 
using InlineImageContainer = AZStd::list< InlineImage * >
 
using DrawBatchContainer = AZStd::list< DrawBatch >
 
using DrawBatchLineContainer = AZStd::list< DrawBatchLine >
 
using FontFamilyRefSet = AZStd::set< FontFamilyPtr >
 

Public Member Functions

 AZ_COMPONENT (UiTextComponent, LyShine::UiTextComponentUuid, AZ::Component)
 
void ResetOverrides () override
 
void SetOverrideColor (const AZ::Color &color) override
 
void SetOverrideAlpha (float alpha) override
 
void SetOverrideFont (FontFamilyPtr fontFamily) override
 
void SetOverrideFontEffect (unsigned int fontEffectIndex) override
 
void Render (LyShine::IRenderGraph *renderGraph) override
 
AZStd::string GetText () override
 
void SetText (const AZStd::string &text) override
 
AZStd::string GetTextWithFlags (GetTextFlags flags=GetAsIs) override
 
void SetTextWithFlags (const AZStd::string &text, SetTextFlags flags=SetAsIs) override
 
AZ::Color GetColor () override
 
void SetColor (const AZ::Color &color) override
 
LyShine::PathnameType GetFont () override
 
void SetFont (const LyShine::PathnameType &fontPath) override
 
int GetFontEffect () override
 
void SetFontEffect (int effectIndex) override
 
AZStd::string GetFontEffectName (int effectIndex) override
 
void SetFontEffectByName (const AZStd::string &effectName) override
 
float GetFontSize () override
 
void SetFontSize (float size) override
 
void GetTextAlignment (IDraw2d::HAlign &horizontalAlignment, IDraw2d::VAlign &verticalAlignment) override
 
void SetTextAlignment (IDraw2d::HAlign horizontalAlignment, IDraw2d::VAlign verticalAlignment) override
 
IDraw2d::HAlign GetHorizontalTextAlignment () override
 
void SetHorizontalTextAlignment (IDraw2d::HAlign alignment) override
 
IDraw2d::VAlign GetVerticalTextAlignment () override
 
void SetVerticalTextAlignment (IDraw2d::VAlign alignment) override
 
float GetCharacterSpacing () override
 
void SetCharacterSpacing (float characterSpacing) override
 
float GetLineSpacing () override
 
void SetLineSpacing (float lineSpacing) override
 Expects pixels.
 
int GetCharIndexFromPoint (AZ::Vector2 point, bool mustBeInBoundingBox) override
 
int GetCharIndexFromCanvasSpacePoint (AZ::Vector2 point, bool mustBeInBoundingBox) override
 
AZ::Vector2 GetPointFromCharIndex (int index) override
 
AZ::Color GetSelectionColor () override
 
void GetSelectionRange (int &startIndex, int &endIndex) override
 
void SetSelectionRange (int startIndex, int endIndex, const AZ::Color &selectionColor) override
 
void ClearSelectionRange () override
 
AZ::Vector2 GetTextSize () override
 
float GetTextWidth () override
 
float GetTextHeight () override
 
void GetTextBoundingBox (int startIndex, int endIndex, UiTransformInterface::RectPointsArray &rectPoints) override
 
DisplayedTextFunction GetDisplayedTextFunction () const override
 
void SetDisplayedTextFunction (const DisplayedTextFunction &displayedTextFunction) override
 
OverflowMode GetOverflowMode () override
 
void SetOverflowMode (OverflowMode overflowMode) override
 
WrapTextSetting GetWrapText () override
 
void SetWrapText (WrapTextSetting wrapSetting) override
 
ShrinkToFit GetShrinkToFit () override
 
void SetShrinkToFit (ShrinkToFit shrinkToFit) override
 
void ResetCursorLineHint () override
 
bool GetIsMarkupEnabled () override
 
void SetIsMarkupEnabled (bool isEnabled) override
 
float GetMinimumShrinkScale () override
 
void SetMinimumShrinkScale (float minShrinkScale) override
 
void GetClickableTextRects (UiClickableTextInterface::ClickableTextRects &clickableTextRects) override
 
void SetClickableTextColor (int id, const AZ::Color &color) override
 
void PropertyValuesChanged () override
 
void OnCanvasSpaceRectChanged (AZ::EntityId entityId, const UiTransformInterface::Rect &oldRect, const UiTransformInterface::Rect &newRect) override
 
void OnTransformToViewportChanged () override
 
float GetMinWidth () override
 
float GetMinHeight () override
 
float GetTargetWidth (float maxWidth) override
 
float GetTargetHeight (float maxHeight) override
 
float GetExtraWidthRatio () override
 
float GetExtraHeightRatio () override
 
void OnFontsReloaded () override
 
void LanguageChanged () override
 
void OnCanvasTextPixelAlignmentChange () override
 
void OnAtlasLoaded (const TextureAtlasNamespace::TextureAtlas *atlas) override
 
void OnAtlasUnloaded (const TextureAtlasNamespace::TextureAtlas *atlas) 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

using DrawBatchLineIters = AZStd::vector< DrawBatchLineContainer::iterator >
 
using DrawBatchStartPosPair = AZStd::pair< DrawBatch *, float >
 
using DrawBatchStartPositions = AZStd::vector< DrawBatchStartPosPair >
 

Protected Member Functions

void Init () override
 
void Activate () override
 
void Deactivate () override
 
void ChangeFont (const AZStd::string &fontFileName)
 Called when we know the font needs to be changed.
 
void GetTextBoundingBoxPrivate (const DrawBatchLines &drawBatchLines, int startIndex, int endIndex, UiTransformInterface::RectPointsArray &rectPoints)
 Implementation of getting bounding box for the given displayed text.
 
void GetTextRect (UiTransformInterface::RectPoints &rect)
 Get the bounding rectangle of the text, in untransformed canvas space.
 
void GetTextRect (UiTransformInterface::RectPoints &rect, const AZ::Vector2 &textSize)
 
void OnTextChange ()
 ChangeNotify callback for text string change.
 
void OnColorChange ()
 ChangeNotify callback for color change.
 
void OnAlignmentChange ()
 ChangeNotify callback for alignment change.
 
void OnOverflowChange ()
 ChangeNotify callback for overflow settings change.
 
void OnFontSizeChange ()
 ChangeNotify callback for font size change.
 
AZ::u32 OnFontPathnameChange ()
 ChangeNotify callback for font pathname change.
 
void OnFontEffectChange ()
 ChangeNotify callback for font effect change.
 
void OnWrapTextSettingChange ()
 ChangeNotify callback for text wrap setting change.
 
void OnShrinkToFitChange ()
 ChangeNotify callback for shrink-to-fit setting change.
 
void OnMinShrinkScaleChange ()
 ChangeNotify callback for "minimum shrink scale" setting change.
 
void OnCharSpacingChange ()
 ChangeNotify callback for char spacing change.
 
void OnLineSpacingChange ()
 ChangeNotify callback for line spacing change.
 
void OnMarkupEnabledChange ()
 ChangeNotify callback for markup enabled change.
 
FontEffectComboBoxVec PopulateFontEffectList ()
 Populate the list for the font effect combo box in the properties pane.
 
float CalculateHorizontalClipOffset ()
 
void MarkDrawBatchLinesDirty (bool invalidateLayout)
 Mark draw batches dirty.
 
const DrawBatchLinesGetDrawBatchLines ()
 Calculate the DrawBatchLines if needed and return a const ref.
 
void CalculateDrawBatchLines (UiTextComponent::DrawBatchLines &drawBatchLinesOut, bool forceNoWrap=false, float availableWidth=-1.0f, bool excludeTrailingSpaceWidth=true)
 Calculates draw batch lines.
 
void RenderToCache (float alpha)
 Renders the text to the render cache.
 
void RenderDrawBatchLines (const UiTextComponent::DrawBatchLines &drawBatchLines, const AZ::Vector2 &pos, const UiTransformInterface::RectPoints &points, const AZ::Matrix4x4 &transformToViewport, STextDrawContext &fontContext)
 Add DrawBatch lines to the render graph for rendering.
 
void UpdateTextRenderBatchesForFontTextureChange ()
 Update the text render batches in the case of a font texture change.
 
STextDrawContext GetTextDrawContextPrototype (int requestFontSize, const AZ::Vector2 &fontSizeScale) const
 Returns a prototypical STextDrawContext to be used when interacting with IFont routines..
 
void OnTextWidthPropertyChanged ()
 Recomputes draw batch lines as appropriate depending on current options when text width properties are modified.
 
void HandleOverflowText (UiTextComponent::DrawBatchLines &drawBatchLinesOut)
 Handles overflow and shrink-to-text settings to text.
 
void HandleShrinkToFit (UiTextComponent::DrawBatchLines &drawBatchLinesOut, float availableHeight=-1.0f)
 Handles shrink-to-fit for text, if applicable.
 
void HandleUniformShrinkToFitWithScale (UiTextComponent::DrawBatchLines &drawBatchLinesOut, const AZ::Vector2 &scaleVec)
 Handles the "uniform" shrink-to-fit setting.
 
void HandleShrinkToFitWithWrapping (UiTextComponent::DrawBatchLines &drawBatchLinesOut, const AZ::Vector2 &currentElementSize, const AZ::Vector2 &textSize)
 Handles the shrink-to-fit setting for word-wrapped text.
 
void HandleWidthOnlyShrinkToFitWithWrapping (UiTextComponent::DrawBatchLines &drawBatchLinesOut, const AZ::Vector2 &currentElementSize, int maxLinesElementCanHold)
 Handles "width only" word-wrapped shrink-to-fit text.
 
void HandleUniformShrinkToFitWithWrapping (UiTextComponent::DrawBatchLines &drawBatchLinesOut, const AZ::Vector2 &currentElementSize, int maxLinesElementCanHold)
 Handles "uniform" word-wrapped shrink-to-fit text.
 
void HandleEllipsis (UiTextComponent::DrawBatchLines &drawBatchLinesOut, float availableHeight=-1.0f)
 Inserts ellipsis into overflowing text.
 
void GetLineToEllipsisAndLinesToTruncate (UiTextComponent::DrawBatchLines &drawBatchLinesOut, DrawBatchLineContainer::iterator *lineToEllipsis, DrawBatchLineIters &linesToRemove, const AZ::Vector2 &currentElementSize)
 Returns the draw batch line to ellipsis and the following lines to truncate (if any).
 
void GetDrawBatchStartPositions (DrawBatchStartPositions &startPositions, DrawBatchLine *lineToEllipsis, const AZ::Vector2 &currentElementSize)
 Returns the "starting" pixel position for each batch on the given line.
 
DrawBatchGetDrawBatchToEllipseAndPositions (const char *ellipseText, const STextDrawContext &ctx, const AZ::Vector2 &currentElementSize, DrawBatchStartPositions *startPositions, float *drawBatchStartPos, float *ellipsisPos)
 Returns the draw batch that will have ellipsis inserted, along with required position information to do so.
 
void TruncateDrawBatches (DrawBatchLine *lineToTruncate, const DrawBatch *truncateAfterBatch)
 Removes all draw batches following the given DrawBatch on the given DrawBatchLine.
 
int GetStartEllipseIndexInDrawBatch (const DrawBatch *drawBatchToEllipse, const STextDrawContext &ctx, const float drawBatchStartPos, const float ellipsePos)
 Given a draw batch, get the character index where ellipsis should be inserted in the string.
 
void InsertEllipsisText (const char *ellipseText, const int ellipsisCharPos, DrawBatch *drawBatchToEllipse)
 Inserts the ellipse text into the given draw batch and updates batch and line sizing information.
 
void SetBatchLineFontPointers (DrawBatchLine *batchLine)
 
bool GetTextOverflowsBounds (const AZ::Vector2 &textSize, const AZ::Vector2 &elementSize) const
 Returns true if the given text rect overflows the given element size, false otherwise.
 
AZ::Vector2 GetTextSizeFromDrawBatchLines (const UiTextComponent::DrawBatchLines &drawBatchLines) const
 Compute the text size from the already computed draw batch lines.
 
AZStd::string GetLocalizedText (const AZStd::string &text)
 Localize the given text string.
 
AZ::Vector2 CalculateAlignedPositionWithYOffset (const UiTransformInterface::RectPoints &points)
 

Member Function Documentation

◆ CalculateAlignedPositionWithYOffset()

AZ::Vector2 UiTextComponent::CalculateAlignedPositionWithYOffset ( const UiTransformInterface::RectPoints points)
protected

Given rect points and number of lines of text to display, returns the position to display text.

The number of lines of text determines the Y offset of the first line to display. For top-aligned text, this offset will be zero (regardless of the number of lines of text) because the first line to display will always be displayed at the top of the rect, while bottom-aligned text will be offset by the number of lines to display, and vertically centered text will be offset by half of that amount.

Example: if horizontal alignment is "left" and vertical alignment is "top", this will simply return the top-left point of the rect.

This assumes the given rect points are axis-aligned.

◆ CalculateHorizontalClipOffset()

float UiTextComponent::CalculateHorizontalClipOffset ( )
protected

Returns the amount of pixels the displayed text is adjusted for clipping.

Returns zero if text is not large enough to be clipped or clipping isn't enabled.

Note
This does not simply return m_clipoffset. This method calculates and assigns new values to m_clipOffset and m_clipOffsetMultiplier and returns their product.

◆ GetTextRect()

void UiTextComponent::GetTextRect ( UiTransformInterface::RectPoints rect,
const AZ::Vector2 &  textSize 
)
protected

Similar to GetTextRect, but allows getting a rect for only a portion of text (via textSize).

This method is particularly useful for multi-line text, where text selection can vary line-by-line, or across multiple lines of text, in which case you only want rects for a portion of the displayed text, rather than all of it (which GetTextRect does).

◆ SetBatchLineFontPointers()

void UiTextComponent::SetBatchLineFontPointers ( DrawBatchLine batchLine)
protected

Ensures that all draw batches on the given batch line have valid font pointers

This is primarily used for ellipsis overflow handling, making it easier to make assumptions about which font to use when inserting ellipsis text for a given batch (when that batch is an image batch).

◆ SetCharacterSpacing()

void UiTextComponent::SetCharacterSpacing ( float  characterSpacing)
override

Expects 1/1000th ems, where 1 em = font size. This will also affect text size, which can lead to formatting changes (with word-wrap enabled for instance).


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