Add an element to the top of a vertical box

Just want to add that while this method of inverting scaling works, I had other issues surrounding the scaling that made it feel a bit wonky.

Instead I looked at the VerticalBoxSlot class and made my own slot class with the build slot function recreated so that it would do the following:

void UNotificationBoxSlot::BuildSlot(const TSharedRef<SVerticalBox>& VerticalBox)
{
	const int32 ChildCount = VerticalBox->GetChildren()->Num();
	const int32 Index = ChildCount > 1 ? 0 : ChildCount - 1;
	
	VerticalBox->InsertSlot(Index)
	           .Expose(Slot)
	           .Padding(Padding)
	           .HAlign(HorizontalAlignment)
	           .VAlign(VerticalAlignment)
	           .SizeParam(UWidget::ConvertSerializedSizeParamToRuntime(Size))
	[
		Content == nullptr ? SNullWidget::NullWidget : Content->TakeWidget()
	];
}

The result below without the need to mess with inverted scaling.
ProjectIsekai_WIP_NotificationsV2

You would have to create your own panel widget to make use of the slot, which is simple enough if you follow how the VerticalBox panel widget is laid out.

Also requires being comfortable in working in C++.

Just in case anyone else came across this wondering the same thing.

1 Like