From 75a14b8b4591f6f41307ad6a3a12e34cd3425a62 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 31 Jul 2021 20:21:34 +1000 Subject: [PATCH] [client] overlay/graphs: allow the window position and size to be saved This change allows the window position and size to be changed, and saved/loaded by imgui. Additionally the plots will now scale to the window size. --- client/src/overlay/graphs.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/client/src/overlay/graphs.c b/client/src/overlay/graphs.c index 44682ffc..932476ca 100644 --- a/client/src/overlay/graphs.c +++ b/client/src/overlay/graphs.c @@ -100,14 +100,23 @@ static int graphs_render(void * udata, bool interactive, ImVec2 pos = {0.0f, 0.0f}; igSetNextWindowBgAlpha(0.4f); igSetNextWindowPos(pos, ImGuiCond_FirstUseEver, pos); + igSetNextWindowSize( + (ImVec2){ + 28.0f * fontSize, + 7.0f * fontSize * ll_count(gs.graphs) + }, + ImGuiCond_FirstUseEver); - igBegin( - "Performance Metrics", - NULL, - ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | - ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar - ); + ImGuiWindowFlags flags = ImGuiWindowFlags_NoNav; + if (!interactive) + flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration; + + igBegin("Performance Metrics", NULL, flags); + + ImVec2 winSize; + igGetContentRegionAvail(&winSize); + const float height = (winSize.y / ll_count(gs.graphs)) + - igGetStyle()->ItemSpacing.y; GraphHandle graph; for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); ) @@ -124,9 +133,7 @@ static int graphs_render(void * udata, bool interactive, metrics.freq = 1000.0f / metrics.avg; } - char title[64]; - const ImVec2 size = {28.0f * fontSize, 7.0f * fontSize}; - + char title[64]; snprintf(title, sizeof(title), "%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz", graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq); @@ -139,7 +146,7 @@ static int graphs_render(void * udata, bool interactive, title, graph->min, graph->max, - size, + (ImVec2){ winSize.x, height }, sizeof(float)); };