Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Slate STextBlock animate ContentScale do nothing

I'm trying to animate a STextBlock within a SBorder change the content scale, but it does nothing.

  * Implement a STextBlock with animation facilities
 class KSGMSLATE_API SKTextBlockAnimated : public SBorder
         // STextBlock arguments
         : _Text()
         , _TextStyle(&FCoreStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText"))
         , _Font()
         , _ColorAndOpacity()
         , _ShadowOffset()
         , _ShadowColorAndOpacity()
         , _HighlightColor()
         , _HighlightShape()
         , _HighlightText()
         , _WrapTextAt(0.0f)
         , _AutoWrapText(false)
         , _WrappingPolicy(ETextWrappingPolicy::DefaultWrapping)
         , _Margin()
         , _LineHeightPercentage(1.0f)
         , _Justification(ETextJustify::Left)
         , _MinDesiredWidth(0.0f)
         , _TextShapingMethod()
         , _TextFlowDirection()
         , _LineBreakPolicy()
         // End of STextBlock arguments
         , _AnimationType(ECurveEaseFunction::CubicOut)
         , _AnimationSeconds(1.0f)
         , _AutoPlay(true)
         , _LoopMode(true)
         , _ScaleXFactor(2.0f)
         , _ScaleYFactor(2.0f)
     // STextBlock arguments
     /** The text displayed in this text block */
     /** Pointer to a style of the text block, which dictates the font, color, and shadow options. */
     SLATE_STYLE_ARGUMENT(FTextBlockStyle, TextStyle)
     /** Sets the font used to draw the text */
     SLATE_ATTRIBUTE(FSlateFontInfo, Font)
     /** Text color and opacity */
     SLATE_ATTRIBUTE(FSlateColor, ColorAndOpacity)
     /** Drop shadow offset in pixels */
     SLATE_ATTRIBUTE(FVector2D, ShadowOffset)
     /** Shadow color and opacity */
     SLATE_ATTRIBUTE(FLinearColor, ShadowColorAndOpacity)
     /** The color used to highlight the specified text */
     SLATE_ATTRIBUTE(FLinearColor, HighlightColor)
     /** The brush used to highlight the specified text*/
     SLATE_ATTRIBUTE(const FSlateBrush*, HighlightShape)
     /** Highlight this text in the text block */
     SLATE_ATTRIBUTE(FText, HighlightText)
     /** Whether text wraps onto a new line when it's length exceeds this width; if this value is zero or negative, no wrapping occurs. */
     SLATE_ATTRIBUTE(float, WrapTextAt)
     /** Whether to wrap text automatically based on the widget's computed horizontal space.  IMPORTANT: Using automatic wrapping can result
     in visual artifacts, as the the wrapped size will computed be at least one frame late!  Consider using WrapTextAt instead.  The initial
     desired size will not be clamped.  This works best in cases where the text block's size is not affecting other widget's layout. */
     SLATE_ATTRIBUTE(bool, AutoWrapText)
     /** The wrapping policy to use */
     SLATE_ATTRIBUTE(ETextWrappingPolicy, WrappingPolicy)
     /** The amount of blank space left around the edges of text area. */
     SLATE_ATTRIBUTE(FMargin, Margin)
     /** The amount to scale each lines height by. */
     SLATE_ATTRIBUTE(float, LineHeightPercentage)
     /** How the text should be aligned with the margin. */
     SLATE_ATTRIBUTE(ETextJustify::Type, Justification)
     /** Minimum width that a text block should be */
     SLATE_ATTRIBUTE(float, MinDesiredWidth)
     /** Which text shaping method should we use? (unset to use the default returned by GetDefaultTextShapingMethod) */
     SLATE_ARGUMENT(TOptional<ETextShapingMethod>, TextShapingMethod)
     /** Which text flow direction should we use? (unset to use the default returned by GetDefaultTextFlowDirection) */
     SLATE_ARGUMENT(TOptional<ETextFlowDirection>, TextFlowDirection)
     /** The iterator to use to detect appropriate soft-wrapping points for lines (or null to use the default) */
     SLATE_ARGUMENT(TSharedPtr<IBreakIterator>, LineBreakPolicy)
     /** Called when this text is double clicked */
     SLATE_EVENT(FOnClicked, OnDoubleClicked)
     // End of STextBlock arguments
     /** The animation type */
     SLATE_ARGUMENT(ECurveEaseFunction::Type, AnimationType)
     /** The animation seconds */
     SLATE_ARGUMENT(float, AnimationSeconds)
     /** Auto play the animation */
     SLATE_ARGUMENT(bool, AutoPlay)
     /** Play the animation in loop mode */
     SLATE_ARGUMENT(bool, LoopMode)
     /** The scaling X factor */
     SLATE_ATTRIBUTE(float, ScaleXFactor)
     /** The scaling Y factor */
     SLATE_ATTRIBUTE(float, ScaleYFactor)
     * Construct this widget
     * @param    InArgs    The declaration data for this widget
     void Construct(const FArguments& InArgs);
      * @brief Is the animation playing ?
      * @return true if animation is playing, false if not.
     bool IsAnimationPlaying() const
         return Curve.IsPlaying();
      * @brief Play the animation.
     void PlayAnimation()
         if (Curve.IsPlaying())
      * @brief Pause the animation.
     void PauseAnimation()
      * @brief Gets text scale based on the animation curve.
      * @return The FVector2D text scale.
     FVector2D GetDesiredSizeScale() const;
     /** Curved used to simulate the animation */
     FCurveSequence Curve;
     TSharedPtr<class STextBlock> TextBlock;
     /** The scaling X factor */
     TAttribute<float> ScaleXFactor;
     /** The scaling Y factor */
     TAttribute<float> ScaleYFactor;

 void SKTextBlockAnimated::Construct(const FArguments& InArgs)
     ScaleXFactor = InArgs._ScaleXFactor;
     ScaleYFactor = InArgs._ScaleYFactor;
     // The curve used for animating the text block
     Curve = FCurveSequence(0.0f, InArgs._AnimationSeconds, InArgs._AnimationType);
         .ContentScale(this, &SKTextBlockAnimated::GetDesiredSizeScale)
             SAssignNew(TextBlock, STextBlock)
     Curve.Play(this->AsShared(), InArgs._LoopMode);
     // If not auto play, pause it immediately
     if (InArgs._AutoPlay == false)
 FVector2D SKTextBlockAnimated::GetDesiredSizeScale() const
     if (Curve.IsPlaying())
         float Scale = Curve.GetLerp();
         float X = FMath::Lerp(1.0f, ScaleXFactor.Get(), Scale);
         float Y = FMath::Lerp(1.0f, ScaleYFactor.Get(), Scale);
         UE_LOG(LogKSGMSlate, VeryVerbose, TEXT("SKTextBlockAnimated::GetDesiredSizeScale  -  Scale=%g   X=%g  Y=%g"), Scale, X, Y);
         return FVector2D(X, Y);
     UE_LOG(LogKSGMSlate, VeryVerbose, TEXT("SKTextBlockAnimated::GetDesiredSizeScale  -  1.0 - 1.0 "));
     return FVector2D(1.0f, 1.0f);

The scale factor is changing correctly, but the text block does not change.

[2017.04.04-06.16.30:331][476]LogKSGMSlate:VeryVerbose: SKTextBlockAnimated::GetDesiredSizeScale - Scale=0.440506 X=2.32152 Y=1.88101
[2017.04.04-06.16.30:347][477]LogKSGMSlate:VeryVerbose: SKTextBlockAnimated::GetDesiredSizeScale - Scale=0.456686 X=2.37006 Y=1.91337

Anyone has an idea why the content is not scaled ?

Product Version: UE 4.15
more ▼

asked Apr 04 '17 at 06:58 AM in C++ Programming

avatar image

714 49 56 128

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question