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

Function HorizontalRadioButtonsAt

Siv3D/src/Siv3D/SimpleGUI/SivSimpleGUI.cpp:655–741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

653 }
654
655 bool HorizontalRadioButtonsAt(size_t& index, const Array<String>& options, const Vec2& center, const Optional<double>& _itemWidth, bool enabled)
656 {
657 const Font& font = GetFont();
658
659 double itemWidth = 0.0;
660 {
661 if (_itemWidth)
662 {
663 itemWidth = *_itemWidth;
664 }
665 else
666 {
667 for (const auto& option : options)
668 {
669 itemWidth = Max<double>(itemWidth, RadioButtonPadding * 3 + RadioButtonSize + font(option).region().w);
670 }
671
672 itemWidth = Math::Ceil(itemWidth);
673 }
674 }
675
676 const double width = (itemWidth * options.size());
677 const RectF region{ Arg::center = center, width, UnitSize };
678 const bool onClient = Cursor::OnClientRect();
679
680 bool hasChanged = false;
681 const double baseY = (center.y - UnitSize / 2 + 18);
682 const int32 fontHeight = font.height();
683
684 region.draw(BackgroundColor);
685 {
686 const ColorF checkedCircleColor = (enabled ? RadioButtonFillColor : RadioButtonDisabledBaseColor);
687 const ColorF uncheckedCircleColor = (enabled ? RadioButtonBaseColor : RadioButtonDisabledBaseColor);
688
689 for (size_t itemIndex = 0; itemIndex < options.size(); ++itemIndex)
690 {
691 const double posX = (region.x + itemWidth * itemIndex);
692 const RectF radioButtonBox{ Arg::leftCenter(posX + RadioButtonPadding, baseY), RadioButtonSize };
693 const Circle radioButton{ radioButtonBox.center(), (RadioButtonSize / 2.0) };
694 const Vec2 labelPos{ (posX + RadioButtonPadding * 2 + RadioButtonSize), (radioButton.y - fontHeight / 2.0 + FontYOffset - 0.5) };
695 const bool mouseOver = (enabled && radioButtonBox.mouseOver());
696 const bool checked = (index == itemIndex);
697
698 if (checked)
699 {
700 radioButton.drawFrame(2, 0.5, checkedCircleColor);
701 radioButton.stretched(-5).draw(checkedCircleColor);
702 }
703 else
704 {
705 radioButton.drawFrame(2, 0.5, uncheckedCircleColor);
706 }
707
708 if (mouseOver && onClient)
709 {
710 Cursor::RequestStyle(CursorStyle::Hand);
711 }
712

Callers 1

HorizontalRadioButtonsFunction · 0.85

Calls 13

CeilFunction · 0.85
OnClientRectFunction · 0.85
RequestStyleFunction · 0.85
GetTextColorFunction · 0.85
centerMethod · 0.80
regionMethod · 0.45
sizeMethod · 0.45
heightMethod · 0.45
drawMethod · 0.45
mouseOverMethod · 0.45
drawFrameMethod · 0.45
stretchedMethod · 0.45

Tested by

no test coverage detected