| 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); |
no test coverage detected