MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / RadioButton

Method RadioButton

KBotExt/imgui/imgui_widgets.cpp:1200–1252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1198}
1199
1200bool ImGui::RadioButton(const char* label, bool active)
1201{
1202 ImGuiWindow* window = GetCurrentWindow();
1203 if (window->SkipItems)
1204 return false;
1205
1206 ImGuiContext& g = *GImGui;
1207 const ImGuiStyle& style = g.Style;
1208 const ImGuiID id = window->GetID(label);
1209 const ImVec2 label_size = CalcTextSize(label, NULL, true);
1210
1211 const float square_sz = GetFrameHeight();
1212 const ImVec2 pos = window->DC.CursorPos;
1213 const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
1214 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));
1215 ItemSize(total_bb, style.FramePadding.y);
1216 if (!ItemAdd(total_bb, id))
1217 return false;
1218
1219 ImVec2 center = check_bb.GetCenter();
1220 center.x = IM_ROUND(center.x);
1221 center.y = IM_ROUND(center.y);
1222 const float radius = (square_sz - 1.0f) * 0.5f;
1223
1224 bool hovered, held;
1225 bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
1226 if (pressed)
1227 MarkItemEdited(id);
1228
1229 RenderNavHighlight(total_bb, id);
1230 const int num_segment = window->DrawList->_CalcCircleAutoSegmentCount(radius);
1231 window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), num_segment);
1232 if (active)
1233 {
1234 const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f));
1235 window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark));
1236 }
1237
1238 if (style.FrameBorderSize > 0.0f)
1239 {
1240 window->DrawList->AddCircle(center + ImVec2(1, 1), radius, GetColorU32(ImGuiCol_BorderShadow), num_segment, style.FrameBorderSize);
1241 window->DrawList->AddCircle(center, radius, GetColorU32(ImGuiCol_Border), num_segment, style.FrameBorderSize);
1242 }
1243
1244 ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y);
1245 if (g.LogEnabled)
1246 LogRenderedText(&label_pos, active ? "(x)" : "( )");
1247 if (label_size.x > 0.0f)
1248 RenderText(label_pos, label);
1249
1250 IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
1251 return pressed;
1252}
1253
1254// 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..
1255bool ImGui::RadioButton(const char* label, int* v, int v_button)

Callers

nothing calls this directly

Calls 9

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
GetIDMethod · 0.80
GetCenterMethod · 0.80
AddCircleFilledMethod · 0.80
AddCircleMethod · 0.80

Tested by

no test coverage detected