MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / ImageButtonEx

Method ImageButtonEx

imgui_tiny_app/imgui/imgui_widgets.cpp:1179–1208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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