Using FSlateLayoutTransform

I’ve been wanting to draw custom boxes using FSlateDrawElement::DrawBox(). Nevertheless, the previous way of passing paint geometry PaintContext.AllottedGeometry.ToPaintGeometry(FVector2D, FVector2D) has been deprecated and no longer compiles (which is a bit strange given the WidgetBlueprintLibrary does it this way, but anyhow…). In other words, a function like this no longer compiles:

void UMyWidget::DrawCustomBox(FPaintContext& PaintContext, class USlateBrushAsset* Brush, FVector2D Size, FVector2D Position)
{
        PaintContext.MaxLayer++;
		FSlateDrawElement::MakeBox(
			PaintContext.OutDrawElements,
			PaintContext.MaxLayer,
			PaintContext.AllottedGeometry.ToPaintGeometry(Position, Size),
			&Brush->Brush,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
}

Instead, I imagine I would require something which looks like this:

void UMyWidget::DrawCustomBox(FPaintContext& PaintContext, class USlateBrushAsset* Brush, FVector2D Size, FVector2D Position)
{
        FSlateLayoutTransform SlateLayoutTransform(??); // What goes here? 
        PaintContext.MaxLayer++;
		FSlateDrawElement::MakeBox(
			PaintContext.OutDrawElements,
			PaintContext.MaxLayer,
			PaintContext.AllottedGeometry.ToPaintGeometry(SlateLayoutTransform),
			&Brush->Brush,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
}

In other words, how do you construct a FSlateLayoutTransform from a position and a size? It wants a translation and a scale. I’m assuming that the translation = position, but the scale is a float… so I’m assuming we’re working with transform matrices. Would I have to set the TransformVector afterward to multiply the scale by my desired X/Y box size?

As you mentioned

PaintContext.AllottedGeometry.ToPaintGeometry(Position, Size),

won’t work anymore, but instead of:

I’d suggest you try:

PaintContext.AllottedGeometry.ToPaintGeometry(Size, FSlateLayoutTransform(Position)),

That should do what you were looking for.

(Posted to help others who might have the same issue)