#pragma once #include "UI/Element/Div.h" #include "UI/Style/Class.h" namespace Seele { namespace UI { // A checkbox: a square indicator + optional label. // HTML analog: // // Usage: // auto* cb = new Checkbox<>(); // // per-frame: cb->setChecked(viewState.flag) // // Pure display widget. The view drives checked state via setChecked(). // The checkbox does NOT handle its own onClick — the view wires the // toggle logic via attr.onClick on the owning container. template class Checkbox : public Div { public: using Div::attr; using Div::style; using Div::markDirty; using Div::getTheme; using Div::children; Checkbox(Attributes attr = Attributes{}, std::initializer_list children = {}) : Div(std::move(attr), children) { style.height = 20; style.width = 20; } virtual ~Checkbox() override {} void setChecked(bool checked) { _checked = checked; markDirty(); } bool isChecked() const { return _checked; } 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); } // The System calls applyOverrides() during style() after applyStyle. // We use it to reflect checked/hover/focus in the background color. void applyOverrides() override { const Theme& th = getTheme(); if (_checked) { style.backgroundColor = th.color(ColorToken::Green); } 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 _checked = false; bool _hovered = false; bool _focused = false; }; } // namespace UI } // namespace Seele