Download

Troubles with drawing an image in a custom widget

Hey Team,

I have created a new Graph UMG widget with an underlying CompoundWidget slate graph rending below it.

graph.JPG

I’m running into issues as I am attempting to draw a small icon (bmp texture) on my graph to indicate the max point on the data line.
FSlateDrawElement::MakeBox maximizes the brush to the size of my graph, rather than allowing me to provide a size and position and call it on my slate’s OnPaint().

Is there any way I can limit it to the position and size I wish?

Cheers,
Mugen

Part of the data passed to MakeBox is the paint geometry of the box, including the size and position. If you’re just using the paint geometry of the chart that’s why.

That did the trick, cheers Nick.

I had attempted to create the geometry previously but had not tried .MakeChild(). For clarification to solve the problem, this is what I ended up with to produce the desired result:



int32 SGraph::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
    FGeometry geometry = AllottedGeometry.MakeChild(IconSize, IconTransform);
    FSlateDrawElement::MakeBox(OutDrawElements, LayerId + 1, geometry.ToPaintGeometry(), Brush.Get(), MyClippingRect);
    return LayerId; 
}


Hope this can help others.
Cheers
Mugen

1 Like