MCPcopy Create free account
hub / github.com/Siv3D/OpenSiv3D / CheckBoxAt

Function CheckBoxAt

Siv3D/src/Siv3D/SimpleGUI/SivSimpleGUI.cpp:422–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420 }
421
422 bool CheckBoxAt(bool& checked, const StringView label, const Vec2& center, const Optional<double>& _width, const bool enabled)
423 {
424 const Font& font = GetFont();
425 const DrawableText dtext = font(label);
426
427 const double width = _width.value_or_eval([&](){ return Math::Ceil(CheckBoxPadding * 3 + CheckBoxSize + dtext.region().w); });
428 const RectF region{ Arg::center = center, width, UnitSize };
429 const RectF checkBox{ Arg::leftCenter(region.x + 8, center.y), CheckBoxSize };
430 const RoundRect roundCheckBox = checkBox.rounded(3.2);
431 const Vec2 labelPos{ (region.x + CheckBoxPadding * 2 + CheckBoxSize), (center.y - font.height() / 2.0 + FontYOffset) };
432 const bool mouseOver = (enabled && checkBox.mouseOver());
433
434 region.draw(BackgroundColor);
435
436 if (checked)
437 {
438 if (enabled)
439 {
440 roundCheckBox.draw(mouseOver ? CheckBoxHighlightedFillColor : CheckBoxFillColor);
441 }
442 else
443 {
444 roundCheckBox.draw(CheckBoxDisabledFillColor);
445 }
446
447 DrawCheck(checkBox.center());
448 }
449 else
450 {
451 const RoundRect innerRoundRect = checkBox.stretched(-1.25).rounded(3.2);
452
453 if (enabled)
454 {
455 roundCheckBox.draw(CheckBoxBaseColor);
456 innerRoundRect.draw(mouseOver ? CheckBoxMouseOverColor : ColorF{ 0.95 });
457 }
458 else
459 {
460 roundCheckBox.draw(CheckBoxDisabledBaseColor);
461 innerRoundRect.draw(ColorF{ 0.8 });
462 }
463 }
464
465 dtext.draw(labelPos, GetTextColor(enabled));
466
467 if (enabled && Cursor::OnClientRect() && checkBox.mouseOver())
468 {
469 Cursor::RequestStyle(CursorStyle::Hand);
470 }
471
472 const bool previousValue = checked;
473
474 if (enabled && Cursor::OnClientRect() && checkBox.leftClicked())
475 {
476 checked = !checked;
477 }
478
479 return (checked != previousValue);

Callers 1

CheckBoxFunction · 0.85

Calls 13

CeilFunction · 0.85
DrawCheckFunction · 0.85
GetTextColorFunction · 0.85
OnClientRectFunction · 0.85
RequestStyleFunction · 0.85
centerMethod · 0.80
regionMethod · 0.45
roundedMethod · 0.45
heightMethod · 0.45
mouseOverMethod · 0.45
drawMethod · 0.45
stretchedMethod · 0.45

Tested by

no test coverage detected