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:
83
host/src/ui/app_chrome.hpp
Normal file
83
host/src/ui/app_chrome.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Top-level overlay chrome shared across panels: which panels are visible, the
|
||||
// global "show debug details" switch, rolling frame-timing stats, and the main
|
||||
// menu bar that drives them. Keeping this in one place lets the individual panels
|
||||
// stay focused on their own pipeline while presenting a consistent shell.
|
||||
#pragma once
|
||||
|
||||
namespace coop
|
||||
{
|
||||
|
||||
// Visibility + verbosity shared by all panels. Panels read `debug_details` to
|
||||
// gate verbose diagnostics; the main loop reads the per-panel flags to decide
|
||||
// what to draw.
|
||||
struct UiState
|
||||
{
|
||||
bool show_controllers = true;
|
||||
bool show_injection = true;
|
||||
bool show_video = true;
|
||||
bool show_audio = true;
|
||||
bool debug_details = false; // off = general status; on = full diagnostics
|
||||
};
|
||||
|
||||
// Rolling frame-timing over a ~1 s window, recomputed each window so the status
|
||||
// bar can show a stable FPS plus the min/max frame time (jitter) underneath it.
|
||||
class FrameStats
|
||||
{
|
||||
public:
|
||||
void tick(float dt_ms)
|
||||
{
|
||||
if (dt_ms < cur_min_)
|
||||
{
|
||||
cur_min_ = dt_ms;
|
||||
}
|
||||
if (dt_ms > cur_max_)
|
||||
{
|
||||
cur_max_ = dt_ms;
|
||||
}
|
||||
accum_ms_ += dt_ms;
|
||||
++frames_;
|
||||
if (accum_ms_ >= 1000.0f && frames_ > 0)
|
||||
{
|
||||
avg_ms_ = accum_ms_ / static_cast<float>(frames_);
|
||||
min_ms_ = cur_min_;
|
||||
max_ms_ = cur_max_;
|
||||
cur_min_ = 1.0e9f;
|
||||
cur_max_ = 0.0f;
|
||||
accum_ms_ = 0.0f;
|
||||
frames_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] float avg_ms() const
|
||||
{
|
||||
return avg_ms_;
|
||||
}
|
||||
[[nodiscard]] float min_ms() const
|
||||
{
|
||||
return min_ms_;
|
||||
}
|
||||
[[nodiscard]] float max_ms() const
|
||||
{
|
||||
return max_ms_;
|
||||
}
|
||||
[[nodiscard]] float fps() const
|
||||
{
|
||||
return avg_ms_ > 0.0f ? 1000.0f / avg_ms_ : 0.0f;
|
||||
}
|
||||
|
||||
private:
|
||||
float accum_ms_ = 0.0f;
|
||||
int frames_ = 0;
|
||||
float cur_min_ = 1.0e9f;
|
||||
float cur_max_ = 0.0f;
|
||||
float avg_ms_ = 0.0f;
|
||||
float min_ms_ = 0.0f;
|
||||
float max_ms_ = 0.0f;
|
||||
};
|
||||
|
||||
// Draw the main menu bar (app name, View menu of panel toggles + debug switch,
|
||||
// and a right-aligned FPS readout). Returns the menu bar height so the caller can
|
||||
// keep panels clear of it on first layout.
|
||||
float draw_main_menu_bar(UiState& ui, const FrameStats& stats);
|
||||
|
||||
} // namespace coop
|
||||
Reference in New Issue
Block a user