Fivee

导航

UMG ScrollBox Reverse

在ScrollBox 对应的panel中, 修改 OnArrangeChildren 方法, 开放一个参数给界面配置

void SScrollPanelExt::OnArrangeChildren(const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren) const
{
    float CurChildOffset = -PhysicalOffset;

    if (bReverseDirection) // 差异就在这一段里
    {
        for (int32 SlotIndex = Children.Num() - 1; SlotIndex >= 0; --SlotIndex)
        {
            const SScrollBoxExt::FSlot& ThisSlot = Children[SlotIndex];
            const EVisibility ChildVisibility = ThisSlot.GetWidget()->GetVisibility();

            if (ChildVisibility != EVisibility::Collapsed)
            {
                if (Orientation == Orient_Vertical)
                {
                    CurChildOffset = ArrangeChildVerticalAndReturnOffset(AllottedGeometry, ArrangedChildren, ThisSlot, CurChildOffset);
                }
                else
                {
                    CurChildOffset = ArrangeChildHorizontalAndReturnOffset(AllottedGeometry, ArrangedChildren, ThisSlot, CurChildOffset);
                }
            }
        }
    }
    else {
        for (int32 SlotIndex = 0; SlotIndex < Children.Num(); ++SlotIndex)
        {
            const SScrollBoxExt::FSlot& ThisSlot = Children[SlotIndex];
            const EVisibility ChildVisibility = ThisSlot.GetWidget()->GetVisibility();

            if (ChildVisibility != EVisibility::Collapsed)
            {
                if (Orientation == Orient_Vertical)
                {
                    CurChildOffset = ArrangeChildVerticalAndReturnOffset(AllottedGeometry, ArrangedChildren, ThisSlot, CurChildOffset);
                }
                else
                {
                    CurChildOffset = ArrangeChildHorizontalAndReturnOffset(AllottedGeometry, ArrangedChildren, ThisSlot, CurChildOffset);
                }
            }
        }
    }
}

即可简单的将上下左右反转。

posted on 2021-05-11 17:59  Fivee  阅读(71)  评论(0编辑  收藏  举报