MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / ButtonEx

Method ButtonEx

imgui_tiny_app/imgui/imgui_widgets.cpp:782–821  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected