MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / ImageButtonEx

Method ImageButtonEx

extern/imgui/imgui_widgets.cpp:1047–1072  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
ImClampFunction · 0.85
ImMinFunction · 0.85
AddRectFilledMethod · 0.80
AddImageMethod · 0.80

Tested by

no test coverage detected