CogEngine: Improve plot window UI

Make docking of plots optional
This commit is contained in:
Arnaud Jamin
2025-01-14 23:36:41 -05:00
parent c561f4b92d
commit 5eee7c9903
2 changed files with 119 additions and 88 deletions
@@ -47,8 +47,19 @@ void FCogEngineWindow_Plots::RenderContent()
{ {
Super::RenderContent(); Super::RenderContent();
TArray<FCogDebugPlotEntry*> VisiblePlots;
for (FCogDebugPlotEntry& Plot : FCogDebugPlot::Plots)
{
if (Plot.CurrentYAxis != ImAxis_COUNT && Plot.CurrentRow != INDEX_NONE)
{
VisiblePlots.Add(&Plot);
}
}
RenderMenu(); RenderMenu();
if (Config->DockPlotList)
{
if (ImGui::BeginTable("PlotTable", 2, ImGuiTableFlags_RowBg if (ImGui::BeginTable("PlotTable", 2, ImGuiTableFlags_RowBg
| ImGuiTableFlags_Resizable | ImGuiTableFlags_Resizable
| ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersV
@@ -60,10 +71,9 @@ void FCogEngineWindow_Plots::RenderContent()
ImGui::TableSetupColumn("Plots", ImGuiTableColumnFlags_WidthStretch, 0.0f); ImGui::TableSetupColumn("Plots", ImGuiTableColumnFlags_WidthStretch, 0.0f);
ImGui::TableNextRow(); ImGui::TableNextRow();
TArray<FCogDebugPlotEntry*> VisiblePlots;
ImGui::TableNextColumn(); ImGui::TableNextColumn();
RenderPlotsList(VisiblePlots); RenderPlotsList(ImVec2(0, -1));
ImGui::TableNextColumn(); ImGui::TableNextColumn();
RenderPlots(VisiblePlots); RenderPlots(VisiblePlots);
@@ -71,6 +81,12 @@ void FCogEngineWindow_Plots::RenderContent()
ImGui::EndTable(); ImGui::EndTable();
} }
}
else
{
RenderPlots(VisiblePlots);
}
bApplyTimeScale = false; bApplyTimeScale = false;
} }
@@ -79,6 +95,15 @@ void FCogEngineWindow_Plots::RenderMenu()
{ {
if (ImGui::BeginMenuBar()) if (ImGui::BeginMenuBar())
{ {
if (Config->DockPlotList == false)
{
if (ImGui::BeginMenu("Plots"))
{
RenderPlotsList(ImVec2(ImGui::GetFontSize() * 15, ImGui::GetFontSize() * 20));
ImGui::EndMenu();
}
}
if (ImGui::BeginMenu("Options")) if (ImGui::BeginMenu("Options"))
{ {
if (ImGui::MenuItem("Clear data")) if (ImGui::MenuItem("Clear data"))
@@ -119,6 +144,9 @@ void FCogEngineWindow_Plots::RenderMenu()
FCogWindowWidgets::SetNextItemToShortWidth(); FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Show value at cursor", &Config->ShowValueAtCursor); ImGui::Checkbox("Show value at cursor", &Config->ShowValueAtCursor);
FCogWindowWidgets::SetNextItemToShortWidth();
ImGui::Checkbox("Dock plots", &Config->DockPlotList);
constexpr ImGuiColorEditFlags ColorEditFlags = ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf; constexpr ImGuiColorEditFlags ColorEditFlags = ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf;
FCogImguiHelper::ColorEdit4("Pause background color", Config->PauseBackgroundColor, ColorEditFlags); FCogImguiHelper::ColorEdit4("Pause background color", Config->PauseBackgroundColor, ColorEditFlags);
ImGui::SetItemTooltip("Background color of the plot when paused."); ImGui::SetItemTooltip("Background color of the plot when paused.");
@@ -133,9 +161,9 @@ void FCogEngineWindow_Plots::RenderMenu()
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::RenderPlotsList(TArray<FCogDebugPlotEntry*>& VisiblePlots) void FCogEngineWindow_Plots::RenderPlotsList(const ImVec2& InSize)
{ {
if (ImGui::BeginChild("Plots", ImVec2(0, -1))) if (ImGui::BeginChild("Plots", InSize))
{ {
int Index = 0; int Index = 0;
@@ -143,11 +171,6 @@ void FCogEngineWindow_Plots::RenderPlotsList(TArray<FCogDebugPlotEntry*>& Visibl
for (FCogDebugPlotEntry& Plot : FCogDebugPlot::Plots) for (FCogDebugPlotEntry& Plot : FCogDebugPlot::Plots)
{ {
if (Plot.CurrentYAxis != ImAxis_COUNT && Plot.CurrentRow != INDEX_NONE)
{
VisiblePlots.Add(&Plot);
}
ImGui::PushID(Index); ImGui::PushID(Index);
ImGui::PushStyleColor(ImGuiCol_Text, Plot.IsEventPlot ? IM_COL32(128, 128, 255, 255) : IM_COL32(255, 255, 255, 255)); ImGui::PushStyleColor(ImGuiCol_Text, Plot.IsEventPlot ? IM_COL32(128, 128, 255, 255) : IM_COL32(255, 255, 255, 255));
@@ -451,7 +474,8 @@ void FCogEngineWindow_Plots::RenderValues(FCogDebugPlotEntry& Entry, const char*
float Value; float Value;
if (Entry.FindValue(ImPlot::GetPlotMousePos().x, Value)) if (Entry.FindValue(ImPlot::GetPlotMousePos().x, Value))
{ {
FCogWindowWidgets::BeginTableTooltip(); if (FCogWindowWidgets::BeginTableTooltip())
{
if (ImGui::BeginTable("Params", 2, ImGuiTableFlags_Borders)) if (ImGui::BeginTable("Params", 2, ImGuiTableFlags_Borders))
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
@@ -464,6 +488,7 @@ void FCogEngineWindow_Plots::RenderValues(FCogDebugPlotEntry& Entry, const char*
FCogWindowWidgets::EndTableTooltip(); FCogWindowWidgets::EndTableTooltip();
} }
} }
}
if (Entry.ShowValuesMarkers) if (Entry.ShowValuesMarkers)
{ {
@@ -567,7 +592,8 @@ void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugPlotEvent* Hovere
{ {
if (ImPlot::IsPlotHovered() && HoveredEvent != nullptr) if (ImPlot::IsPlotHovered() && HoveredEvent != nullptr)
{ {
FCogWindowWidgets::BeginTableTooltip(); if (FCogWindowWidgets::BeginTableTooltip())
{
if (ImGui::BeginTable("Params", 2, ImGuiTableFlags_Borders)) if (ImGui::BeginTable("Params", 2, ImGuiTableFlags_Borders))
{ {
//------------------------ //------------------------
@@ -635,4 +661,5 @@ void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugPlotEvent* Hovere
} }
FCogWindowWidgets::EndTableTooltip(); FCogWindowWidgets::EndTableTooltip();
} }
}
} }
@@ -26,7 +26,7 @@ protected:
virtual void RenderContent() override; virtual void RenderContent() override;
static void RenderPlotsList(TArray<FCogDebugPlotEntry*>& VisiblePlots); static void RenderPlotsList(const ImVec2& InSize);
void RenderPlots(const TArray<FCogDebugPlotEntry*>& VisiblePlots) const; void RenderPlots(const TArray<FCogDebugPlotEntry*>& VisiblePlots) const;
@@ -75,6 +75,9 @@ public:
UPROPERTY(Config) UPROPERTY(Config)
FColor PauseBackgroundColor = FColor(10, 0, 0, 255); FColor PauseBackgroundColor = FColor(10, 0, 0, 255);
UPROPERTY(Config)
bool DockPlotList = false;
virtual void Reset() override virtual void Reset() override
{ {
Rows = 1; Rows = 1;
@@ -84,5 +87,6 @@ public:
ShowValueAtCursor = true; ShowValueAtCursor = true;
DragViewSensitivity = 10.0f; DragViewSensitivity = 10.0f;
PauseBackgroundColor = FColor(10, 0, 0, 255); PauseBackgroundColor = FColor(10, 0, 0, 255);
DockPlotList = false;
} }
}; };