// Copyright Epic Games, Inc. All Rights Reserved. #include "STableTreeViewRow.h" #include "EditorStyleSet.h" #include "SlateOptMacros.h" #include "Widgets/SOverlay.h" #include "Widgets/Images/SImage.h" // Insights #include "Insights/Common/TimeUtils.h" #include "Insights/Table/ViewModels/Table.h" #include "Insights/Table/ViewModels/TableColumn.h" #include "Insights/Table/Widgets/STableTreeViewCell.h" #include "Insights/Table/Widgets/STableTreeViewTooltip.h" #define LOCTEXT_NAMESPACE "STableTreeView" namespace Insights { //////////////////////////////////////////////////////////////////////////////////////////////////// BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void STableTreeViewRow::Construct(const FArguments& InArgs, const TSharedRef& InOwnerTableView) { OnShouldBeEnabled = InArgs._OnShouldBeEnabled; IsColumnVisibleDelegate = InArgs._OnIsColumnVisible; GetColumnOutlineHAlignmentDelegate = InArgs._OnGetColumnOutlineHAlignmentDelegate; SetHoveredCellDelegate = InArgs._OnSetHoveredCell; HighlightText = InArgs._HighlightText; HighlightedNodeName = InArgs._HighlightedNodeName; TablePtr = InArgs._TablePtr; TableTreeNodePtr = InArgs._TableTreeNodePtr; RowToolTip = MakeShared(TableTreeNodePtr); SetEnabled(TAttribute(this, &STableTreeViewRow::HandleShouldBeEnabled)); SMultiColumnTableRow::Construct(SMultiColumnTableRow::FArguments(), InOwnerTableView); } //////////////////////////////////////////////////////////////////////////////////////////////////// TSharedRef STableTreeViewRow::GenerateWidgetForColumn(const FName& ColumnId) { TSharedPtr ColumnPtr = TablePtr->FindColumnChecked(ColumnId); return SNew(SOverlay) .Visibility(EVisibility::SelfHitTestInvisible) + SOverlay::Slot() .Padding(0.0f) [SNew(SImage) .Image(FEditorStyle::GetBrush("Profiler.LineGraphArea")) .ColorAndOpacity(this, &STableTreeViewRow::GetBackgroundColorAndOpacity)] + SOverlay::Slot() .Padding(0.0f) [SNew(SImage) .Image(this, &STableTreeViewRow::GetOutlineBrush, ColumnId) .ColorAndOpacity(this, &STableTreeViewRow::GetOutlineColorAndOpacity)] + SOverlay::Slot() [SNew(STableTreeViewCell, SharedThis(this)) .Visibility(this, &STableTreeViewRow::IsColumnVisible, ColumnId) .TablePtr(TablePtr) .ColumnPtr(ColumnPtr) .TableTreeNodePtr(TableTreeNodePtr) .HighlightText(HighlightText) .IsNameColumn(ColumnPtr->IsHierarchy()) .OnSetHoveredCell(this, &STableTreeViewRow::OnSetHoveredCell)]; } END_SLATE_FUNCTION_BUILD_OPTIMIZATION //////////////////////////////////////////////////////////////////////////////////////////////////// FReply STableTreeViewRow::OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { return SMultiColumnTableRow::OnDragDetected(MyGeometry, MouseEvent); } //////////////////////////////////////////////////////////////////////////////////////////////////// TSharedRef STableTreeViewRow::GetRowToolTip() const { return RowToolTip.ToSharedRef(); } //////////////////////////////////////////////////////////////////////////////////////////////////// void STableTreeViewRow::InvalidateContent() { RowToolTip->InvalidateWidget(); } //////////////////////////////////////////////////////////////////////////////////////////////////// FSlateColor STableTreeViewRow::GetBackgroundColorAndOpacity() const { return FLinearColor(0.0f, 0.0f, 0.0f, 1.0f); } //////////////////////////////////////////////////////////////////////////////////////////////////// FSlateColor STableTreeViewRow::GetBackgroundColorAndOpacity(double Time) const { const FLinearColor Color = Time > TimeUtils::Second ? FLinearColor(0.3f, 0.0f, 0.0f, 1.0f) : Time > TimeUtils::Milisecond ? FLinearColor(0.3f, 0.1f, 0.0f, 1.0f) : Time > TimeUtils::Microsecond ? FLinearColor(0.0f, 0.1f, 0.0f, 1.0f) : FLinearColor(0.0f, 0.0f, 0.0f, 1.0f); return Color; } //////////////////////////////////////////////////////////////////////////////////////////////////// FSlateColor STableTreeViewRow::GetOutlineColorAndOpacity() const { const FLinearColor NoColor(0.0f, 0.0f, 0.0f, 0.0f); const bool bShouldBeHighlighted = TableTreeNodePtr->GetName() == HighlightedNodeName.Get(); const FLinearColor OutlineColorAndOpacity = bShouldBeHighlighted ? FLinearColor(FColorList::SlateBlue) : NoColor; return OutlineColorAndOpacity; } //////////////////////////////////////////////////////////////////////////////////////////////////// const FSlateBrush* STableTreeViewRow::GetOutlineBrush(const FName ColumnId) const { EHorizontalAlignment Result = HAlign_Center; if (IsColumnVisibleDelegate.IsBound()) { Result = GetColumnOutlineHAlignmentDelegate.Execute(ColumnId); } const FSlateBrush* Brush = nullptr; if (Result == HAlign_Left) { Brush = FEditorStyle::GetBrush("Profiler.EventGraph.Border.L"); } else if (Result == HAlign_Right) { Brush = FEditorStyle::GetBrush("Profiler.EventGraph.Border.R"); } else { Brush = FEditorStyle::GetBrush("Profiler.EventGraph.Border.TB"); } return Brush; } //////////////////////////////////////////////////////////////////////////////////////////////////// bool STableTreeViewRow::HandleShouldBeEnabled() const { bool bResult = false; if (TableTreeNodePtr->IsGroup()) { bResult = true; } else { if (OnShouldBeEnabled.IsBound()) { bResult = OnShouldBeEnabled.Execute(TableTreeNodePtr); } } return bResult; } //////////////////////////////////////////////////////////////////////////////////////////////////// EVisibility STableTreeViewRow::IsColumnVisible(const FName ColumnId) const { EVisibility Result = EVisibility::Collapsed; if (IsColumnVisibleDelegate.IsBound()) { Result = IsColumnVisibleDelegate.Execute(ColumnId) ? EVisibility::Visible : EVisibility::Collapsed; } return Result; } //////////////////////////////////////////////////////////////////////////////////////////////////// void STableTreeViewRow::OnSetHoveredCell(TSharedPtr InTablePtr, TSharedPtr InColumnPtr, FTableTreeNodePtr InTreeNodePtr) { SetHoveredCellDelegate.ExecuteIfBound(InTablePtr, InColumnPtr, InTreeNodePtr); } //////////////////////////////////////////////////////////////////////////////////////////////////// } // namespace Insights #undef LOCTEXT_NAMESPACE