| 4745 | } |
| 4746 | |
| 4747 | bool ColormapButton(const char* label, const ImVec2& size_arg, ImPlotColormap cmap) { |
| 4748 | ImGuiContext &G = *GImGui; |
| 4749 | const ImGuiStyle& style = G.Style; |
| 4750 | ImGuiWindow * Window = G.CurrentWindow; |
| 4751 | if (Window->SkipItems) |
| 4752 | return false; |
| 4753 | ImPlotContext& gp = *GImPlot; |
| 4754 | cmap = cmap == IMPLOT_AUTO ? gp.Style.Colormap : cmap; |
| 4755 | IM_ASSERT_USER_ERROR(cmap >= 0 && cmap < gp.ColormapData.Count, "Invalid colormap index!"); |
| 4756 | const ImU32* keys = gp.ColormapData.GetKeys(cmap); |
| 4757 | const int count = gp.ColormapData.GetKeyCount(cmap); |
| 4758 | const bool qual = gp.ColormapData.IsQual(cmap); |
| 4759 | const ImVec2 pos = ImGui::GetCurrentWindow()->DC.CursorPos; |
| 4760 | const ImVec2 label_size = ImGui::CalcTextSize(label, nullptr, true); |
| 4761 | ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f); |
| 4762 | const ImRect rect = ImRect(pos.x,pos.y,pos.x+size.x,pos.y+size.y); |
| 4763 | RenderColorBar(keys,count,*ImGui::GetWindowDrawList(),rect,false,false,!qual); |
| 4764 | const ImU32 text = CalcTextColor(gp.ColormapData.LerpTable(cmap,G.Style.ButtonTextAlign.x)); |
| 4765 | ImGui::PushStyleColor(ImGuiCol_Button,IM_COL32_BLACK_TRANS); |
| 4766 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered,ImVec4(1,1,1,0.1f)); |
| 4767 | ImGui::PushStyleColor(ImGuiCol_ButtonActive,ImVec4(1,1,1,0.2f)); |
| 4768 | ImGui::PushStyleColor(ImGuiCol_Text,text); |
| 4769 | ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding,0); |
| 4770 | const bool pressed = ImGui::Button(label,size); |
| 4771 | ImGui::PopStyleColor(4); |
| 4772 | ImGui::PopStyleVar(1); |
| 4773 | return pressed; |
| 4774 | } |
| 4775 | |
| 4776 | //----------------------------------------------------------------------------- |
| 4777 | // [Section] Miscellaneous |
no test coverage detected