iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🪟

[UE5] How to Create a Slate Window with Tabs

に公開

Environment at Time of Writing

Item Version
Unreal Engine 5.6.1
OS Windows 11
Platform Windows

Overview

There are occasional opportunities to create a window using Slate.
In such cases, I often find myself wanting to separate functionality into tabs.
While looking at how other engine tools are built is the most practical approach,
honestly, digging through them can be quite tedious, so I created a simple sample and will provide a brief explanation.

What Was Created

The image below shows a nearly empty, simple window.
It contains a TextBox intended as a menu bar and two tabs.

It also includes window layout restoration, so feel free to rearrange the tab layout and restart the window.
It should open with the layout you had when you closed it.

Source Code

The code is publicly available at the link below.
To run it, create a Plugins folder in your project, clone it inside, build, and execute.
https://github.com/KTA552/UE-SlateTabWindowSample

The essential parts are in the C++ file below, so if you just want to see the code, look there.
https://github.com/KTA552/UE-SlateTabWindowSample/blob/main/Source/SlateTabWindowSample/Private/TabWindow.cpp

Steps to Create a Window with Tabs

Create a TabManager from the Created Window

There might be other ways to do this, but this is the fastest approach.
Pass the tab to Construct, then generate the TabManager from it.
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/SlateTabWindowSample.cpp#L15-L16
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L9-L11

Configure the Window Layout

Create a TabManagerLayout and configure how the layout should be arranged.
This is also where you decide whether to arrange them horizontally or vertically.
Tabs are added to the Stack created here.
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L20-L21
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L38-L47

Create and Configure Tabs

Create tabs for the defined layout and register them.
The key parts are TabManager->RegisterTabSpawner and Stack->AddTab.
Here, you register the tab and set its display options.

https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L49-L59

Configure Child Elements

Set up the child elements you want inside the window.
The important part is TabManager->RestoreFrom. This registers all the tab contents together.
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L74-L107

Configure Window Layout Restoration

This is an extra feature.
It's a sample showing how to save and restore the window layout.
Use FLayoutSaveRestore to save to config, then restore the saved layout and overwrite the TabManagerLayout.
If you do this, call it before RestoreFrom. Important.
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L13-L31
https://github.com/KTA552/UE-SlateTabWindowSample/blob/12d1c77a4d5fd93497ec5ffe9d90256455baf4c0/Source/SlateTabWindowSample/Private/TabWindow.cpp#L71-L72

Summary

Slate can be a bit intimidating at first, but once you get the hang of it, it's convenient for registering functionality in an immediate-GUI-like manner.
Since you sometimes need C++ to call engine features, you'll likely use it fairly often.
Adding tabs gives tools a more polished look, so this was an introduction to creating them.
I hope this serves as a useful reference.

GitHubで編集を提案

Discussion