1、.Padding(10.f)等于.Padding(10.f, 10.f, 10.f, 10.f)
2、LOCTEXT("键值", "输出或显示的TEXT"):注意,键值如果相同,例如:
LOCTEXT("1", "我") //返回的是“我”
LOCTEXT("1", "你") //返回的是“我”
LOCTEXT("2", "你") //返回的是“你”
因为1最开始注册的值是我,之后用键值为1的LOCTEXT,不管你第二个参数是多少,都是和第一次注册的值是一样的
SMyCompoundWidget.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/Input/SButton.h"
/**
*
*/
class SMyCompoundWidget : public SButton
{
public:
SLATE_BEGIN_ARGS(SMyCompoundWidget)
{}
SLATE_END_ARGS()
/** Constructs this widget with InArgs */
void Construct(const FArguments& InArgs);
};
SMyCompoundWidget.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "SMyCompoundWidget.h"
#include "SlateOptMacros.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SMyCompoundWidget::Construct(const FArguments& InArgs)
{
SButton::Construct(SButton::FArguments()
.ContentPadding(FMargin(10, 5, 10, 5)));
ChildSlot
[
//SNew(SButton)
//Populate the widget
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(SButton)
]
+ SVerticalBox::Slot()
.Padding(0, 10, 0, 0)
[
SNew(SButton)
]
];
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
Inherit.cpp:
// Copyright Epic Games, Inc. All Rights Reserved.
#include "Inherit.h"
#include "InheritStyle.h"
#include "InheritCommands.h"
#include "LevelEditor.h"
#include "Widgets/Docking/SDockTab.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Text/STextBlock.h"
#include "ToolMenus.h"
#include "SMyCompoundWidget.h"
static const FName InheritTabName("Inherit");
#define LOCTEXT_NAMESPACE "FInheritModule"
void FInheritModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
FInheritStyle::Initialize();
FInheritStyle::ReloadTextures();
FInheritCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction(
FInheritCommands::Get().OpenPluginWindow,
FExecuteAction::CreateRaw(this, &FInheritModule::PluginButtonClicked),
FCanExecuteAction());
UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FInheritModule::RegisterMenus));
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(InheritTabName, FOnSpawnTab::CreateRaw(this, &FInheritModule::OnSpawnPluginTab))
.SetDisplayName(LOCTEXT("FInheritTabTitle", "Inherit"))
.SetMenuType(ETabSpawnerMenuType::Hidden);
}
void FInheritModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
UToolMenus::UnRegisterStartupCallback(this);
UToolMenus::UnregisterOwner(this);
FInheritStyle::Shutdown();
FInheritCommands::Unregister();
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(InheritTabName);
}
TSharedRef<SDockTab> FInheritModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
FText WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Add code to {0} in {1} to override this window's contents"),
FText::FromString(TEXT("FInheritModule::OnSpawnPluginTab")),
FText::FromString(TEXT("Inherit.cpp"))
);
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SAssignNew(temp, SMyCompoundWidget)
//SNew(SButton)
]
];
}
void FInheritModule::PluginButtonClicked()
{
FGlobalTabmanager::Get()->TryInvokeTab(InheritTabName);
}
void FInheritModule::RegisterMenus()
{
// Owner will be used for cleanup in call to UToolMenus::UnregisterOwner
FToolMenuOwnerScoped OwnerScoped(this);
{
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window");
{
FToolMenuSection& Section = Menu->FindOrAddSection("WindowLayout");
Section.AddMenuEntryWithCommandList(FInheritCommands::Get().OpenPluginWindow, PluginCommands);
}
}
{
UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar");
{
FToolMenuSection& Section = ToolbarMenu->FindOrAddSection("Settings");
{
FToolMenuEntry& Entry = Section.AddEntry(FToolMenuEntry::InitToolBarButton(FInheritCommands::Get().OpenPluginWindow));
Entry.SetCommandList(PluginCommands);
}
}
}
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FInheritModule, Inherit)
尽量放一个插件里面
效果如下: