MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / ButtonEx

Method ButtonEx

include/imgui/imgui_widgets.cpp:784–824  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782}
783
784bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags)
785{
786 ImGuiWindow* window = GetCurrentWindow();
787 if (window->SkipItems)
788 return false;
789
790 ImGuiContext& g = *GImGui;
791 const ImGuiStyle& style = g.Style;
792 const ImGuiID id = window->GetID(label);
793 const char* label_end = FindRenderedTextEnd(label);
794 const ImVec2 label_size = CalcTextSize(label, label_end, false);
795
796 ImVec2 pos = window->DC.CursorPos;
797 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)
798 pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
799 ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
800
801 const ImRect bb(pos, pos + size);
802 ItemSize(size, style.FramePadding.y);
803 if (!ItemAdd(bb, id))
804 return false;
805
806 bool hovered, held;
807 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
808
809 // Render
810 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
811 RenderNavCursor(bb, id);
812 RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
813
814 if (g.LogEnabled)
815 LogSetNextTextDecoration("[", "]");
816 RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, label_end, &label_size, style.ButtonTextAlign, &bb);
817
818 // Automatically close popups
819 //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
820 // CloseCurrentPopup();
821
822 IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
823 return pressed;
824}
825
826bool ImGui::Button(const char* label, const ImVec2& size_arg)
827{

Callers

nothing calls this directly

Calls 3

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected