MCPcopy Create free account
hub / github.com/RenderKit/embree / ButtonEx

Method ButtonEx

tutorials/common/imgui/imgui_widgets.cpp:684–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

682}
683
684bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags)
685{
686 ImGuiWindow* window = GetCurrentWindow();
687 if (window->SkipItems)
688 return false;
689
690 ImGuiContext& g = *GImGui;
691 const ImGuiStyle& style = g.Style;
692 const ImGuiID id = window->GetID(label);
693 const ImVec2 label_size = CalcTextSize(label, NULL, true);
694
695 ImVec2 pos = window->DC.CursorPos;
696 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)
697 pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
698 ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
699
700 const ImRect bb(pos, pos + size);
701 ItemSize(size, style.FramePadding.y);
702 if (!ItemAdd(bb, id))
703 return false;
704
705 if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
706 flags |= ImGuiButtonFlags_Repeat;
707
708 bool hovered, held;
709 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
710
711 // Render
712 const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
713 RenderNavHighlight(bb, id);
714 RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
715
716 if (g.LogEnabled)
717 LogSetNextTextDecoration("[", "]");
718 RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
719
720 // Automatically close popups
721 //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
722 // CloseCurrentPopup();
723
724 IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
725 return pressed;
726}
727
728bool ImGui::Button(const char* label, const ImVec2& size_arg)
729{

Callers

nothing calls this directly

Calls 3

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected