MCPcopy Create free account
hub / github.com/Wemino/EchoPatch / ImageButtonEx

Method ImageButtonEx

include/imgui/imgui_widgets.cpp:1172–1201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1170#endif
1171
1172bool ImGui::ImageButtonEx(ImGuiID id, ImTextureRef tex_ref, const ImVec2& image_size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col, ImGuiButtonFlags flags)
1173{
1174 ImGuiContext& g = *GImGui;
1175 ImGuiWindow* window = GetCurrentWindow();
1176 if (window->SkipItems)
1177 return false;
1178
1179 const ImVec2 padding = g.Style.FramePadding;
1180 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + image_size + padding * 2.0f);
1181 ItemSize(bb);
1182 if (!ItemAdd(bb, id))
1183 return false;
1184
1185 bool hovered, held;
1186 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
1187
1188 // Render
1189 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
1190 RenderNavCursor(bb, id);
1191 RenderFrame(bb.Min, bb.Max, col, true, g.Style.FrameRounding);
1192 if (bg_col.w > 0.0f)
1193 window->DrawList->AddRectFilled(bb.Min + padding, bb.Max - padding, GetColorU32(bg_col));
1194 float image_rounding = ImMax(g.Style.FrameRounding - ImMax(padding.x, padding.y), g.Style.ImageRounding);
1195 if (image_rounding > 0.0f)
1196 window->DrawList->AddImageRounded(tex_ref, bb.Min + padding, bb.Max - padding, uv0, uv1, GetColorU32(tint_col), image_rounding);
1197 else
1198 window->DrawList->AddImage(tex_ref, bb.Min + padding, bb.Max - padding, uv0, uv1, GetColorU32(tint_col));
1199
1200 return pressed;
1201}
1202
1203// - ImageButton() adds style.FramePadding*2.0f to provided size. This is in order to facilitate fitting an image in a button.
1204// - ImageButton() draws a background based on regular Button() color + optionally an inner background if specified. (#8165) // FIXME: Maybe that's not the best design?

Callers

nothing calls this directly

Calls 6

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
AddRectFilledMethod · 0.80
AddImageRoundedMethod · 0.80
AddImageMethod · 0.80

Tested by

no test coverage detected