Custom editor windows are useful when you have a new tool with user-configurable settings, or want to display some information to people using your customized editor.
Be sure to have an editor module by following the recipe earlier in this chapter before you start.
Read through either the Creating new menu entries or Creating new toolbar buttons recipes so that you can create a button within the editor that will launch our new window.
TSharedRef<SWindow> CookbookWindow = SNew(SWindow) .Title(FText::FromString(TEXT("Cookbook Window"))) .ClientSize(FVector2D(800, 400)) .SupportsMaximize(false) .SupportsMinimize(false) [ SNew(SVerticalBox) +SVerticalBox::Slot() .HAlign(HAlign_Center) .VAlign(VAlign_Center) [ SNew(STextBlock) .Text(FText::FromString(TEXT("Hello from Slate"))) ] ]; IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame")); if (MainFrameModule.GetParentWindow().IsValid()) { FSlateApplication::Get().AddWindowAsNativeChild(CookbookWindow, MainFrameModule.GetParentWindow().ToSharedRef()); } else { FSlateApplication::Get().AddWindow(CookbookWindow); }
TSharedRef< >
or TSharedPtr< >
.SNew()
function returns a TSharedRef
templated on the requested widget class.<Widget>.Property(Value).Property(Value)
.[]
) can be used to specify the content to be placed inside the widget, for example, a picture or label inside a button.SWindow
is a top-level widget with only one slot for child widgets, so we don't need to add a slot for it ourselves. We place content into that slot by creating it inside the pair of brackets.SVerticalBox
, which is a widget that can have an arbitrary number of slots for child widgets that are displayed in a vertical list.+
operator and the SVerticalBox::Slot()
function.Slot()
returns a widget like any other, so we can set properties on it like we did on our SWindow
.HAlign
and VAlign
.Slot
has a single child widget, and it's created inside the []
operators just as for SWindow
.Slot
content, we create a text block with some custom text.SWindow
now has its child widgets added, but it isn't being displayed yet, because it isn't added to the window hierarchy.3.135.247.188