Generalize UI: main menu bar with panel toggles + frame stats
Add a top menu bar (host/src/ui/app_chrome) as the overlay shell: - View menu toggles each panel (Controllers / Injection / Video / Audio) and a global "Debug details" switch (consumed by panels in a follow-up). - A right-aligned performance readout: stable 1 s FPS plus the frame-time spread (avg, min-max) so stutter is visible; it turns amber on a >25 ms spike. FrameStats keeps the rolling window. Consolidates the FPS that was duplicated in the controllers and video panels into this one readout. First structural step of the "generalize the UI" roadmap task; content rework (debug-vs-general split, renaming the spike-era readouts) follows. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
63
host/src/ui/app_chrome.cpp
Normal file
63
host/src/ui/app_chrome.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "ui/app_chrome.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace coop
|
||||
{
|
||||
|
||||
float draw_main_menu_bar(UiState& ui, const FrameStats& stats)
|
||||
{
|
||||
float height = 0.0f;
|
||||
if (!ImGui::BeginMainMenuBar())
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted("CoopAllTheThings");
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::BeginMenu("View"))
|
||||
{
|
||||
ImGui::MenuItem("Controllers", nullptr, &ui.show_controllers);
|
||||
ImGui::MenuItem("Injection", nullptr, &ui.show_injection);
|
||||
ImGui::MenuItem("Video mirror", nullptr, &ui.show_video);
|
||||
ImGui::MenuItem("Audio mirror", nullptr, &ui.show_audio);
|
||||
ImGui::Separator();
|
||||
ImGui::MenuItem("Debug details", nullptr, &ui.debug_details);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Help"))
|
||||
{
|
||||
ImGui::TextDisabled("F1 hide/show this overlay");
|
||||
ImGui::TextDisabled("Esc quit");
|
||||
ImGui::Separator();
|
||||
ImGui::TextDisabled("This window is what Remote Play");
|
||||
ImGui::TextDisabled("Together captures.");
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
// Right-aligned performance readout: stable FPS with the frame-time spread
|
||||
// (min/max over the last second) so stutter is visible at a glance.
|
||||
char perf[96];
|
||||
std::snprintf(perf, sizeof(perf), "%.0f FPS %.2f ms (%.2f-%.2f)", stats.fps(), stats.avg_ms(),
|
||||
stats.min_ms(), stats.max_ms());
|
||||
const float text_w = ImGui::CalcTextSize(perf).x;
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - text_w - ImGui::GetStyle().FramePadding.x * 2.0f);
|
||||
if (stats.max_ms() > 25.0f) // ~sub-40 FPS spike in the window
|
||||
{
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.3f, 1.0f), "%s", perf);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextUnformatted(perf);
|
||||
}
|
||||
|
||||
height = ImGui::GetWindowHeight();
|
||||
ImGui::EndMainMenuBar();
|
||||
return height;
|
||||
}
|
||||
|
||||
} // namespace coop
|
||||
Reference in New Issue
Block a user