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

Method ImageButtonEx

include/imgui/imgui_widgets.cpp:1175–1204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1173#endif
1174
1175bool 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)
1176{
1177 ImGuiContext& g = *GImGui;
1178 ImGuiWindow* window = GetCurrentWindow();
1179 if (window->SkipItems)
1180 return false;
1181
1182 const ImVec2 padding = g.Style.FramePadding;
1183 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + image_size + padding * 2.0f);
1184 ItemSize(bb);
1185 if (!ItemAdd(bb, id))
1186 return false;
1187
1188 bool hovered, held;
1189 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
1190
1191 // Render
1192 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
1193 RenderNavCursor(bb, id);
1194 RenderFrame(bb.Min, bb.Max, col, true, g.Style.FrameRounding);
1195 if (bg_col.w > 0.0f)
1196 window->DrawList->AddRectFilled(bb.Min + padding, bb.Max - padding, GetColorU32(bg_col));
1197 float image_rounding = ImMax(g.Style.FrameRounding - ImMax(padding.x, padding.y), g.Style.ImageRounding);
1198 if (image_rounding > 0.0f)
1199 window->DrawList->AddImageRounded(tex_ref, bb.Min + padding, bb.Max - padding, uv0, uv1, GetColorU32(tint_col), image_rounding);
1200 else
1201 window->DrawList->AddImage(tex_ref, bb.Min + padding, bb.Max - padding, uv0, uv1, GetColorU32(tint_col));
1202
1203 return pressed;
1204}
1205
1206// - ImageButton() adds style.FramePadding*2.0f to provided size. This is in order to facilitate fitting an image in a button.
1207// - 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