UE4 Slate教程3——Slate类型介绍

Slate类图
如上图所示,Slate控件主要分为三类:SCompoundWidget、SPanel、SLeafWidget,下面将一一讲解。

SCompoundWidget

SCompoundWidget对应于UMG中的“WidgetBlueprint(控件蓝图)”,用来作为控件容器。当我们在C++类向导中创建Slate类时,创建的就是SCompoundWidget。
可以通过成员ChildSlot结合重载的[]操作符往控件里面添加其他控件,例如教程1中:

void SStandardSlateWidget::Construct(const FArguments& InArgs)
{	
	ChildSlot
	[
		SNew(STextBlock)
		.Font(FSlateFontInfo("Veranda", 100))
		.Text(NSLOCTEXT("HelloSlate", "HelloSlateText", "Hello, Slate!"))
	];
}

此外,最常用的SButton控件也属于SCompoundWidget,可以使用Content函数结合重载的[]操作符添加其他控件:

void SStandardSlateWidget::Construct(const FArguments& InArgs)
{	
	ChildSlot
	[
		SNew(SButton)
		.Content()
		[
			SNew(STextBlock)
			.Font(FSlateFontInfo("Veranda", 100))
			.Text(NSLOCTEXT("HelloSlate", "HelloSlateText", "Hello, Slate!"))
		]
	];
	
}

效果如下(白色区域是一个超大的SButton):
SButton

SPanel

SPanel对应于UMG中的Panel分组:
UMGPanel分组
SPanel用来设置布局,使用Slot添加多个子控件(SCompoundWidget只能添加1个子控件)。那么何为Slot呢?Slot即为UMG中的插槽,假设UMG的层级如下:
UMG层级
选中“Button_49”,可以在其细节面板中看到:
Slo
即为SPanel子布局的属性,包括Padding、Size、Horizontal Align、Vertical Align。
使用Slot添加子控件可以使用“+ Slot()”,也可以调用AddSlot函数,还是以教程1中的SStandardSlateWidget为例:

void SStandardSlateWidget::Construct(const FArguments& InArgs)
{	
	ChildSlot
	[
		SAssignNew(VerticalBoxPtr, SVerticalBox)

		+ SVerticalBox::Slot()
		.Padding(1.0)
		.FillHeight(0.3f)
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Top)
		[
			SNew(SButton)
		]

		+ SVerticalBox::Slot()
		.FillHeight(0.5f)
		.HAlign(HAlign_Center)
		[
			SNew(SButton)
		]
	];

	VerticalBoxPtr->AddSlot()
		.FillHeight(0.2f)
		[
			SNew(SButton)
		];
}

效果如下:
VerticalBox示例

SLeafWidget

叶子控件,故名思意,该控件不能添加子控件。
常用的为STextBlock与SImage。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值