ImageButton() is flawed as 'id' is always derived from 'texture_id' (see #2464 #1390) We provide this internal helper to write your own variant while we figure out how to redesign the public ImageButton() API.
| 1040 | // ImageButton() is flawed as 'id' is always derived from 'texture_id' (see #2464 #1390) |
| 1041 | // We provide this internal helper to write your own variant while we figure out how to redesign the public ImageButton() API. |
| 1042 | bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col) |
| 1043 | { |
| 1044 | ImGuiContext& g = *GImGui; |
| 1045 | ImGuiWindow* window = GetCurrentWindow(); |
| 1046 | if (window->SkipItems) |
| 1047 | return false; |
| 1048 | |
| 1049 | const ImVec2 padding = g.Style.FramePadding; |
| 1050 | const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2.0f); |
| 1051 | ItemSize(bb); |
| 1052 | if (!ItemAdd(bb, id)) |
| 1053 | return false; |
| 1054 | |
| 1055 | bool hovered, held; |
| 1056 | bool pressed = ButtonBehavior(bb, id, &hovered, &held); |
| 1057 | |
| 1058 | // Render |
| 1059 | const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); |
| 1060 | RenderNavHighlight(bb, id); |
| 1061 | RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, g.Style.FrameRounding)); |
| 1062 | if (bg_col.w > 0.0f) |
| 1063 | window->DrawList->AddRectFilled(bb.Min + padding, bb.Max - padding, GetColorU32(bg_col)); |
| 1064 | window->DrawList->AddImage(texture_id, bb.Min + padding, bb.Max - padding, uv0, uv1, GetColorU32(tint_col)); |
| 1065 | |
| 1066 | return pressed; |
| 1067 | } |
| 1068 | |
| 1069 | bool ImGui::ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col) |
| 1070 | { |
nothing calls this directly
no test coverage detected