- SlateCore\Public\Widgets\SOverlay.h
/**
* Implements an overlay widget.
*
* Overlay widgets allow for layering several widgets on top of each other.
* Each slot of an overlay represents a layer that can contain one widget.
* The slots will be rendered on top of each other in the order they are declared in code.
*
* Usage:
* SNew(SOverlay)
* + SOverlay::Slot(SNew(SMyWidget1))
* + SOverlay::Slot(SNew(SMyWidget2))
* + SOverlay::Slot(SNew(SMyWidget3))
*
* Note that SWidget3 will be drawn on top of SWidget2 and SWidget1.
*/
class SLATECORE_API SOverlay
: public SPanel
{
public:
/** A slot that support alignment of content and padding and z-order */
class SLATECORE_API FOverlaySlot : public TSlotBase<FOverlaySlot>
{
public:
FOverlaySlot()
: TSlotBase<FOverlaySlot>()
, ZOrder(0)
, HAlignment(HAlign_Fill)
, VAlignment(VAlign_Fill)
, SlotPadding(0.0f)
{ }
FOverlaySlot& HAlign( EHorizontalAlignment InHAlignment )
{
HAlignment = InHAlignment;
return *this;
}
FOverlaySlot& VAlign( EVerticalAlignment InVAlignment )
{
VAlignment = InVAlignment;
return *this;
}
FOverlaySlot& Padding(float Uniform)
{
SlotPadding = FMargin(Uniform);
return *this;
}
FOverlaySlot& Padding(float Horizontal, float Vertical)
{
SlotPadding = FMargin(Horizontal, Vertical);
return *this;
}
FOverlaySlot& Padding(float Left, float Top, float Right, float Bottom)
{
SlotPadding = FMargin(Left, Top, Right, Bottom);
return *this;
}
FOverlaySlot& Padding( const TAttribute<FMargin> InPadding )
{
SlotPadding = InPadding;
return *this;
}
/** Slots with larger ZOrder values will draw above slots with smaller ZOrder values. Slots
with the same ZOrder will simply draw in the order they were added. Currently this only
works for overlay slots that are added dynamically with AddWidget() and RemoveWidget() */
int32 ZOrder;
TEnumAsByte<EHorizontalAlignment> HAlignment;
TEnumAsByte<EVerticalAlignment> VAlignment;
TAttribute< FMargin > SlotPadding;
};
SLATE_BEGIN_ARGS( SOverlay )
{
_Visibility = EVisibility::SelfHitTestInvisible;
}
SLATE_SUPPORTS_SLOT( SOverlay::FOverlaySlot )
SLATE_END_ARGS()
SOverlay();
/**
* Construct this widget.
*
* @param InArgs The declaration data for this widget
*/
void Construct( const FArguments& InArgs );
/** Returns the number of child widgets */
int32 GetNumWidgets() const;
/**
* Removes a widget from this overlay.
*
* @param Widget The widget content to remove
*/
bool RemoveSlot( TSharedRef< SWidget > Widget );
/** Adds a slot at the specified location (ignores Z-order) */
FOverlaySlot& AddSlot(int32 ZOrder=INDEX_NONE);
/** Removes a slot at the specified location */
void RemoveSlot(int32 ZOrder=INDEX_NONE);
/** Removes all children from the overlay */
void ClearChildren();
/** @return a new slot. Slots contain children for SOverlay */
static FOverlaySlot& Slot()
{
return *(new FOverlaySlot());
}
// SWidget interface
virtual void OnArrangeChildren( const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren ) const override;
virtual FChildren* GetChildren() override;
virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override;
// End of SWidget interface
protected:
// Begin SWidget overrides.
virtual FVector2D ComputeDesiredSize(float) const override;
// End SWidget overrides.
protected:
/** The SOverlay's slots; each slot contains a child widget. */
TPanelChildren<FOverlaySlot> Children;
};
SOverlay按照上下层布局子widgets。在这里我们看到FOverlaySlot,该Slot类型定义了子Widget的布局属性。
问题列表:
FMargin是什么概念
SlateCore\Public\Widgets\SNullWidget.h
/**
* Implements a widget that can be used as a placeholder.
*
* Widgets that support slots, such as SOverlay and SHorizontalBox should initialize
* their slots' child widgets to SNullWidget if no user defined widget was provided.
*/
class SLATECORE_API SNullWidget
{
public:
/**
* Returns a placeholder widget.
*
* @return The widget.
*/
static TSharedRef<class SWidget> NullWidget;
};
空Widget, 起到占位作用,啥也不干。
- StateCore\Public\Widgets\SLeafWidget.h
/**
* Implements a leaf widget.
*
* A LeafWidget is a Widget that has no slots for children.
* LeafWidgets are usually intended as building blocks for aggregate widgets.
*/
class SLATECORE_API SLeafWidget
: public SWidget
{
public:
SLeafWidget()
{
bCanHaveChildren = false;
}
virtual void SetVisibility( TAttribute<EVisibility> InVisibility ) override final;
private:
// Begin SWidget overrides
/**
* Overwritten from SWidget.
*
* LeafWidgets provide a visual representation of themselves. They do so by adding DrawElement(s)
* to the OutDrawElements. DrawElements should have their positions set to absolute coordinates in
* Window space; for this purpose the Slate system provides the AllottedGeometry parameter.
* AllottedGeometry describes the space allocated for the visualization of this widget.
*
* Whenever possible, LeafWidgets should avoid dealing with layout properties. See TextBlock for an example.
*/
virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override = 0;
/**
* Overwritten from SWidget.
*
* LeafWidgets should compute their DesiredSize based solely on their visual representation. There is no need to
* take child widgets into account as LeafWidgets have none by definition. For example, the TextBlock widget simply
* measures the area necessary to display its text with the given font and font size.
*/
virtual FVector2D ComputeDesiredSize(float) const override = 0;
/**
* Overwritten from SWidget.
*
* Leaf widgets never have children.
*/
virtual FChildren* GetChildren() override;
virtual void OnArrangeChildren( const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren ) const override;
private:
// Shared instance of FNoChildren for all widgets with no children.
static FNoChildren NoChildrenInstance;
};
叶子Widget,没有子Widget.
- SlateCore\Public\Widgets\SBoxPanel.h
/**
* A BoxPanel contains one child and describes how that child should be arranged on the screen.
*/
class SLATECORE_API SBoxPanel : public SPanel;
/** A Horizontal Box Panel. See SBoxPanel for more info. */
class SLATECORE_API SHorizontalBox : public SBoxPanel
/** A Vertical Box Panel. See SBoxPanel for more info. */
class SLATECORE_API SVerticalBox : public SBoxPanel;
/** A Vertical Box Panel. See SBoxPanel for more info. */
class SLATECORE_API SDragAndDropVerticalBox : public SVerticalBox
- SlateCore\Public\Widgets\SCompoundWidget.h
/**
* A CompoundWidget is the base from which most non-primitive widgets should be built.
* CompoundWidgets have a protected member named ChildSlot.
*/
class SLATECORE_API SCompoundWidget : public SWidget
{
public:
/**
* Returns the size scaling factor for this widget.
*
* @return Size scaling factor.
*/
const FVector2D GetContentScale() const
{
return ContentScale.Get();
}
/**
* Sets the content scale for this widget.
*
* @param InContentScale Content scaling factor.
*/
void SetContentScale( const TAttribute< FVector2D >& InContentScale )
{
ContentScale = InContentScale;
}
/**
* Gets the widget's color.
*/
FLinearColor GetColorAndOpacity() const
{
return ColorAndOpacity.Get();
}
/**
* Sets the widget's color.
*
* @param InColorAndOpacity The ColorAndOpacity to be applied to this widget and all its contents.
*/
void SetColorAndOpacity( const TAttribute<FLinearColor>& InColorAndOpacity )
{
ColorAndOpacity = InColorAndOpacity;
}
/**
* Sets the widget's foreground color.
*
* @param InColor The color to set.
*/
void SetForegroundColor( const TAttribute<FSlateColor>& InForegroundColor )
{
ForegroundColor = InForegroundColor;
}
public:
// SWidgetOverrides
virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override;
virtual FChildren* GetChildren() override;
virtual void OnArrangeChildren( const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren ) const override;
virtual FSlateColor GetForegroundColor() const override;
public:
virtual void SetVisibility( TAttribute<EVisibility> InVisibility ) override final;
protected:
// Begin SWidget overrides.
virtual FVector2D ComputeDesiredSize(float) const override;
// End SWidget overrides.
protected:
/** Disallow public construction */
SCompoundWidget();
/** The slot that contains this widget's descendants.*/
FSimpleSlot ChildSlot;
/** The layout scale to apply to this widget's contents; useful for animation. */
TAttribute<FVector2D> ContentScale;
/** The color and opacity to apply to this widget and all its descendants. */
TAttribute<FLinearColor> ColorAndOpacity;
/** Optional foreground color that will be inherited by all of this widget's contents */
TAttribute<FSlateColor> ForegroundColor;
};
- SlateCore\Public\Widgets\SUserWidget.h
/**
* Use SUserWidget as a base class to build aggregate widgets that are not meant
* to serve as low-level building blocks. Examples include: a main menu, a user card,
* an info dialog for a selected object, a splash screen.
*
* See SUserWidgetExample
*
* SMyWidget.h
* -----------
* class SMyWidget : public SUserWidget
* {
* public:
* SLATE_USER_ARGS( SMyWidget )
* {}
* SLATE_END_ARGS()
*
* // MUST Provide this function for SNew to call!
* virtual void Construct( const FArguments& InArgs ) = 0;
*
* virtual void DoSomething() = 0;
* };
*
* SMyWidget.cpp
* -------------
* namespace Implementation
* {
* class SMyWidget : public ::SMyWidget
* {
* public:
* virtual void Construct( const FArguments& InArgs ) override
* {
* SUserWidget::Construct( SUserWidget::FArguments()
* [
* SNew(STextBlock)
* .Text( NSLOCTEXT("x", "x", "My Widget's Content") )
* ]
* }
*
* private:
* // Private implementation details can occur here
* // without ever leaking out into the .h file!
* }
* }
*
* TSharedRef<SMyWidget> SMyWidget::New()
* {
* return MakeShareable( new SMyWidget() );
* }
*/
class SUserWidget : public SCompoundWidget
{
public:
struct FArguments : public TSlateBaseNamedArgs<SUserWidget>
{
typedef FArguments WidgetArgsType;
FORCENOINLINE FArguments()
: _Content()
, _HAlign(HAlign_Fill)
, _VAlign(VAlign_Fill)
{}
SLATE_DEFAULT_SLOT( FArguments, Content )
SLATE_ARGUMENT( EHorizontalAlignment, HAlign )
SLATE_ARGUMENT( EVerticalAlignment, VAlign )
};
protected:
void Construct( const FArguments& InArgs )
{
this->ChildSlot
.HAlign( InArgs._HAlign )
.VAlign( InArgs._VAlign )
[
InArgs._Content.Widget
];
}
protected:
/** User widgets can be allocated explicitly in the C++ */
void* operator new ( const size_t InSize )
{
return FMemory::Malloc(InSize);
}
};