ue5 c++ slate代码 FSlateIcon Icon 如何设置大小
时间: 2024-05-13 11:13:27 浏览: 244
要设置Slate图标的大小,您可以使用FSlateIcon的SetWidth和SetHeight方法。例如,以下是将图标大小设置为64x64像素的示例代码:
```
FSlateIcon Icon = FSlateIcon(FEditorStyle::GetStyleSetName(), "MyIcon");
Icon.SetWidth(64);
Icon.SetHeight(64);
```
请注意,某些Slate图标可能具有固定大小,因此您可能无法更改其大小。
相关问题
ue5 c++ slate 添加一个输入框
可以使用以下代码来添加一个输入框:
```cpp
TSharedPtr<SEditableTextBox> TextBox;
SAssignNew(TextBox, SEditableTextBox)
.IsReadOnly(false)
.OnTextChanged(this, &SMyWidget::OnTextChanged);
```
其中,`SMyWidget::OnTextChanged` 是一个回调函数,它将在文本框的文本发生变化时被调用。你可以在这个回调函数中处理文本框的输入。
ue5 c++ slate插件中资源查看的上下文菜单扩展 完整代码
下面是一个示例的完整代码,它可以在Slate插件中添加资源查看的上下文菜单扩展:
```cpp
#include "MySlateModule.h"
#include "MyAsset.h"
#include "MyAssetEditor.h"
#include "MyAssetActions.h"
#define LOCTEXT_NAMESPACE "MySlateModule"
void FMySlateModule::StartupModule()
{
// 注册资源类型
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
TSharedPtr<IAssetTypeActions> AssetTypeActions = MakeShareable(new FMyAssetActions);
AssetTools.RegisterAssetTypeActions(AssetTypeActions.ToSharedRef());
// 添加上下文菜单扩展
if (UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>())
{
FAssetEditorExtenderDelegate AssetEditorExtenderDelegate = FAssetEditorExtenderDelegate::CreateRaw(this, &FMySlateModule::AddAssetEditorContextMenuExtender);
AssetEditorSubsystem->OnExtendersChanged().AddRaw(this, &FMySlateModule::OnAssetEditorExtendersChanged);
AssetEditorSubsystem->AddAssetEditorContextMenuExtender(AssetEditorExtenderDelegate);
}
}
void FMySlateModule::ShutdownModule()
{
// 取消注册资源类型
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
for (TSharedPtr<IAssetTypeActions>& AssetTypeActions : AssetTools.GetAllAssetTypeActions())
{
AssetTools.UnregisterAssetTypeActions(AssetTypeActions.ToSharedRef());
}
// 移除上下文菜单扩展
if (UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>())
{
AssetEditorSubsystem->OnExtendersChanged().RemoveAll(this);
AssetEditorSubsystem->RemoveAssetEditorContextMenuExtender(AssetEditorContextMenuExtenderDelegateHandle);
}
}
void FMySlateModule::AddAssetEditorContextMenuExtender(UObject* Object, UBlueprintEditor* Editor, TArray<FExtender>& Extenders)
{
if (UMyAsset* MyAsset = Cast<UMyAsset>(Object))
{
TSharedPtr<FExtender> Extender = MakeShareable(new FExtender);
Extender->AddMenuExtension(
"AssetEditorActions",
EExtensionHook::After,
nullptr,
FMenuExtensionDelegate::CreateRaw(this, &FMySlateModule::AddAssetEditorContextMenuExtension, MyAsset)
);
Extenders.Add(Extender.ToSharedRef());
}
}
void FMySlateModule::AddAssetEditorContextMenuExtension(FMenuBuilder& MenuBuilder, UMyAsset* MyAsset)
{
MenuBuilder.BeginSection("MyAssetSection", LOCTEXT("MyAssetSectionLabel", "My Asset"));
{
MenuBuilder.AddMenuEntry(
LOCTEXT("MyAssetViewSource", "View Source"),
LOCTEXT("MyAssetViewSourceTooltip", "View the source code for this asset."),
FSlateIcon(),
FUIAction(
FExecuteAction::CreateRaw(this, &FMySlateModule::OnViewSourceClicked, MyAsset),
FCanExecuteAction::CreateLambda([]() { return true; })
),
NAME_None,
EUserInterfaceActionType::Button
);
}
MenuBuilder.EndSection();
}
void FMySlateModule::OnAssetEditorExtendersChanged()
{
if (UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>())
{
AssetEditorContextMenuExtenderDelegateHandle = AssetEditorSubsystem->GetAssetEditorContextMenuExtender(GetModularFeatureName(), FName("BlueprintEditor")).GetHandle();
}
}
void FMySlateModule::OnViewSourceClicked(UMyAsset* MyAsset)
{
// 打开资源的源代码编辑器
FMyAssetEditor::CreateEditor(EToolkitMode::Standalone, nullptr, MyAsset);
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FMySlateModule, MySlateModule)
阅读全文