2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Framework/MultiBox/SWidgetBlock.h"
|
|
|
|
|
#include "Widgets/SBoxPanel.h"
|
|
|
|
|
#include "Framework/MultiBox/MultiBoxBuilder.h"
|
2020-05-12 09:32:51 -04:00
|
|
|
#include "Styling/ToolBarStyle.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param InHeadingText Heading text
|
|
|
|
|
*/
|
2020-10-27 13:18:06 -04:00
|
|
|
FWidgetBlock::FWidgetBlock( TSharedRef<SWidget> InContent, const FText& InLabel, bool bInNoIndent, EHorizontalAlignment InHorizontalAlignment)
|
2014-08-01 02:25:53 -04:00
|
|
|
: FMultiBlock( nullptr, nullptr, NAME_None, EMultiBlockType::Widget )
|
2014-03-14 14:13:41 -04:00
|
|
|
, ContentWidget( InContent )
|
|
|
|
|
, Label( InLabel )
|
|
|
|
|
, bNoIndent( bInNoIndent )
|
2020-10-27 13:18:06 -04:00
|
|
|
, HorizontalAlignment(InHorizontalAlignment)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-29 20:50:34 -04:00
|
|
|
void FWidgetBlock::SetCustomMenuDelegate( FNewMenuDelegate& InCustomMenuDelegate )
|
|
|
|
|
{
|
|
|
|
|
CustomMenuDelegate = InCustomMenuDelegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void FWidgetBlock::CreateMenuEntry(FMenuBuilder& MenuBuilder) const
|
|
|
|
|
{
|
2021-03-29 20:50:34 -04:00
|
|
|
if ( CustomMenuDelegate.IsBound() )
|
|
|
|
|
{
|
|
|
|
|
CustomMenuDelegate.Execute(MenuBuilder);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FText EntryLabel = (!Label.IsEmpty()) ? Label : NSLOCTEXT("WidgetBlock", "CustomControl", "Custom Control");
|
|
|
|
|
MenuBuilder.AddWidget(ContentWidget, FText::GetEmpty(), true);
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allocates a widget for this type of MultiBlock. Override this in derived classes.
|
|
|
|
|
*
|
|
|
|
|
* @return MultiBlock widget object
|
|
|
|
|
*/
|
|
|
|
|
TSharedRef< class IMultiBlockBaseWidget > FWidgetBlock::ConstructWidget() const
|
|
|
|
|
{
|
|
|
|
|
return SNew( SWidgetBlock )
|
|
|
|
|
.Cursor(EMouseCursor::Default);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-27 13:18:06 -04:00
|
|
|
bool FWidgetBlock::GetAlignmentOverrides(EHorizontalAlignment& OutHorizontalAlignment, EVerticalAlignment& OutVerticalAlignment, bool& bOutAutoWidth) const
|
|
|
|
|
{
|
|
|
|
|
OutHorizontalAlignment = HorizontalAlignment;
|
|
|
|
|
OutVerticalAlignment = VAlign_Fill;
|
|
|
|
|
bOutAutoWidth = HorizontalAlignment != HAlign_Fill ? false : true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
/**
|
|
|
|
|
* Construct this widget
|
|
|
|
|
*
|
|
|
|
|
* @param InArgs The declaration data for this widget
|
|
|
|
|
*/
|
|
|
|
|
void SWidgetBlock::Construct( const FArguments& InArgs )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Builds this MultiBlock widget up from the MultiBlock associated with it
|
|
|
|
|
*/
|
|
|
|
|
void SWidgetBlock::BuildMultiBlockWidget(const ISlateStyle* StyleSet, const FName& StyleName)
|
|
|
|
|
{
|
2021-02-18 20:47:25 -04:00
|
|
|
TSharedPtr< const FMultiBox > MultiBox = OwnerMultiBoxWidget.Pin()->GetMultiBox();
|
2014-03-14 14:13:41 -04:00
|
|
|
TSharedRef< const FWidgetBlock > WidgetBlock = StaticCastSharedRef< const FWidgetBlock >( MultiBlock.ToSharedRef() );
|
|
|
|
|
|
2020-05-12 09:32:51 -04:00
|
|
|
// Support menus which do not have a defined widget style yet
|
2014-03-14 14:13:41 -04:00
|
|
|
bool bHasLabel = !WidgetBlock->Label.IsEmpty();
|
2020-05-12 09:32:51 -04:00
|
|
|
FMargin Padding;
|
|
|
|
|
const FTextBlockStyle* LabelStyle = nullptr;
|
|
|
|
|
if(StyleSet->HasWidgetStyle<FToolBarStyle>(StyleName))
|
|
|
|
|
{
|
|
|
|
|
const FToolBarStyle& ToolBarStyle = StyleSet->GetWidgetStyle<FToolBarStyle>(StyleName);
|
|
|
|
|
|
|
|
|
|
Padding = WidgetBlock->bNoIndent ? ToolBarStyle.BlockPadding : ToolBarStyle.IndentedBlockPadding;
|
|
|
|
|
LabelStyle = &ToolBarStyle.LabelStyle;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Padding = WidgetBlock->bNoIndent ? StyleSet->GetMargin(StyleName, ".Block.Padding") : StyleSet->GetMargin(StyleName, ".Block.IndentedPadding");
|
|
|
|
|
|
|
|
|
|
LabelStyle = &StyleSet->GetWidgetStyle<FTextBlockStyle>(ISlateStyle::Join(StyleName, ".Label"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedPtr<SMultiBoxWidget> OwnerMultiBoxWidgetPinned = OwnerMultiBoxWidget.Pin();
|
|
|
|
|
|
|
|
|
|
if(OwnerMultiBoxWidgetPinned->GetMultiBox()->GetType() == EMultiBoxType::Menu)
|
|
|
|
|
{
|
|
|
|
|
// Account for checkmark used in other menu blocks but not used in for widget rows
|
2020-12-01 13:29:07 -04:00
|
|
|
Padding = Padding + FMargin(14, 0, 8, 0);
|
2021-01-22 19:32:07 -04:00
|
|
|
|
|
|
|
|
// If there is no label, allow the custom menu widget to consume the entire space
|
|
|
|
|
if (!bHasLabel)
|
2021-02-18 20:47:25 -04:00
|
|
|
{
|
2021-01-22 19:32:07 -04:00
|
|
|
Padding = FMargin(0);
|
2021-02-18 20:47:25 -04:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-22 19:32:07 -04:00
|
|
|
|
2021-02-18 20:47:25 -04:00
|
|
|
// For searchable menus with a custom widgets without a label, find a TextBlock to connect with for search
|
|
|
|
|
// This is similar to how SMenuEntryBlock works
|
|
|
|
|
FText SearchLabel = WidgetBlock->Label;
|
|
|
|
|
TAttribute<FText> SearchHighlightText;
|
|
|
|
|
|
|
|
|
|
if( OwnerMultiBoxWidgetPinned->GetMultiBox()->GetType() == EMultiBoxType::Menu && OwnerMultiBoxWidgetPinned->GetSearchable())
|
|
|
|
|
{
|
|
|
|
|
SearchHighlightText.Bind(OwnerMultiBoxWidgetPinned.Get(), &SMultiBoxWidget::GetSearchText);
|
|
|
|
|
|
|
|
|
|
if (!bHasLabel)
|
|
|
|
|
{
|
|
|
|
|
TSharedRef<SWidget> TextBlock = FindTextBlockWidget(WidgetBlock->ContentWidget);
|
|
|
|
|
if (TextBlock != SNullWidget::NullWidget )
|
|
|
|
|
{
|
|
|
|
|
// Bind the search text to the widgets text to highlight
|
|
|
|
|
TSharedRef<STextBlock> TheTextBlock = StaticCastSharedRef<STextBlock>(TextBlock);
|
|
|
|
|
TheTextBlock->SetHighlightText(SearchHighlightText);
|
|
|
|
|
|
|
|
|
|
SearchLabel = TheTextBlock.Get().GetText();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-12 09:32:51 -04:00
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-08-26 10:33:13 -04:00
|
|
|
// Add this widget to the search list of the multibox
|
2021-02-18 20:47:25 -04:00
|
|
|
OwnerMultiBoxWidgetPinned->AddElement(this->AsWidget(), SearchLabel, MultiBlock->GetSearchable());
|
2015-08-26 10:33:13 -04:00
|
|
|
|
|
|
|
|
// This widget holds the search text, set it as the search block widget
|
2020-05-12 09:32:51 -04:00
|
|
|
if (OwnerMultiBoxWidgetPinned->GetSearchTextWidget() == WidgetBlock->ContentWidget)
|
2015-08-26 10:33:13 -04:00
|
|
|
{
|
2020-05-12 09:32:51 -04:00
|
|
|
OwnerMultiBoxWidgetPinned->SetSearchBlockWidget(this->AsWidget());
|
2015-08-26 10:33:13 -04:00
|
|
|
this->AsWidget()->SetVisibility(EVisibility::Collapsed);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
ChildSlot
|
|
|
|
|
.Padding( Padding ) // Large left margin mimics the indent of normal menu items when bNoIndent is false
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
.Visibility( bHasLabel ? EVisibility::Visible : EVisibility::Collapsed )
|
|
|
|
|
+ SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
2021-01-22 19:32:07 -04:00
|
|
|
.Padding( bHasLabel ? FMargin(0.f, 0.f, 4.f, 0.f) : FMargin(0))
|
2014-03-14 14:13:41 -04:00
|
|
|
.VAlign( VAlign_Center )
|
|
|
|
|
[
|
|
|
|
|
SNew( STextBlock )
|
2020-05-12 09:32:51 -04:00
|
|
|
.TextStyle(LabelStyle)
|
|
|
|
|
.Text(WidgetBlock->Label)
|
2021-02-18 20:47:25 -04:00
|
|
|
.HighlightText(SearchHighlightText)
|
2020-08-24 17:12:49 -04:00
|
|
|
.ColorAndOpacity(FAppStyle::Get().GetSlateColor("Colors.ForegroundHover"))
|
2014-03-14 14:13:41 -04:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
2021-08-31 12:01:38 -04:00
|
|
|
.VAlign(bHasLabel ? VAlign_Center : VAlign_Fill)
|
2014-03-14 14:13:41 -04:00
|
|
|
.FillWidth(1.f)
|
|
|
|
|
[
|
|
|
|
|
WidgetBlock->ContentWidget
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-02-18 20:47:25 -04:00
|
|
|
|
|
|
|
|
TSharedRef<SWidget> SWidgetBlock::FindTextBlockWidget( TSharedRef<SWidget> Content )
|
|
|
|
|
{
|
|
|
|
|
if (Content->GetType() == FName(TEXT("STextBlock")))
|
|
|
|
|
{
|
|
|
|
|
return Content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FChildren* Children = Content->GetChildren();
|
|
|
|
|
int32 NumChildren = Children->Num();
|
|
|
|
|
|
|
|
|
|
for( int32 Index = 0; Index < NumChildren; ++Index )
|
|
|
|
|
{
|
|
|
|
|
TSharedRef<SWidget> Found = FindTextBlockWidget( Children->GetChildAt( Index ));
|
|
|
|
|
if (Found != SNullWidget::NullWidget)
|
|
|
|
|
{
|
|
|
|
|
return Found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return SNullWidget::NullWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SWidgetBlock::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
|
|
|
|
{
|
|
|
|
|
// If this widget is in a Menu, attempt to close any other open submenus within that menu
|
|
|
|
|
TSharedPtr<SMultiBoxWidget> OwnerMultiBoxWidgetPinned = OwnerMultiBoxWidget.Pin();
|
|
|
|
|
if(OwnerMultiBoxWidgetPinned->GetMultiBox()->GetType() == EMultiBoxType::Menu)
|
|
|
|
|
{
|
|
|
|
|
const TSharedPtr< const SMenuAnchor > OpenedMenuAnchor( OwnerMultiBoxWidgetPinned->GetOpenMenu() );
|
|
|
|
|
if ( OpenedMenuAnchor.IsValid() && OpenedMenuAnchor->IsOpen() )
|
|
|
|
|
{
|
|
|
|
|
OwnerMultiBoxWidgetPinned->CloseSummonedMenus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SMultiBlockBaseWidget::OnMouseEnter(MyGeometry, MouseEvent);
|
|
|
|
|
}
|
|
|
|
|
|