MCPcopy Create free account
hub / github.com/NVIDIA-RTX/RTXNTC / ToggleButton

Function ToggleButton

tools/explorer/ImGuiExtensions.cpp:20–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18{
19
20bool ToggleButton(const char* label, bool* state, const ImVec2& size_arg, ImGuiButtonFlags flags)
21{
22 // The implementation is copied and adjusted from ImGui::ButtonEx(...)
23
24 ImGuiWindow* window = GetCurrentWindow();
25 if (window->SkipItems)
26 return false;
27
28 ImGuiContext& g = *GImGui;
29 const ImGuiStyle& style = g.Style;
30 const ImGuiID id = window->GetID(label);
31 const ImVec2 label_size = CalcTextSize(label, NULL, true);
32
33 ImVec2 pos = window->DC.CursorPos;
34 if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset)
35 pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
36 ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
37
38 const ImRect bb(pos, pos + size);
39 ItemSize(size, style.FramePadding.y);
40 if (!ItemAdd(bb, id))
41 return false;
42
43 bool hovered, held;
44 bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
45
46 if (pressed)
47 *state = !*state;
48
49 // Render
50 PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f);
51 const ImU32 col = GetColorU32(*state ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_FrameBg : ImGuiCol_WindowBg);
52 RenderNavHighlight(bb, id);
53 RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
54 PopStyleVar();
55
56 if (g.LogEnabled)
57 LogSetNextTextDecoration("[", "]");
58 if (g.CurrentItemFlags & ImGuiItemFlags_Disabled)
59 PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
60 RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, nullptr, &label_size, style.ButtonTextAlign, &bb);
61 if (g.CurrentItemFlags & ImGuiItemFlags_Disabled)
62 PopStyleColor();
63
64 return pressed;
65}
66
67bool ToggleButtonFlags(const char* label, ImU32* state, ImU32 bit, const ImVec2& size_arg, ImGuiButtonFlags flags)
68{

Callers 3

BuildControlDialogMethod · 0.85
ToggleButtonFlagsFunction · 0.85
BuildControlDialogMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected