Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Private/SEditorViewportToolBarButton.cpp
Lauren Barnes 6248f8d412 Replacing legacy EditorStyle calls with AppStyle
#preflight 6272a74d2f6d177be3c6fdda
#rb Matt.Kuhlenschmidt

#ROBOMERGE-OWNER: Lauren.Barnes
#ROBOMERGE-AUTHOR: lauren.barnes
#ROBOMERGE-SOURCE: CL 20057269 via CL 20070159 via CL 20072035 via CL 20072203
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)
#ROBOMERGE-CONFLICT from-shelf

[CL 20105363 by Lauren Barnes in ue5-main branch]
2022-05-09 13:12:28 -04:00

103 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SEditorViewportToolBarButton.h"
#include "Styling/SlateTypes.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Input/SCheckBox.h"
#include "Styling/AppStyle.h"
void SEditorViewportToolBarButton::Construct( const FArguments& Declaration)
{
OnClickedDelegate = Declaration._OnClicked;
IsChecked = Declaration._IsChecked;
const TSharedRef<SWidget>& ContentSlotWidget = Declaration._Content.Widget;
bool bContentOverride = ContentSlotWidget != SNullWidget::NullWidget;
EUserInterfaceActionType ButtonType = Declaration._ButtonType;
// The style of the image to show in the button
const FName ImageStyleName = Declaration._Image.Get();
TSharedPtr<SWidget> ButtonWidget;
if( ButtonType == EUserInterfaceActionType::Button )
{
const FSlateBrush* Brush = FAppStyle::GetBrush( ImageStyleName );
ButtonWidget =
SNew( SButton )
.ButtonStyle(Declaration._ButtonStyle)
.OnClicked( OnClickedDelegate )
.HAlign( HAlign_Center )
.VAlign( VAlign_Center )
.ContentPadding(FMargin(4.f, 0.f))
[
// If we have a content override use it instead of the default image
bContentOverride
? ContentSlotWidget
: TSharedRef<SWidget>( SNew( SImage ) .Image( Brush ) )
];
}
else
{
// Cache off checked/unchecked image states
NormalBrush = FAppStyle::GetBrush( ImageStyleName, ".Normal" );
CheckedBrush = FAppStyle::GetBrush( ImageStyleName, ".Checked" );
if( CheckedBrush->GetResourceName() == FName("Default") )
{
// A different checked brush was not specified so use the normal image when checked
CheckedBrush = NormalBrush;
}
ButtonWidget =
SNew( SCheckBox )
.Style(Declaration._CheckBoxStyle)
.OnCheckStateChanged( this, &SEditorViewportToolBarButton::OnCheckStateChanged )
.IsChecked( this, &SEditorViewportToolBarButton::OnIsChecked )
[
bContentOverride ? ContentSlotWidget :
TSharedRef<SWidget>(
SNew( SBox )
.Padding(0.0f)
.VAlign( VAlign_Center )
.HAlign( HAlign_Center )
[
SNew( SImage )
.Image( this, &SEditorViewportToolBarButton::OnGetButtonImage )
.ColorAndOpacity(FSlateColor::UseForeground())
])
];
}
ChildSlot
[
ButtonWidget.ToSharedRef()
];
}
void SEditorViewportToolBarButton::OnCheckStateChanged( ECheckBoxState NewCheckedState )
{
// When the check state changes (can only happen during clicking in this case) execute our on clicked delegate
if(OnClickedDelegate.IsBound() == true)
{
OnClickedDelegate.Execute();
}
}
const FSlateBrush* SEditorViewportToolBarButton::OnGetButtonImage() const
{
return IsChecked.Get() == true ? CheckedBrush : NormalBrush;
}
ECheckBoxState SEditorViewportToolBarButton::OnIsChecked() const
{
return IsChecked.Get() == true ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}