I have a custom material that requires to know widget size. I want to build my own UBorder implementation that uses that material. However for the life of me I can’t figure out how to get the size!
UBorder internally constructs SBorder, which has OnPaint method that actually captures the correct geometry, but it’s not exposed anywhere. I’ve tried getting the slot->GetSize() and cachedGeometry, but all these values are always 0. Maybe I am capturing them at the wrong place, not sure.
class BLAH_API UBeveledWidget : public UBorder
// etc
TSharedRef<SWidget> UBeveledWidget::RebuildWidget()
{
auto widget = Super::RebuildWidget();
FVector2D borderSize = MyBorder->GetDesiredSize();
UE_LOG(LogTemp, Warning, TEXT("Desired size: %f, %f"), borderSize.X, borderSize.Y);
auto slot = Cast<UCanvasPanelSlot>(Slot);
if (slot)
{
borderSize = slot->GetSize();
UE_LOG(LogTemp, Warning, TEXT("Slot size: %f, %f"), borderSize.X, borderSize.Y);
}
borderSize = GetCachedGeometry().GetLocalSize();
UE_LOG(LogTemp, Warning, TEXT("Cached size: %f, %f"), borderSize.X, borderSize.Y);
borderSize = GetPaintSpaceGeometry().GetLocalSize();
UE_LOG(LogTemp, Warning, TEXT("Paint size: %f, %f"), borderSize.X, borderSize.Y);
return widget;
}