| 4622 | } |
| 4623 | |
| 4624 | void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size, const char* format, ImPlotColormapScaleFlags flags, ImPlotColormap cmap) { |
| 4625 | ImGuiContext &G = *GImGui; |
| 4626 | ImGuiWindow * Window = G.CurrentWindow; |
| 4627 | if (Window->SkipItems) |
| 4628 | return; |
| 4629 | |
| 4630 | const ImGuiID ID = Window->GetID(label); |
| 4631 | ImVec2 label_size(0,0); |
| 4632 | if (!ImHasFlag(flags, ImPlotColormapScaleFlags_NoLabel)) { |
| 4633 | label_size = ImGui::CalcTextSize(label,nullptr,true); |
| 4634 | } |
| 4635 | |
| 4636 | ImPlotContext& gp = *GImPlot; |
| 4637 | cmap = cmap == IMPLOT_AUTO ? gp.Style.Colormap : cmap; |
| 4638 | IM_ASSERT_USER_ERROR(cmap >= 0 && cmap < gp.ColormapData.Count, "Invalid colormap index!"); |
| 4639 | |
| 4640 | ImVec2 frame_size = ImGui::CalcItemSize(size, 0, gp.Style.PlotDefaultSize.y); |
| 4641 | if (frame_size.y < gp.Style.PlotMinSize.y && size.y < 0.0f) |
| 4642 | frame_size.y = gp.Style.PlotMinSize.y; |
| 4643 | |
| 4644 | ImPlotRange range(ImMin(scale_min,scale_max), ImMax(scale_min,scale_max)); |
| 4645 | gp.CTicker.Reset(); |
| 4646 | Locator_Default(gp.CTicker, range, frame_size.y, true, Formatter_Default, (void*)format); |
| 4647 | |
| 4648 | const bool rend_label = label_size.x > 0; |
| 4649 | const float txt_off = gp.Style.LabelPadding.x; |
| 4650 | const float pad = txt_off + gp.CTicker.MaxSize.x + (rend_label ? txt_off + label_size.y : 0); |
| 4651 | float bar_w = 20; |
| 4652 | if (frame_size.x == 0) |
| 4653 | frame_size.x = bar_w + pad + 2 * gp.Style.PlotPadding.x; |
| 4654 | else { |
| 4655 | bar_w = frame_size.x - (pad + 2 * gp.Style.PlotPadding.x); |
| 4656 | if (bar_w < gp.Style.MajorTickLen.y) |
| 4657 | bar_w = gp.Style.MajorTickLen.y; |
| 4658 | } |
| 4659 | |
| 4660 | ImDrawList &DrawList = *Window->DrawList; |
| 4661 | ImRect bb_frame = ImRect(Window->DC.CursorPos, Window->DC.CursorPos + frame_size); |
| 4662 | ImGui::ItemSize(bb_frame); |
| 4663 | if (!ImGui::ItemAdd(bb_frame, ID, &bb_frame)) |
| 4664 | return; |
| 4665 | |
| 4666 | ImGui::RenderFrame(bb_frame.Min, bb_frame.Max, GetStyleColorU32(ImPlotCol_FrameBg), true, G.Style.FrameRounding); |
| 4667 | |
| 4668 | const bool opposite = ImHasFlag(flags, ImPlotColormapScaleFlags_Opposite); |
| 4669 | const bool inverted = ImHasFlag(flags, ImPlotColormapScaleFlags_Invert); |
| 4670 | const bool reversed = scale_min > scale_max; |
| 4671 | |
| 4672 | float bb_grad_shift = opposite ? pad : 0; |
| 4673 | ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding + ImVec2(bb_grad_shift, 0), |
| 4674 | bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x + bb_grad_shift, |
| 4675 | frame_size.y - gp.Style.PlotPadding.y)); |
| 4676 | |
| 4677 | ImGui::PushClipRect(bb_frame.Min, bb_frame.Max, true); |
| 4678 | const ImU32 col_text = ImGui::GetColorU32(ImGuiCol_Text); |
| 4679 | |
| 4680 | const bool invert_scale = inverted ? (reversed ? false : true) : (reversed ? true : false); |
| 4681 | const float y_min = invert_scale ? bb_grad.Max.y : bb_grad.Min.y; |
no test coverage detected