Day 0

作者: 蛋求疼 | 来源:发表于2018-04-08 15:39 被阅读0次

    1. SlateCore\SlotBase.h
    class SLATECORE_API FSlotBase  // widget槽位, 每个槽位可拥有一个widget实例
    {
      FORCEINLINE_DEBUGGABLE void AttachWidget( const TSharedRef<SWidget>& InWidget )
      {
          Widget = InWidget;
      }
    
      /**
       * Access the widget in the current slot.
       * There will always be a widget in the slot; sometimes it is
       * the SNullWidget instance.
       */
      FORCEINLINE_DEBUGGABLE const TSharedRef<SWidget>& GetWidget() const
      {
          return Widget;
      }
    
      /**
       * Remove the widget from its current slot.
       * The removed widget is returned so that operations could be performed on it.
       * If the null widget was being stored, an invalid shared ptr is returned instead.
       */
      const TSharedPtr<SWidget> DetachWidget();
    private:
      /**
       *
       * Widget IS NOW PRIVATE!
       *
       */
      TSharedRef<SWidget> Widget;
    };
    
    template<typename SlotType>
    class TSlotBase : public FSlotBase;
    
    

    问题列表:

    • 为何要TSlotBase,FSlotBase的子类是否拥有更多的槽位属性.
    1. SlateCore\Public\Widgets\DeclarativeSyntaxSupport.h
      该文件时为了实现声明式编写ui而定义一些宏和类,声明式语法如下
            //The Maximize/Minimize button is only displayed when not in Immersive mode.
            SNew( SEditorViewportToolBarButton )
              .Cursor( EMouseCursor::Default )
              .ButtonType( EUserInterfaceActionType::ToggleButton )
              .IsChecked( ViewportRef, &SLevelViewport::IsMaximized )
              .OnClicked( ViewportRef, &SLevelViewport::OnToggleMaximize )
              .Visibility( ViewportRef, &SLevelViewport::GetMaximizeToggleVisibility )
              .Image( "LevelViewportToolBar.Maximize" )
              .ToolTipText( LOCTEXT("Maximize_ToolTip", "Maximizes or restores this viewport") )
    

    宏定义:

    /**
     * Slate widgets are constructed through SNew and SAssignNew.
     * e.g.
     *      
     *     TSharedRef<SButton> MyButton = SNew(SButton);
     *        or
     *     TSharedPtr<SButton> MyButton;
     *     SAssignNew( MyButton, SButton );
     *
     * Using SNew and SAssignNew ensures that widgets are populated
     */
    
    #define SNew( WidgetType, ... ) \
        MakeTDecl<WidgetType>( #WidgetType, __FILE__, __LINE__, RequiredArgs::MakeRequiredArgs(__VA_ARGS__) ) <<= TYPENAME_OUTSIDE_TEMPLATE WidgetType::FArguments()
    
    
    #define SAssignNew( ExposeAs, WidgetType, ... ) \
        MakeTDecl<WidgetType>( #WidgetType, __FILE__, __LINE__, RequiredArgs::MakeRequiredArgs(__VA_ARGS__) ) . Expose( ExposeAs ) <<= TYPENAME_OUTSIDE_TEMPLATE WidgetType::FArguments()
    

    其中每种类型的Widget都有自己的WidgetType::FArguments,作为初始化新实例的参数。

    TDecl封装了构造Widget实例和初始化操作:

    /**
     * Utility class used during widget instantiation.
     * Performs widget allocation and construction.
     * Ensures that debug info is set correctly.
     * Returns TSharedRef to widget.
     *
     * @see SNew
     * @see SAssignNew
     */
    template<class WidgetType, typename RequiredArgsPayloadType>
    struct TDecl
    {
        TDecl( const ANSICHAR* InType, const ANSICHAR* InFile, int32 OnLine, RequiredArgsPayloadType&& InRequiredArgs )
            : _Widget( TWidgetAllocator<WidgetType, TIsDerivedFrom<WidgetType, SUserWidget>::IsDerived >::PrivateAllocateWidget() )
            , _RequiredArgs(InRequiredArgs)
        {
            _Widget->SetDebugInfo( InType, InFile, OnLine );
        }
    
        /**
         * Initialize OutVarToInit with the widget that is being constructed.
         * @see SAssignNew
         */
        template<class ExposeAsWidgetType>
        TDecl& Expose( TSharedPtr<ExposeAsWidgetType>& OutVarToInit )
        {
            OutVarToInit = _Widget;
            return *this;
        }
    
        /**
         * Initialize OutVarToInit with the widget that is being constructed.
         * @see SAssignNew
         */
        template<class ExposeAsWidgetType>
        TDecl& Expose( TSharedRef<ExposeAsWidgetType>& OutVarToInit )
        {
            OutVarToInit = _Widget;
            return *this;
        }
    
        /**
         * Initialize a WEAK OutVarToInit with the widget that is being constructed.
         * @see SAssignNew
         */
        template<class ExposeAsWidgetType>
        TDecl& Expose( TWeakPtr<ExposeAsWidgetType>& OutVarToInit )
        {
            OutVarToInit = _Widget;
            return *this;
        }
    
        /**
         * Complete widget construction from InArgs.
         *
         * @param InArgs  NamedArguments from which to construct the widget.
         *
         * @return A reference to the widget that we constructed.
         */
            // 注意:该重载函数在宏中的应用.
        TSharedRef<WidgetType> operator<<=( const typename WidgetType::FArguments& InArgs ) const
        {
            //@todo UMG: This should be removed in favor of all widgets calling their superclass construct.
            _Widget->SWidgetConstruct(
                InArgs._ToolTipText,
                InArgs._ToolTip ,
                InArgs._Cursor ,
                InArgs._IsEnabled ,
                InArgs._Visibility,
                InArgs._RenderTransform,
                InArgs._RenderTransformPivot,
                InArgs._Tag,
                InArgs._ForceVolatile,
                InArgs._Clipping,
                InArgs.MetaData );
    
                    // 这里传递用户自定义类的参数, 和 FArguments的参数
            _RequiredArgs.CallConstruct(_Widget, InArgs);
    
            return _Widget;
        }
    
        const TSharedRef<WidgetType> _Widget;
        RequiredArgsPayloadType& _RequiredArgs;
    };
    
    1. SlateCore\Public\Widgets\IToolTip.h
      工具提示接口, 目前还不知道如何使用。
    /**
     * Interface for tool tips.
     */
    class IToolTip
    {
    public:
    
        /**
         * Gets the widget that this tool tip represents.
         *
         * @return The tool tip widget.
         */
        virtual TSharedRef<class SWidget> AsWidget( ) = 0;
    
        /**
         * Gets the tool tip's content widget.
         *
         * @return The content widget.
         */
        virtual TSharedRef<SWidget> GetContentWidget( ) = 0;
    
        /**
         * Sets the tool tip's content widget.
         *
         * @param InContentWidget The new content widget to set.
         */
        virtual void SetContentWidget( const TSharedRef<SWidget>& InContentWidget ) = 0;
    
        /**
         * Checks whether this tool tip has no content to display right now.
         *
         * @return true if the tool tip has no content to display, false otherwise.
         */
        virtual bool IsEmpty( ) const = 0;
    
        /**
         * Checks whether this tool tip can be made interactive by the user (by holding Ctrl).
         *
         * @return true if it is an interactive tool tip, false otherwise.
         */
        virtual bool IsInteractive( ) const = 0;
    
        /**
         * Called when the tooltip widget is about to be requested for opening.
         */
        virtual void OnOpening( ) = 0;
    
        /**
         * Called when the tooltip widget is closed and the tooltip is no longer needed.
         */
        virtual void OnClosed( ) = 0;
    
    public:
    
        /** Virtual destructor. */
        virtual ~IToolTip( ) { }
    };
    

    相关文章

      网友评论

          本文标题:Day 0

          本文链接:https://www.haomeiwen.com/subject/ktnphftx.html