MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / Checkbox

Method Checkbox

imgui_tiny_app/imgui/imgui_widgets.cpp:1244–1317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1242#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
1243
1244bool ImGui::Checkbox(const char* label, bool* v)
1245{
1246 ImGuiWindow* window = GetCurrentWindow();
1247 if (window->SkipItems)
1248 return false;
1249
1250 ImGuiContext& g = *GImGui;
1251 const ImGuiStyle& style = g.Style;
1252 const ImGuiID id = window->GetID(label);
1253 const ImVec2 label_size = CalcTextSize(label, NULL, true);
1254
1255 const float square_sz = GetFrameHeight();
1256 const ImVec2 pos = window->DC.CursorPos;
1257 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));
1258 ItemSize(total_bb, style.FramePadding.y);
1259 const bool is_visible = ItemAdd(total_bb, id);
1260 const bool is_multi_select = (g.LastItemData.ItemFlags & ImGuiItemFlags_IsMultiSelect) != 0;
1261 if (!is_visible)
1262 if (!is_multi_select || !g.BoxSelectState.UnclipMode || !g.BoxSelectState.UnclipRect.Overlaps(total_bb)) // Extra layer of "no logic clip" for box-select support
1263 {
1264 IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
1265 return false;
1266 }
1267
1268 // Range-Selection/Multi-selection support (header)
1269 bool checked = *v;
1270 if (is_multi_select)
1271 MultiSelectItemHeader(id, &checked, NULL);
1272
1273 bool hovered, held;
1274 bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
1275
1276 // Range-Selection/Multi-selection support (footer)
1277 if (is_multi_select)
1278 MultiSelectItemFooter(id, &checked, &pressed);
1279 else if (pressed)
1280 checked = !checked;
1281
1282 if (*v != checked)
1283 {
1284 *v = checked;
1285 pressed = true; // return value
1286 MarkItemEdited(id);
1287 }
1288
1289 const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz));
1290 const bool mixed_value = (g.LastItemData.ItemFlags & ImGuiItemFlags_MixedValue) != 0;
1291 if (is_visible)
1292 {
1293 RenderNavCursor(total_bb, id);
1294 RenderFrame(check_bb.Min, check_bb.Max, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
1295 ImU32 check_col = GetColorU32(ImGuiCol_CheckMark);
1296 if (mixed_value)
1297 {
1298 // Undocumented tristate/mixed/indeterminate checkbox (#2644)
1299 // This may seem awkwardly designed because the aim is to make ImGuiItemFlags_MixedValue supported by all widgets (not just checkbox)
1300 ImVec2 pad(ImMax(1.0f, IM_TRUNC(square_sz / 3.6f)), ImMax(1.0f, IM_TRUNC(square_sz / 3.6f)));
1301 window->DrawList->AddRectFilled(check_bb.Min + pad, check_bb.Max - pad, check_col, style.FrameRounding);

Callers

nothing calls this directly

Calls 6

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
GetIDMethod · 0.80
AddRectFilledMethod · 0.80

Tested by

no test coverage detected