ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

UE4 slateUI slot

2022-01-18 13:33:07  阅读:145  来源: 互联网

标签:slot FSlotBase return slateUI SlotType TSlotBase UE4 public const


void Construct( const FArguments& Args )
    {
        SetCanTick(false);

        this->ChildSlot
            [
                SNew(SVerticalBox)
                + SVerticalBox::Slot()
                .Padding( FMargin( 0.0f, 0.0f, 2.0f, 0.0f ) )
                [
                    FSlateApplicationBase::Get().MakeImage(
                        FSlateApplicationBase::Get().GetAppIcon(),
                        Args._IconColorAndOpacity,
                        EVisibility::HitTestInvisible
                    )
                ]
            ];
    }

slate代码这样写的,一开始学感觉很奇怪

其实这是为了减少代码而设计的.

首先这个widget继承自SCompoundWidget,这个可以有子控件,SCompoundWidget继承自SWidget,这个SWidget是基础的控件,它不可以有子控件

SCompoundWidget里面有成员 ChildSlot ,是这样定义的 FSimpleSlot ChildSlot;  这个是子控件容器

/** A slot that support alignment of content and padding */
class SLATECORE_API FSimpleSlot : public TSupportsOneChildMixin<FSimpleSlot>, public TSupportsContentAlignmentMixin<FSimpleSlot>, public TSupportsContentPaddingMixin<FSimpleSlot>
{
public:
    FSimpleSlot(SWidget* InParent)
    : TSupportsOneChildMixin<FSimpleSlot>(InParent)
    , TSupportsContentAlignmentMixin<FSimpleSlot>(HAlign_Fill, VAlign_Fill)
    {
    }
};



下面是TSupportsOneChildMixin定义

/**
 * Widgets that will only have one child can return an instance of FOneChild.
 */
template <typename MixedIntoType>
class TSupportsOneChildMixin : public FChildren, public TSlotBase<MixedIntoType>
{
public:
    TSupportsOneChildMixin(SWidget* InOwner)
        : FChildren(InOwner)
        , TSlotBase<MixedIntoType>()
    {
        this->RawParentPtr = InOwner;
    }

    virtual int32 Num() const override { return 1; }

    virtual TSharedRef<SWidget> GetChildAt( int32 ChildIndex ) override
    {
        check(ChildIndex == 0);
        return FSlotBase::GetWidget();
    }

    virtual TSharedRef<const SWidget> GetChildAt( int32 ChildIndex ) const override
    {
        check(ChildIndex == 0);
        return FSlotBase::GetWidget();
    }

private:
    virtual const FSlotBase& GetSlotAt(int32 ChildIndex) const override { check(ChildIndex == 0); return *this; }
};

而TSlotBase有重写[]  方法

template<typename SlotType>
class TSlotBase : public FSlotBase
{
public:

    TSlotBase()
    : FSlotBase()
    {}

    TSlotBase( const TSharedRef<SWidget>& InWidget )
    : FSlotBase( InWidget )
    {}

    SlotType& operator[]( const TSharedRef<SWidget>& InChildWidget )
    {
        this->AttachWidget(InChildWidget);
        return (SlotType&)(*this);
    }

    SlotType& Expose( SlotType*& OutVarToInit )
    {
        OutVarToInit = (SlotType*)this;
        return (SlotType&)(*this);
    }
};

所以有上面那个方括号里面写代码的内容,意思就是方括号里面的widget 加到子控件数组里

 

标签:slot,FSlotBase,return,slateUI,SlotType,TSlotBase,UE4,public,const
来源: https://www.cnblogs.com/dragon2012/p/15817394.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有