UE5 slate BlankProgram独立程序系列

ops/2024/11/25 13:08:50/

源码版Engine\Source\Programs\中copy BlankProgram文件夹,重命名为ASlateLearning,修改所有文件命名及内部名称。

ASlateLearning.Target.cs

// Copyright Epic Games, Inc. All Rights Reserved.using UnrealBuildTool;
using System.Collections.Generic;[SupportedPlatforms(UnrealPlatformClass.All)]
public class ASlateLearningTarget : TargetRules
{public ASlateLearningTarget(TargetInfo Target) : base(Target){Type = TargetType.Program;IncludeOrderVersion = EngineIncludeOrderVersion.Latest;LinkType = TargetLinkType.Monolithic;LaunchModuleName = "ASlateLearning";bBuildDeveloperTools = false;bool bDebugOrDevelopment = Target.Configuration == UnrealTargetConfiguration.Debug || Target.Configuration == UnrealTargetConfiguration.Development;//bBuildWithEditorOnlyData = Target.Platform.IsInGroup(UnrealPlatformGroup.Desktop) && bDebugOrDevelopment;bBuildWithEditorOnlyData = true;bCompileAgainstEngine = false;bCompileAgainstCoreUObject = true;bCompileAgainstApplicationCore = true;bCompileICU = false;bIsBuildingConsoleApplication = true;}
}

ASlateLearning.Build.cs

// Copyright Epic Games, Inc. All Rights Reserved.using UnrealBuildTool;public class ASlateLearning : ModuleRules
{public ASlateLearning(ReadOnlyTargetRules Target) : base(Target){PublicIncludePaths.Add("Runtime/Launch/Public");PrivateIncludePaths.Add("Runtime/Launch/Private");PrivateDependencyModuleNames.AddRange(new string[]{"AppFramework","Core","ApplicationCore","Projects","Slate","SlateCore","StandaloneRenderer",});}
}

 ASlateLearning.cpp

// Copyright Epic Games, Inc. All Rights Reserved.#include "ASlateLearning.h"#include "RequiredProgramMainCPPInclude.h"
#include "StandaloneRenderer.h"DEFINE_LOG_CATEGORY_STATIC(LogASlateLearning, Log, All);IMPLEMENT_APPLICATION(LogASlateLearning, "ASlateLearning");INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
{GEngineLoop.PreInit(ArgC, ArgV);FSlateApplication::InitializeAsStandaloneApplication(GetStandardStandaloneRenderer());FSlateApplication::InitHighDPI(true);const TSharedPtr<SWindow> MainWindow = SNew(SWindow).ClientSize(FVector2D(800, 600));FSlateApplication::Get().AddWindow(MainWindow.ToSharedRef());while (!IsEngineExitRequested()){BeginExitIfRequested();FSlateApplication::Get().PumpMessages();FSlateApplication::Get().Tick();}FEngineLoop::AppExit();return 0;
}

运行后会出现创建的窗口,后面继续扩展

// Copyright Epic Games, Inc. All Rights Reserved.#include "ASlateLearning.h"#include "RequiredProgramMainCPPInclude.h"
#include "StandaloneRenderer.h"DEFINE_LOG_CATEGORY_STATIC(LogASlateLearning, Log, All);IMPLEMENT_APPLICATION(LogASlateLearning, "ASlateLearning");INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
{GEngineLoop.PreInit(ArgC, ArgV);FSlateApplication::InitializeAsStandaloneApplication(GetStandardStandaloneRenderer());FSlateApplication::InitHighDPI(true);const TSharedPtr<SWindow> MainWindow = SNew(SWindow).ClientSize(FVector2D(800, 600))[SNew(SHorizontalBox) + SHorizontalBox::Slot()[SNew(SButton).Text(NSLOCTEXT("L10N", "Key", "Button Content"))]];FSlateApplication::Get().AddWindow(MainWindow.ToSharedRef());while (!IsEngineExitRequested()){BeginExitIfRequested();FSlateApplication::Get().PumpMessages();FSlateApplication::Get().Tick();}FEngineLoop::AppExit();return 0;
}

运行后窗口样式,button太大因为Slot默认的对其策略是HAlign::Fill,VAlign::Fill,调整后的这部分代码应该是

 使用SOverlay::FOverlaySlot* Slot;个Slot的指针,用.Expose(Slot)获取指针,Expose方法填入一个插槽指针并将其返回,此后,我们通过APi可以获得一个SWidget的引用,此时的代码应该是这样了

// Copyright Epic Games, Inc. All Rights Reserved.#include "ASlateLearning.h"#include "RequiredProgramMainCPPInclude.h"
#include "StandaloneRenderer.h"DEFINE_LOG_CATEGORY_STATIC(LogASlateLearning, Log, All);IMPLEMENT_APPLICATION(LogASlateLearning, "ASlateLearning");INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
{GEngineLoop.PreInit(ArgC, ArgV);FSlateApplication::InitializeAsStandaloneApplication(GetStandardStandaloneRenderer());FSlateApplication::InitHighDPI(true);SOverlay::FOverlaySlot* Slot;const TSharedPtr<SWindow> MainWindow = SNew(SWindow).ClientSize(FVector2D(800, 600))[SNew(SOverlay)+ SOverlay::Slot().HAlign(HAlign_Left).VAlign(VAlign_Top).Expose(Slot)[SNew(SHorizontalBox)+ SHorizontalBox::Slot().HAlign(HAlign_Left).VAlign(VAlign_Top)[SNew(SButton).Text(NSLOCTEXT("L10N", "Key", "Button Content"))]]];SWidget& slotwidget = Slot->GetWidget().Get();SHorizontalBox& HorizontalBox = static_cast<SHorizontalBox&>(slotwidget);for (int i = 0; i <5;++i){HorizontalBox.AddSlot()[SNew(SHorizontalBox)+ SHorizontalBox::Slot().HAlign(HAlign_Left).VAlign(VAlign_Top)[SNew(SButton).Text(NSLOCTEXT("L10N", "Key", "Button Content"))]];}FSlateApplication::Get().AddWindow(MainWindow.ToSharedRef());while (!IsEngineExitRequested()){BeginExitIfRequested();FSlateApplication::Get().PumpMessages();FSlateApplication::Get().Tick();}FEngineLoop::AppExit();return 0;
}

 运行后的窗口变成了

 可以为每个Button添加一些方法,通过OnClicked_Lambda之类的方法

 


http://www.ppmy.cn/ops/136575.html

相关文章

Java的包装类及其缓存机制

Java的包装类及其缓存机制 ​ Java 的包装类&#xff08;Wrapper Classes&#xff09;是为每种基本数据类型提供的对象表示。基本数据类型&#xff08;如 int、double 等&#xff09;是非对象类型&#xff0c;而包装类为它们提供了对应的对象版本&#xff0c;以便可以在需要对…

手撕一个阻塞队列

目录 手撕一个阻塞队列代码讲解 手撕一个阻塞队列 要手撕一个阻塞队列&#xff1a;就要实现一个普通的队列&#xff0c;加上阻塞&#xff0c;加上锁 代码 class MyBlockingQueue{private String[] elemsnull;private int tail0;private int head0;private int size0;private…

鸿蒙NEXT开发-Navigation组件导航

注意&#xff1a;博主有个鸿蒙专栏&#xff0c;里面从上到下有关于鸿蒙next的教学文档&#xff0c;大家感兴趣可以学习下 如果大家觉得博主文章写的好的话&#xff0c;可以点下关注&#xff0c;博主会一直更新鸿蒙next相关知识 专栏地址: https://blog.csdn.net/qq_56760790/…

OmniDiskSweeper :一款专为 macOS 设计的磁盘使用分析工具

OmniDiskSweeper 是一款专为 macOS 设计的磁盘使用分析工具&#xff0c;由 The Omni Group 开发。它的主要目的是帮助用户可视化磁盘上的文件和文件夹&#xff0c;并找出占用大量空间的文件&#xff0c;从而帮助用户释放磁盘空间。 OmniDiskSweeper 的特点包括&#xff1a; 简…

【反向迭代器】—— 我与C++的不解之缘(十七)

前言 ​ 在STL中的迭代器部分&#xff0c;之前只关注与正向迭代器&#xff0c;忽视了反向迭代器&#xff1b;现在来看一下反向迭代器到底是个什么东西&#xff0c;以及反向迭代器怎么实现&#xff0c;怎么为之前自己模拟实现的容器增加反向迭代器&#xff1f; 反向迭代器的使用…

windows vscode C++ 简明教程

windows vscode C++ 简明教程 1 安装mingw64 MinGW-w64(Minimalist GNU for Windows 64)是一个开源工具集,用于在 Windows 系统上编译和生成原生的 Windows 应用程序。它是 MinGW 项目的扩展版本,支持 32 位和 64 位 Windows 程序开发。MinGW-w64 提供了 Windows 版的 GN…

归并排序与逆序对问题(C语言版)

一、引言 归并排序是一种高效且稳定的排序方法&#xff0c;而逆序对问题是算法领域的一个经典问题&#xff0c;本文教大家如何实现归并排序&#xff0c;以及如何使用归并排序去结果逆序对问题 二、归并排序 归并排序思想 分解&#xff1a;将待排序的数组分成两半&#xff0c…

windows11下git与 openssl要注意的问题

看了一下自己贴文的历史&#xff0c;有一条重要的忘了写了。 当时帮有位同事配置gitlab&#xff0c;众说周知gitlab是不太好操作。 但我还是自认自己git还是相当熟的。 解决了一系列问题&#xff0c;如配置代理&#xff0c;sshkey&#xff0c;私有库&#xff0c;等等&#xff0…