MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ImageButton

Method ImageButton

lib/imgui/imgui_widgets.cpp:969–1003  ·  view source on GitHub ↗

frame_padding < 0: uses FramePadding from style (default) frame_padding = 0: no framing frame_padding > 0: set framing size The color used are the button colors.

Source from the content-addressed store, hash-verified

967// frame_padding > 0: set framing size
968// The color used are the button colors.
969bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
970{
971 ImGuiWindow* window = GetCurrentWindow();
972 if (window->SkipItems)
973 return false;
974
975 ImGuiContext& g = *GImGui;
976 const ImGuiStyle& style = g.Style;
977
978 // Default to using texture ID as ID. User can still push string/integer prefixes.
979 // We could hash the size/uv to create a unique ID but that would prevent the user from animating UV.
980 PushID((void*)(intptr_t)user_texture_id);
981 const ImGuiID id = window->GetID("#image");
982 PopID();
983
984 const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
985 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2);
986 const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
987 ItemSize(bb);
988 if (!ItemAdd(bb, id))
989 return false;
990
991 bool hovered, held;
992 bool pressed = ButtonBehavior(bb, id, &hovered, &held);
993
994 // Render
995 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
996 RenderNavHighlight(bb, id);
997 RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding));
998 if (bg_col.w > 0.0f)
999 window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, GetColorU32(bg_col));
1000 window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col));
1001
1002 return pressed;
1003}
1004
1005bool ImGui::Checkbox(const char* label, bool* v)
1006{

Callers

nothing calls this directly

Calls 8

GetCurrentWindowFunction · 0.85
ImVec2Class · 0.85
ItemSizeClass · 0.85
ImClampFunction · 0.85
ImMinFunction · 0.85
AddRectFilledMethod · 0.80
AddImageMethod · 0.80
GetIDMethod · 0.45

Tested by

no test coverage detected