EM_Task/TraceInsights/Private/Insights/NetworkingProfiler/Widgets/SNetStatsTableRow.cpp

197 lines
7.0 KiB
C++
Raw Normal View History

2026-02-13 16:18:33 +08:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "SNetStatsTableRow.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/NetworkingProfiler/Widgets/SNetStatsTableCell.h"
#include "Insights/NetworkingProfiler/Widgets/SNetStatsViewTooltip.h"
#define LOCTEXT_NAMESPACE "SNetStatsView"
////////////////////////////////////////////////////////////////////////////////////////////////////
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SNetStatsTableRow::Construct(const FArguments& InArgs, const TSharedRef<STableViewBase>& InOwnerTableView)
{
OnShouldBeEnabled = InArgs._OnShouldBeEnabled;
IsColumnVisibleDelegate = InArgs._OnIsColumnVisible;
GetColumnOutlineHAlignmentDelegate = InArgs._OnGetColumnOutlineHAlignmentDelegate;
SetHoveredCellDelegate = InArgs._OnSetHoveredCell;
HighlightText = InArgs._HighlightText;
HighlightedNodeName = InArgs._HighlightedNodeName;
TablePtr = InArgs._TablePtr;
NetEventNodePtr = InArgs._NetEventNodePtr;
RowToolTip = MakeShared<SNetEventTableRowToolTip>(NetEventNodePtr);
SetEnabled(TAttribute<bool>(this, &SNetStatsTableRow::HandleShouldBeEnabled));
SMultiColumnTableRow<FNetEventNodePtr>::Construct(SMultiColumnTableRow<FNetEventNodePtr>::FArguments(), InOwnerTableView);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TSharedRef<SWidget> SNetStatsTableRow::GenerateWidgetForColumn(const FName& ColumnId)
{
TSharedPtr<Insights::FTableColumn> ColumnPtr = TablePtr->FindColumnChecked(ColumnId);
return SNew(SOverlay)
.Visibility(EVisibility::SelfHitTestInvisible)
+ SOverlay::Slot()
.Padding(0.0f)
[SNew(SImage)
.Image(FEditorStyle::GetBrush("Profiler.LineGraphArea"))
.ColorAndOpacity(this, &SNetStatsTableRow::GetBackgroundColorAndOpacity)]
+ SOverlay::Slot()
.Padding(0.0f)
[SNew(SImage)
.Image(this, &SNetStatsTableRow::GetOutlineBrush, ColumnId)
.ColorAndOpacity(this, &SNetStatsTableRow::GetOutlineColorAndOpacity)]
+ SOverlay::Slot()
[SNew(SNetStatsTableCell, SharedThis(this))
.Visibility(this, &SNetStatsTableRow::IsColumnVisible, ColumnId)
.TablePtr(TablePtr)
.ColumnPtr(ColumnPtr)
.NetEventNodePtr(NetEventNodePtr)
.HighlightText(HighlightText)
.IsNameColumn(ColumnPtr->IsHierarchy())
.OnSetHoveredCell(this, &SNetStatsTableRow::OnSetHoveredCell)];
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
////////////////////////////////////////////////////////////////////////////////////////////////////
FReply SNetStatsTableRow::OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
return SMultiColumnTableRow<FNetEventNodePtr>::OnDragDetected(MyGeometry, MouseEvent);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TSharedRef<IToolTip> SNetStatsTableRow::GetRowToolTip() const
{
return RowToolTip.ToSharedRef();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void SNetStatsTableRow::InvalidateContent()
{
RowToolTip->InvalidateWidget();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
FSlateColor SNetStatsTableRow::GetBackgroundColorAndOpacity() const
{
return GetBackgroundColorAndOpacity(NetEventNodePtr->GetAggregatedStats().TotalInclusive);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
FSlateColor SNetStatsTableRow::GetBackgroundColorAndOpacity(uint32 Size) const
{
const FLinearColor Color = Size > 1000 ? FLinearColor(0.3f, 0.0f, 0.0f, 1.0f) :
Size > 100 ? FLinearColor(0.3f, 0.1f, 0.0f, 1.0f) :
Size > 10 ? FLinearColor(0.0f, 0.1f, 0.0f, 1.0f) :
FLinearColor(0.0f, 0.0f, 0.0f, 1.0f);
return Color;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
FSlateColor SNetStatsTableRow::GetOutlineColorAndOpacity() const
{
const FLinearColor NoColor(0.0f, 0.0f, 0.0f, 0.0f);
const bool bShouldBeHighlighted = NetEventNodePtr->GetName() == HighlightedNodeName.Get();
const FLinearColor OutlineColorAndOpacity = bShouldBeHighlighted ? FLinearColor(FColorList::SlateBlue) : NoColor;
return OutlineColorAndOpacity;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const FSlateBrush* SNetStatsTableRow::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 SNetStatsTableRow::HandleShouldBeEnabled() const
{
bool bResult = false;
if (NetEventNodePtr->IsGroup())
{
bResult = true;
}
else
{
if (OnShouldBeEnabled.IsBound())
{
bResult = OnShouldBeEnabled.Execute(NetEventNodePtr);
}
}
return bResult;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
EVisibility SNetStatsTableRow::IsColumnVisible(const FName ColumnId) const
{
EVisibility Result = EVisibility::Collapsed;
if (IsColumnVisibleDelegate.IsBound())
{
Result = IsColumnVisibleDelegate.Execute(ColumnId) ? EVisibility::Visible : EVisibility::Collapsed;
}
return Result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void SNetStatsTableRow::OnSetHoveredCell(TSharedPtr<Insights::FTable> InTablePtr, TSharedPtr<Insights::FTableColumn> InColumnPtr, FNetEventNodePtr InNetEventNodePtr)
{
SetHoveredCellDelegate.ExecuteIfBound(InTablePtr, InColumnPtr, InNetEventNodePtr);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE