MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / RadioButton

Method RadioButton

extern/imgui/imgui_widgets.cpp:1216–1267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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