MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / RadioButton

Method RadioButton

lib/imgui/imgui_widgets.cpp:1071–1120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1069}
1070
1071bool ImGui::RadioButton(const char* label, bool active)
1072{
1073 ImGuiWindow* window = GetCurrentWindow();
1074 if (window->SkipItems)
1075 return false;
1076
1077 ImGuiContext& g = *GImGui;
1078 const ImGuiStyle& style = g.Style;
1079 const ImGuiID id = window->GetID(label);
1080 const ImVec2 label_size = CalcTextSize(label, NULL, true);
1081
1082 const float square_sz = GetFrameHeight();
1083 const ImVec2 pos = window->DC.CursorPos;
1084 const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
1085 const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f));
1086 ItemSize(total_bb, style.FramePadding.y);
1087 if (!ItemAdd(total_bb, id))
1088 return false;
1089
1090 ImVec2 center = check_bb.GetCenter();
1091 center.x = IM_ROUND(center.x);
1092 center.y = IM_ROUND(center.y);
1093 const float radius = (square_sz - 1.0f) * 0.5f;
1094
1095 bool hovered, held;
1096 bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
1097 if (pressed)
1098 MarkItemEdited(id);
1099
1100 RenderNavHighlight(total_bb, id);
1101 window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
1102 if (active)
1103 {
1104 const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f));
1105 window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark), 16);
1106 }
1107
1108 if (style.FrameBorderSize > 0.0f)
1109 {
1110 window->DrawList->AddCircle(center + ImVec2(1,1), radius, GetColorU32(ImGuiCol_BorderShadow), 16, style.FrameBorderSize);
1111 window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), 16, style.FrameBorderSize);
1112 }
1113
1114 if (g.LogEnabled)
1115 LogRenderedText(&total_bb.Min, active ? "(x)" : "( )");
1116 if (label_size.x > 0.0f)
1117 RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label);
1118
1119 return pressed;
1120}
1121
1122// FIXME: This would work nicely if it was a public template, e.g. 'template<T> RadioButton(const char* label, T* v, T v_button)', but I'm not sure how we would expose it..
1123bool ImGui::RadioButton(const char* label, int* v, int v_button)

Callers

nothing calls this directly

Calls 7

GetCurrentWindowFunction · 0.85
ImVec2Class · 0.85
ItemSizeClass · 0.85
ImMaxFunction · 0.85
AddCircleFilledMethod · 0.80
AddCircleMethod · 0.80
GetIDMethod · 0.45

Tested by

no test coverage detected