Can I rotate a text element drawn within NativePaint override?

I want to draw various text elements within the space of my custom UMG widget. As far as I can see, Slate layout transforms don’t support rotation, so it would have to be accomplished with the render transform. However, FSlateDrawElement::MakeText doesn’t provide any rotation parameters either, and there doesn’t appear to be a way to manually modify the render transform of an element.

Rotating the widget itself is not an option as only certain text elements within it should be rotated.

What’s the best way to achieve this?

I discovered that you can use the overload of FGeometry::MakeChild taking a render transform, then pass a paint geometry created from the result into the MakeText function. It seems to work, but I don’t know if it is the correct approach and I still have issues with strange clipping behaviour.

Do you mind showing us how you managed this? I am running into the same issue.

Cheers,
Mugen

Sure. Something like this.

auto RotationTransform = FSlateRenderTransform(FQuat2D(SomeRotation));
auto TextGeometry = InGeometry.MakeChild(
  TextSize,
  FSlateLayoutTransform(),
  RotationTransform,
  FVector2D(0.0f, 0.0f)
  );

FSlateDrawElement::MakeText(
  OutDrawElements,
  Layer,
  TextGeometry.ToPaintGeometry(),
  Text,
  FontInfo,
  ClippingRect,
  ESlateDrawEffect::None,
  FontColor
  );

You will likely have trouble with the clipping rect, I still haven’t found a proper solution and am unsure it’s even possible with the way Slate clipping is implemented. If you find stuff getting clipped you can just pass in an arbitrarily large clip rect to MakeText, but then you have to live with text not being clipped when it should be (ie. parent widget boundary). I think this could be worked around by using a scissor rect too, but I haven’t dug into that yet.

1 Like