@@ -1111,6 +1111,49 @@ bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID user_texture_id, const ImVec2&
11111111 return pressed;
11121112}
11131113
1114+ bool ImGui::ImageButtonWithLabelEx(ImGuiID id, const char* label, ImTextureID user_texture_id, const ImVec2& image_size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col, ImGuiButtonFlags flags)
1115+ {
1116+ ImGuiContext& g = *GImGui;
1117+ const ImGuiStyle& style = g.Style;
1118+ ImGuiWindow* window = GetCurrentWindow();
1119+ if (window->SkipItems)
1120+ return false;
1121+
1122+ const ImVec2 padding = g.Style.FramePadding;
1123+ const ImVec2 label_size = CalcTextSize(label, NULL, true);
1124+ const float label_padding = label_size.x > 0 ? style.ItemInnerSpacing.x : 0.0f;
1125+ const ImVec2 bb_size = ImVec2(
1126+ image_size.x + label_padding + label_size.x + padding.x * 2.0f,
1127+ ImMax(image_size.y, label_size.y) + padding.y * 2.0f);
1128+
1129+ const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + bb_size);
1130+ ItemSize(bb);
1131+ if (!ItemAdd(bb, id))
1132+ return false;
1133+
1134+ bool hovered, held;
1135+ bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
1136+
1137+ const ImRect bb_image(
1138+ bb.Min + ImVec2(padding.x, (bb_size.y - image_size.y) * 0.5f),
1139+ bb.Min + ImVec2(padding.x + image_size.x, (bb_size.y - image_size.y) * 0.5f + image_size.y));
1140+
1141+ const ImRect bb_text(
1142+ bb.Min + ImVec2(padding.x + image_size.x + label_padding, (bb_size.y - label_size.y) * 0.5f),
1143+ bb.Min + ImVec2(padding.x + image_size.x + label_padding + label_size.x, (bb_size.y - label_size.y) * 0.5f + label_size.y));
1144+
1145+ // Render
1146+ const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
1147+ RenderNavCursor(bb, id);
1148+ RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, g.Style.FrameRounding));
1149+ if (bg_col.w > 0.0f)
1150+ window->DrawList->AddRectFilled(bb_image.Min, bb_image.Max, GetColorU32(bg_col));
1151+ window->DrawList->AddImage(user_texture_id, bb_image.Min, bb_image.Max, uv0, uv1, GetColorU32(tint_col));
1152+ RenderTextClipped(bb_text.Min, bb_text.Max, label, NULL, &label_size, style.ButtonTextAlign, &bb);
1153+
1154+ return pressed;
1155+ }
1156+
11141157// - ImageButton() adds style.FramePadding*2.0f to provided size. This is in order to facilitate fitting an image in a button.
11151158// - ImageButton() draws a background based on regular Button() color + optionally an inner background if specified. (#8165) // FIXME: Maybe that's not the best design?
11161159bool ImGui::ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& image_size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col)
@@ -1123,6 +1166,16 @@ bool ImGui::ImageButton(const char* str_id, ImTextureID user_texture_id, const I
11231166 return ImageButtonEx(window->GetID(str_id), user_texture_id, image_size, uv0, uv1, bg_col, tint_col);
11241167}
11251168
1169+ bool ImGui::ImageButtonWithLabel(const char* str_id, const char* label, ImTextureID user_texture_id, const ImVec2& image_size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col)
1170+ {
1171+ ImGuiContext& g = *GImGui;
1172+ ImGuiWindow* window = g.CurrentWindow;
1173+ if (window->SkipItems)
1174+ return false;
1175+
1176+ return ImageButtonWithLabelEx(window->GetID(str_id), label, user_texture_id, image_size, uv0, uv1, bg_col, tint_col);
1177+ }
1178+
11261179#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
11271180// Legacy API obsoleted in 1.89. Two differences with new ImageButton()
11281181// - old ImageButton() used ImTextureID as item id (created issue with multiple buttons with same image, transient texture id values, opaque computation of ID)
0 commit comments