MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImageButtonEx

Method ImageButtonEx

KBotExt/imgui/imgui_widgets.cpp:1034–1059  ·  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

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

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