MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / PlotEx

Method PlotEx

lib/imgui/imgui_widgets.cpp:5861–5973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5859//-------------------------------------------------------------------------
5860
5861void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size)
5862{
5863 ImGuiWindow* window = GetCurrentWindow();
5864 if (window->SkipItems)
5865 return;
5866
5867 ImGuiContext& g = *GImGui;
5868 const ImGuiStyle& style = g.Style;
5869 const ImGuiID id = window->GetID(label);
5870
5871 const ImVec2 label_size = CalcTextSize(label, NULL, true);
5872 if (frame_size.x == 0.0f)
5873 frame_size.x = CalcItemWidth();
5874 if (frame_size.y == 0.0f)
5875 frame_size.y = label_size.y + (style.FramePadding.y * 2);
5876
5877 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
5878 const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
5879 const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
5880 ItemSize(total_bb, style.FramePadding.y);
5881 if (!ItemAdd(total_bb, 0, &frame_bb))
5882 return;
5883 const bool hovered = ItemHoverable(frame_bb, id);
5884
5885 // Determine scale from values if not specified
5886 if (scale_min == FLT_MAX || scale_max == FLT_MAX)
5887 {
5888 float v_min = FLT_MAX;
5889 float v_max = -FLT_MAX;
5890 for (int i = 0; i < values_count; i++)
5891 {
5892 const float v = values_getter(data, i);
5893 if (v != v) // Ignore NaN values
5894 continue;
5895 v_min = ImMin(v_min, v);
5896 v_max = ImMax(v_max, v);
5897 }
5898 if (scale_min == FLT_MAX)
5899 scale_min = v_min;
5900 if (scale_max == FLT_MAX)
5901 scale_max = v_max;
5902 }
5903
5904 RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
5905
5906 const int values_count_min = (plot_type == ImGuiPlotType_Lines) ? 2 : 1;
5907 if (values_count >= values_count_min)
5908 {
5909 int res_w = ImMin((int)frame_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
5910 int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
5911
5912 // Tooltip on hover
5913 int v_hovered = -1;
5914 if (hovered && inner_bb.Contains(g.IO.MousePos))
5915 {
5916 const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
5917 const int v_idx = (int)(t * item_count);
5918 IM_ASSERT(v_idx >= 0 && v_idx < values_count);

Callers

nothing calls this directly

Calls 11

GetCurrentWindowFunction · 0.85
ImVec2Class · 0.85
ItemSizeClass · 0.85
ImMinFunction · 0.85
ImMaxFunction · 0.85
ImClampFunction · 0.85
ImSaturateFunction · 0.85
ImLerpFunction · 0.85
AddLineMethod · 0.80
AddRectFilledMethod · 0.80
GetIDMethod · 0.45

Tested by

no test coverage detected