UE4 Editor Plugin UI - SCompoundWidget
UE4 Editor Plugin UI - SCompoundWidget
创建自定义Window
。
创建自定义类
示例Code
涉及的布局相关的类:SBox
,SVerticalBox
,SHorizontalBox
,SUniformGridPanel
。
输入及 显示控件类:SButton
,STextBlock
,SNumericEntryBox
。
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "Framework/Application/SlateApplication.h"
/**
*
*/
class SH3DOptionsWindow : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SH3DOptionsWindow)
{}
SLATE_ARGUMENT(TSharedPtr<SWindow>, WidgetWindow)
SLATE_END_ARGS()
/** Constructs this widget with InArgs */
void Construct(const FArguments& InArgs);
public:
bool ShouldOK() const
{
return bShouldProceed;
}
FTransform GetTransform()const {
return FTransform(Rotation.Quaternion(),Translation,Scale3D);
}
private:
TOptional<float> GetTranslationX() const{ return Translation.X;}
TOptional<float> GetTranslationY() const { return Translation.Y;}
TOptional<float> GetTranslationZ() const { return Translation.Z;}
void SetTranslationX(float X) { Translation.X = X; }
void SetTranslationY(float Y) { Translation.Y = Y; }
void SetTranslationZ(float Z) { Translation.Z = Z; }
TOptional<float> GetScale3DX()const { return Scale3D.X; }
TOptional<float> GetScale3DY()const { return Scale3D.Y; }
TOptional<float> GetScale3DZ()const { return Scale3D.Z; }
void SetScale3DX(float X) { Scale3D.X = X; }
void SetScale3DY(float Y) { Scale3D.Y = Y; }
void SetScale3DZ(float Z) { Scale3D.Z = Z; }
TOptional<float> GetRotationX()const { return Rotation.Roll; }
TOptional<float> GetRotationY()const { return Rotation.Pitch; }
TOptional<float> GetRotationZ()const { return Rotation.Yaw; }
void SetRotationX(float X) { Rotation.Roll = X; }
void SetRotationY(float Y) { Rotation.Pitch = Y; }
void SetRotationZ(float Z) { Rotation.Yaw = Z; }
FReply OnOK()
{
bShouldProceed = true;
if (Window.IsValid())
{
Window.Pin()->RequestDestroyWindow();
}
return FReply::Handled();
}
FReply OnCancel()
{
bShouldProceed = false;
if (Window.IsValid())
{
Window.Pin()->RequestDestroyWindow();
}
return FReply::Handled();
}
private:
TWeakPtr< SWindow > Window;
//others
bool bShouldProceed;
FVector Translation;
FVector Scale3D;
FRotator Rotation;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/SH3DOptionsWindow.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Layout/SUniformGridPanel.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Input/SNumericEntryBox.h"
#include "SlateOptMacros.h"
#define LOCTEXT_NAMESPACE "H3DOptionsWindow"
void SH3DOptionsWindow::Construct(const FArguments& InArgs)
{
Window = InArgs._WidgetWindow;
bShouldProceed = false;
Translation = FVector::ZeroVector;
Rotation = FRotator::ZeroRotator;
Scale3D = FVector::OneVector;
ChildSlot
[
SNew(SVerticalBox)
//第一行:
SVerticalBox::Slot()
.AutoHeight()
.Padding(0.0f, 3.0f, 0.0f, 3.0f)
[
SNew(SHorizontalBox)
SHorizontalBox::Slot()
.AutoWidth()
.Padding(3.0f, 3.0f, 10.0f, 3.0f)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.MinDesiredWidth(75)
.Text(LOCTEXT("H3DOptionsWindow_Location", "Location:"))
.ToolTipText(LOCTEXT("H3DOptionsWindow_LocationTooltip", "Location"))
]
SHorizontalBox::Slot()
.AutoWidth()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this,&SH3DOptionsWindow::GetTranslationX)
.OnValueChanged(this,&SH3DOptionsWindow::SetTranslationX)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Location_X", "X:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetTranslationY)
.OnValueChanged(this, &SH3DOptionsWindow::SetTranslationY)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Location_Y", "Y:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetTranslationZ)
.OnValueChanged(this, &SH3DOptionsWindow::SetTranslationZ)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Location_Z", "Z:"))
]
]
]
]
// 第二行
SVerticalBox::Slot()
.AutoHeight()
.Padding(0.0f, 3.0f, 0.0f, 3.0f)
[
SNew(SHorizontalBox)
SHorizontalBox::Slot()
.AutoWidth()
.Padding(3.0f, 3.0f, 10.0f, 3.0f)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.MinDesiredWidth(75)
.Text(LOCTEXT("H3DOptionsWindow_Rotation", "Rotation:"))
.ToolTipText(LOCTEXT("H3DOptionsWindow_RotationTooltip", "Rotation"))
]
SHorizontalBox::Slot()
.AutoWidth()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetRotationX)
.OnValueChanged(this, &SH3DOptionsWindow::SetRotationX)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Rotation_X", "X:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetRotationY)
.OnValueChanged(this, &SH3DOptionsWindow::SetRotationY)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Rotation_Y", "Y:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetRotationZ)
.OnValueChanged(this, &SH3DOptionsWindow::SetRotationZ)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Rotation_Z", "Z:"))
]
]
]
]
// 第三行
SVerticalBox::Slot()
.AutoHeight()
.Padding(0.0f, 3.0f, 0.0f, 3.0f)
[
SNew(SHorizontalBox)
SHorizontalBox::Slot()
.AutoWidth()
.Padding(3.0f, 3.0f, 10.0f, 3.0f)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.MinDesiredWidth(75)
.Text(LOCTEXT("H3DOptionsWindow_Scale", "Scale:"))
.ToolTipText(LOCTEXT("H3DOptionsWindow_ScaleTooltip", "Scale"))
]
SHorizontalBox::Slot()
.AutoWidth()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetScale3DX)
.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DX)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Scale_X", "X:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetScale3DY)
.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DY)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Scale_Y", "Y:"))
]
]
]
SHorizontalBox::Slot()
.Padding(0.0f, 3.0f, 8.0f, 3.0f)
.AutoWidth()
[
SNew(SNumericEntryBox<float>)
.IsEnabled(true)
.Value(this, &SH3DOptionsWindow::GetScale3DZ)
.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DZ)
.AllowSpin(true)
.MinDesiredValueWidth(75)
.Label()
[
SNew(SBox)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("H3DOptionsWindow_Scale_Z", "Z:"))
]
]
]
]
//第四行 Button 按钮
SVerticalBox::Slot()
.AutoHeight()
.Padding(0.0f, 3.0f, 0.0f, 3.0f)
[
SNew(SUniformGridPanel)
SUniformGridPanel::Slot(1, 0)
.HAlign(HAlign_Right)
[
SNew(SHorizontalBox)
SHorizontalBox::Slot()
.Padding(5, 0)
.AutoWidth()
.HAlign(HAlign_Right)
[
SNew(SButton)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
.Text(LOCTEXT("H3DOptionsWindow_OK", "OK"))
.ToolTipText(LOCTEXT("H3DOptionsWindow_OKTip", "OK"))
.OnClicked(this, &SH3DOptionsWindow::OnOK)
]
SHorizontalBox::Slot()
.Padding(5, 0)
.AutoWidth()
.HAlign(HAlign_Right)
[
SNew(SButton)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
.Text(LOCTEXT("H3DOptionsWindow_Cancel", "Cancel"))
.ToolTipText(LOCTEXT("H3DOptionsWindow_CancelTip", "Cancle"))
.OnClicked(this, &SH3DOptionsWindow::OnCancel)
]
]
]
];
}
#undef LOCTEXT_NAMESPACE
参考
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfkjfie
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01