#pragma once #include "UI/Element/Div.h" #include "UI/Style/Class.h" namespace Seele { namespace UI { // A radio button: a circular indicator + optional label. // HTML analog: // // Usage: // auto* r1 = new Radio<>(); // auto* r2 = new Radio<>(); // // per-frame: r1->setSelected(viewState.choice == 0) // // r2->setSelected(viewState.choice == 1) // // Pure display widget. The view owns the selection state and drives // setSelected() on each radio in the group. template class Radio : public Div { public: using Div::attr; using Div::style; using Div::markDirty; using Div::getTheme; Radio(Attributes attr = Attributes{}, std::initializer_list children = {}) : Div(std::move(attr), children) { style.height = 20; style.width = 20; } virtual ~Radio() override {} void setSelected(bool selected) { _selected = selected; markDirty(); } bool isSelected() const { return _selected; } void setHovered(bool hovered) override { _hovered = hovered; } void setFocused(bool focused) override { _focused = focused; } bool isFocusable() const override { return attr.focusable; } void applyStyle(Style parentStyle, const Theme& theme) override { Div::applyStyle(parentStyle, theme); } void applyOverrides() override { const Theme& th = getTheme(); if (_selected) { style.backgroundColor = th.color(ColorToken::Blue); } else if (_hovered) { style.backgroundColor = Vector(0.22f, 0.24f, 0.28f); } else if (_focused) { style.backgroundColor = Vector(0.20f, 0.22f, 0.26f); } else { style.backgroundColor = Vector(0.14f, 0.14f, 0.16f); } } private: bool _selected = false; bool _hovered = false; bool _focused = false; }; } // namespace UI } // namespace Seele