Download

Slate, modify Scale of Widget

I’m a little confused on how to scale widgets in slate. At first I thought it was SetContentScale but then I realized that is probably for the scaling on devices. So then I looked at RenderTransform, from what I can tell I can’t edit this struct directly, so I think at best, I need to create a new one with new values…but I’m not sure whats the best way to do this, it feels every way I can do it is really messy, for instance to get the current scale I do this:

widget->GetRenderTransform()->GetMatrix().GetScale().GetVector()

Is this really the best way to do this?
At this point, I’m not sure how to create a new transform with a new scale, but maintain all the other values of the previous transform. Any insight?

I found UWidget does it by creating this:

FSlateRenderTransform Transform2D = ::Concatenate(FScale2D(RenderTransform.Scale), FShear2D::FromShearAngles(RenderTransform.Shear), FQuat2D(FMath::DegreesToRadians(RenderTransform.Angle)), FVector2D(RenderTransform.Translation));
SafeWidget->SetRenderTransform(Transform2D);

I wonder if I’m just better off adding a FWidgetTransformation to my Slate widgets and doing it the same way…

edit:

I’m not sure how to pull out the scale, shear, and degrees separately from the SlateRenderTransform, or I could do it this way…

With some Matrix math I was able to pull some values close out, but as it turns out, there’s not really a way to get the scale,shear, and rotation from the original widget unless you saved those values somewhere. Seems Geometry at one time might have held those… but deprecated when UMG and Render Transforms came on the scene. I ended up just implementing basically the same then UWidget has for RenderTransforms.

UMG doesn’t. As you’ve found out, UWidget::UpdateRenderTransform() stores each component transform in a FWidgetTransform struct, not unlike FTransform does for 3D transforms.

Yeah, it feels like something similar should exist in slate though, since any time you would want to edit render transforms you basically have to add this functionality or create a base class like I did

I’m not sure, but I did it like :

// Scale the widget
FSlateRenderTransform trans(FScale2D(ScaleUI), FVector2D(0.f, 0.f));
widget->SetRenderTransform(trans);

its not working, i need to find how to scale slate ;/