MCPcopy Create free account
hub / github.com/Raais/ImStudio / ButtonEx

Method ButtonEx

src/third-party/imgui/imgui_widgets.cpp:670–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668}
669
670bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags)
671{
672 ImGuiWindow* window = GetCurrentWindow();
673 if (window->SkipItems)
674 return false;
675
676 ImGuiContext& g = *GImGui;
677 const ImGuiStyle& style = g.Style;
678 const ImGuiID id = window->GetID(label);
679 const ImVec2 label_size = CalcTextSize(label, NULL, true);
680
681 ImVec2 pos = window->DC.CursorPos;
682 if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag)
683 pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
684 ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
685
686 const ImRect bb(pos, pos + size);
687 ItemSize(size, style.FramePadding.y);
688 if (!ItemAdd(bb, id))
689 return false;
690
691 if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
692 flags |= ImGuiButtonFlags_Repeat;
693
694 bool hovered, held;
695 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
696
697 // Render
698 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
699 RenderNavHighlight(bb, id);
700 RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
701
702 if (g.LogEnabled)
703 LogSetNextTextDecoration("[", "]");
704 RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
705
706 // Automatically close popups
707 //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
708 // CloseCurrentPopup();
709
710 IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
711 return pressed;
712}
713
714bool ImGui::Button(const char* label, const ImVec2& size_arg)
715{

Callers

nothing calls this directly

Calls 2

GetCurrentWindowFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected