[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.
This commit is contained in:
Geoffrey McRae 2021-07-31 20:21:34 +10:00
parent b0c1714777
commit 75a14b8b45

View file

@ -100,14 +100,23 @@ static int graphs_render(void * udata, bool interactive,
ImVec2 pos = {0.0f, 0.0f}; ImVec2 pos = {0.0f, 0.0f};
igSetNextWindowBgAlpha(0.4f); igSetNextWindowBgAlpha(0.4f);
igSetNextWindowPos(pos, ImGuiCond_FirstUseEver, pos); igSetNextWindowPos(pos, ImGuiCond_FirstUseEver, pos);
igSetNextWindowSize(
(ImVec2){
28.0f * fontSize,
7.0f * fontSize * ll_count(gs.graphs)
},
ImGuiCond_FirstUseEver);
igBegin( ImGuiWindowFlags flags = ImGuiWindowFlags_NoNav;
"Performance Metrics", if (!interactive)
NULL, flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration;
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | igBegin("Performance Metrics", NULL, flags);
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar
); ImVec2 winSize;
igGetContentRegionAvail(&winSize);
const float height = (winSize.y / ll_count(gs.graphs))
- igGetStyle()->ItemSpacing.y;
GraphHandle graph; GraphHandle graph;
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&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; metrics.freq = 1000.0f / metrics.avg;
} }
char title[64]; char title[64];
const ImVec2 size = {28.0f * fontSize, 7.0f * fontSize};
snprintf(title, sizeof(title), snprintf(title, sizeof(title),
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz", "%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq); graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq);
@ -139,7 +146,7 @@ static int graphs_render(void * udata, bool interactive,
title, title,
graph->min, graph->min,
graph->max, graph->max,
size, (ImVec2){ winSize.x, height },
sizeof(float)); sizeof(float));
}; };