GUI: add hover function to PlotCustom

allows for fixed arp macro to be displayed as notes
This commit is contained in:
tildearrow 2022-02-08 21:30:06 -05:00
parent 4756599df0
commit 27333dc812
3 changed files with 46 additions and 32 deletions

View file

@ -268,7 +268,7 @@ void PlotBitfield(const char* label, const int* values, int values_count, int va
PlotBitfieldEx(label, &Plot_IntArrayGetter, (void*)&data, values_count, values_offset, overlay_text, bits, graph_size);
}
int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight)
int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float))
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = ImGui::GetCurrentWindow();
@ -331,10 +331,14 @@ int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_gett
const float v0 = values_getter(data, (v_idx) % values_count);
const float v1 = values_getter(data, (v_idx + 1) % values_count);
if (plot_type == ImGuiPlotType_Lines)
ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx + 1, v1);
else if (plot_type == ImGuiPlotType_Histogram)
ImGui::SetTooltip("%d: %8.4g", v_idx+values_display_offset, v0);
if (hoverFunc) {
ImGui::SetTooltip("%s",hoverFunc(v_idx+values_display_offset,v0).c_str());
} else {
if (plot_type == ImGuiPlotType_Lines)
ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx + 1, v1);
else if (plot_type == ImGuiPlotType_Histogram)
ImGui::SetTooltip("%d: %8.4g", v_idx+values_display_offset, v0);
}
idx_hovered = v_idx;
}
@ -395,8 +399,8 @@ int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_gett
return idx_hovered;
}
void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight)
void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float))
{
FurnacePlotArrayGetterData data(values, stride);
PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight);
PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight, hoverFunc);
}