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

Method RadioButton

tutorials/common/imgui/imgui_widgets.cpp:1211–1262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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