| 4825 | } |
| 4826 | |
| 4827 | bool ColormapButton(const char* label, const ImVec2& size_arg, ImPlotColormap cmap) { |
| 4828 | ImGuiContext &G = *GImGui; |
| 4829 | const ImGuiStyle& style = G.Style; |
| 4830 | ImGuiWindow * Window = G.CurrentWindow; |
| 4831 | if (Window->SkipItems) |
| 4832 | return false; |
| 4833 | ImPlotContext& gp = *GImPlot; |
| 4834 | cmap = cmap == IMPLOT_AUTO ? gp.Style.Colormap : cmap; |
| 4835 | IM_ASSERT_USER_ERROR(cmap >= 0 && cmap < gp.ColormapData.Count, "Invalid colormap index!"); |
| 4836 | const ImU32* keys = gp.ColormapData.GetKeys(cmap); |
| 4837 | const int count = gp.ColormapData.GetKeyCount(cmap); |
| 4838 | const bool qual = gp.ColormapData.IsQual(cmap); |
| 4839 | const ImVec2 pos = ImGui::GetCurrentWindow()->DC.CursorPos; |
| 4840 | const ImVec2 label_size = ImGui::CalcTextSize(label, nullptr, true); |
| 4841 | ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f); |
| 4842 | const ImRect rect = ImRect(pos.x,pos.y,pos.x+size.x,pos.y+size.y); |
| 4843 | RenderColorBar(keys,count,*ImGui::GetWindowDrawList(),rect,false,false,!qual); |
| 4844 | const ImU32 text = CalcTextColor(gp.ColormapData.LerpTable(cmap,G.Style.ButtonTextAlign.x)); |
| 4845 | ImGui::PushStyleColor(ImGuiCol_Button,IM_COL32_BLACK_TRANS); |
| 4846 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered,ImVec4(1,1,1,0.1f)); |
| 4847 | ImGui::PushStyleColor(ImGuiCol_ButtonActive,ImVec4(1,1,1,0.2f)); |
| 4848 | ImGui::PushStyleColor(ImGuiCol_Text,text); |
| 4849 | ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding,0); |
| 4850 | const bool pressed = ImGui::Button(label,size); |
| 4851 | ImGui::PopStyleColor(4); |
| 4852 | ImGui::PopStyleVar(1); |
| 4853 | return pressed; |
| 4854 | } |
| 4855 | |
| 4856 | //----------------------------------------------------------------------------- |
| 4857 | // [Section] Miscellaneous |
no test coverage detected