| 4702 | } |
| 4703 | |
| 4704 | void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size, const char* format, ImPlotColormapScaleFlags flags, ImPlotColormap cmap) { |
| 4705 | ImGuiContext &G = *GImGui; |
| 4706 | ImGuiWindow * Window = G.CurrentWindow; |
| 4707 | if (Window->SkipItems) |
| 4708 | return; |
| 4709 | |
| 4710 | const ImGuiID ID = Window->GetID(label); |
| 4711 | ImVec2 label_size(0,0); |
| 4712 | if (!ImHasFlag(flags, ImPlotColormapScaleFlags_NoLabel)) { |
| 4713 | label_size = ImGui::CalcTextSize(label,nullptr,true); |
| 4714 | } |
| 4715 | |
| 4716 | ImPlotContext& gp = *GImPlot; |
| 4717 | cmap = cmap == IMPLOT_AUTO ? gp.Style.Colormap : cmap; |
| 4718 | IM_ASSERT_USER_ERROR(cmap >= 0 && cmap < gp.ColormapData.Count, "Invalid colormap index!"); |
| 4719 | |
| 4720 | ImVec2 frame_size = ImGui::CalcItemSize(size, 0, gp.Style.PlotDefaultSize.y); |
| 4721 | if (frame_size.y < gp.Style.PlotMinSize.y && size.y < 0.0f) |
| 4722 | frame_size.y = gp.Style.PlotMinSize.y; |
| 4723 | |
| 4724 | ImPlotRange range(ImMin(scale_min,scale_max), ImMax(scale_min,scale_max)); |
| 4725 | gp.CTicker.Reset(); |
| 4726 | Locator_Default(gp.CTicker, range, frame_size.y, true, Formatter_Default, (void*)format); |
| 4727 | |
| 4728 | const bool rend_label = label_size.x > 0; |
| 4729 | const float txt_off = gp.Style.LabelPadding.x; |
| 4730 | const float pad = txt_off + gp.CTicker.MaxSize.x + (rend_label ? txt_off + label_size.y : 0); |
| 4731 | float bar_w = 20; |
| 4732 | if (frame_size.x == 0) |
| 4733 | frame_size.x = bar_w + pad + 2 * gp.Style.PlotPadding.x; |
| 4734 | else { |
| 4735 | bar_w = frame_size.x - (pad + 2 * gp.Style.PlotPadding.x); |
| 4736 | if (bar_w < gp.Style.MajorTickLen.y) |
| 4737 | bar_w = gp.Style.MajorTickLen.y; |
| 4738 | } |
| 4739 | |
| 4740 | ImDrawList &DrawList = *Window->DrawList; |
| 4741 | ImRect bb_frame = ImRect(Window->DC.CursorPos, Window->DC.CursorPos + frame_size); |
| 4742 | ImGui::ItemSize(bb_frame); |
| 4743 | if (!ImGui::ItemAdd(bb_frame, ID, &bb_frame)) |
| 4744 | return; |
| 4745 | |
| 4746 | ImGui::RenderFrame(bb_frame.Min, bb_frame.Max, GetStyleColorU32(ImPlotCol_FrameBg), true, G.Style.FrameRounding); |
| 4747 | |
| 4748 | const bool opposite = ImHasFlag(flags, ImPlotColormapScaleFlags_Opposite); |
| 4749 | const bool inverted = ImHasFlag(flags, ImPlotColormapScaleFlags_Invert); |
| 4750 | const bool reversed = scale_min > scale_max; |
| 4751 | |
| 4752 | float bb_grad_shift = opposite ? pad : 0; |
| 4753 | ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding + ImVec2(bb_grad_shift, 0), |
| 4754 | bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x + bb_grad_shift, |
| 4755 | frame_size.y - gp.Style.PlotPadding.y)); |
| 4756 | |
| 4757 | ImGui::PushClipRect(bb_frame.Min, bb_frame.Max, true); |
| 4758 | const ImU32 col_text = ImGui::GetColorU32(ImGuiCol_Text); |
| 4759 | |
| 4760 | const bool invert_scale = inverted ? (reversed ? false : true) : (reversed ? true : false); |
| 4761 | const float y_min = invert_scale ? bb_grad.Max.y : bb_grad.Min.y; |
no test coverage detected