| 530 | } |
| 531 | |
| 532 | bool RadioButtonsAt(size_t& index, const Array<String>& options, const Vec2& center, const Optional<double>& _width, bool enabled) |
| 533 | { |
| 534 | const Font& font = GetFont(); |
| 535 | const RectF region = RadioButtonsRegionAt(options, center, _width); |
| 536 | const bool onClient = Cursor::OnClientRect(); |
| 537 | |
| 538 | bool hasChanged = false; |
| 539 | const int32 labelPosX = static_cast<int32>(region.x + RadioButtonPadding * 2 + RadioButtonSize); |
| 540 | const double baseY = (center.y - (options.size() * CellSize - (CellSize - UnitSize)) / 2.0 + 18); |
| 541 | |
| 542 | region.draw(BackgroundColor); |
| 543 | { |
| 544 | const ColorF checkedCircleColor = (enabled ? RadioButtonFillColor : RadioButtonDisabledBaseColor); |
| 545 | const ColorF uncheckedCircleColor = (enabled ? RadioButtonBaseColor : RadioButtonDisabledBaseColor); |
| 546 | |
| 547 | for (size_t row = 0; row < options.size(); ++row) |
| 548 | { |
| 549 | const RectF radioButtonBox{ Arg::leftCenter(region.x + RadioButtonPadding, baseY + row * CellSize), RadioButtonSize }; |
| 550 | const Circle radioButton{ radioButtonBox.center(), RadioButtonSize / 2.0 }; |
| 551 | const bool mouseOver = (enabled && radioButtonBox.mouseOver()); |
| 552 | const bool checked = (index == row); |
| 553 | |
| 554 | if (checked) |
| 555 | { |
| 556 | radioButton.drawFrame(2, 0.5, checkedCircleColor); |
| 557 | radioButton.stretched(-5).draw(checkedCircleColor); |
| 558 | } |
| 559 | else |
| 560 | { |
| 561 | radioButton.drawFrame(2, 0.5, uncheckedCircleColor); |
| 562 | } |
| 563 | |
| 564 | if (mouseOver && onClient) |
| 565 | { |
| 566 | Cursor::RequestStyle(CursorStyle::Hand); |
| 567 | } |
| 568 | |
| 569 | if (enabled && onClient && radioButtonBox.leftClicked()) |
| 570 | { |
| 571 | if (index != row) |
| 572 | { |
| 573 | index = row; |
| 574 | hasChanged = true; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | { |
| 581 | const int32 fontHeight = font.height(); |
| 582 | const ColorF textColor = GetTextColor(enabled); |
| 583 | size_t row = 0; |
| 584 | |
| 585 | for (const auto& option : options) |
| 586 | { |
| 587 | const RectF radioButtonBox{ Arg::leftCenter(region.x + RadioButtonPadding, baseY + row * CellSize), RadioButtonSize }; |
| 588 | const Circle radioButton{ radioButtonBox.center(), RadioButtonSize / 2.0 }; |
| 589 | const Vec2 labelPos{ labelPosX, (radioButton.y - fontHeight / 2.0 + FontYOffset - 0.5) }; |
no test coverage detected