From 13627265c9c9c5af194d9b917cbacffaaf59014e Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Fri, 6 Jan 2023 17:35:49 +0000 Subject: [PATCH] TypewriterText: Make sure we calculate the wrapped text ahead of time Failing to do this can cause some odd flickering in the desired size because it previously didn't apply until the first letter callback --- .../Private/StevesUI/TypewriterTextWidget.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp b/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp index 97a00fb..059ab5b 100644 --- a/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp +++ b/Source/StevesUEHelpers/Private/StevesUI/TypewriterTextWidget.cpp @@ -108,6 +108,9 @@ void UTypewriterTextWidget::PlayLine(const FText& InLine, float Speed) bHasFinishedPlaying = false; + LineText->SetText(FText()); + CalculateWrappedString(); + FTimerDelegate Delegate; Delegate.BindUObject(this, &ThisClass::PlayNextLetter); @@ -135,11 +138,6 @@ void UTypewriterTextWidget::SkipToLineEnd() void UTypewriterTextWidget::PlayNextLetter() { - if (Segments.Num() == 0) - { - CalculateWrappedString(); - } - // Incorporate pauses as a multiple of play timer (may not be exact but close enough) if (PauseTime > 0) { @@ -200,9 +198,10 @@ void UTypewriterTextWidget::CalculateWrappedString() const FGeometry& TextBoxGeometry = LineText->GetCachedGeometry(); const FVector2D TextBoxSize = TextBoxGeometry.GetLocalSize(); + Layout->ClearLines(); Layout->SetWrappingWidth(TextBoxSize.X); Marshaller->SetText(CurrentLine.ToString(), *Layout.Get()); - Layout->UpdateIfNeeded(); + Layout->UpdateLayout(); bool bHasWrittenText = false; auto Views = Layout->GetLineViews();