25class RadioboxBase :
public ComponentBase,
public RadioboxOption {
27 explicit RadioboxBase(
const RadioboxOption&
option)
28 : RadioboxOption(
option) {}
36 for (
int i = 0; i <
size(); ++i) {
39 auto state = EntryState{
53 bool OnEvent(Event
event)
override {
55 if (!CaptureMouse(
event)) {
59 if (
event.is_mouse()) {
60 return OnMouseEvent(
event);
72 (hovered_) -= box_.y_max - box_.y_min;
75 (hovered_) += box_.y_max - box_.y_min;
81 (hovered_) =
size() - 1;
84 hovered_ = (hovered_ + 1) %
size();
87 hovered_ = (hovered_ +
size() - 1) %
size();
93 focused_entry() = hovered_;
100 selected() = hovered_;
108 bool OnMouseEvent(Event
event) {
111 return OnMouseWheel(
event);
114 for (
int i = 0; i <
size(); ++i) {
115 if (!boxes_[i].Contain(
event.mouse().x,
event.mouse().y)) {
123 if (selected() != i) {
134 bool OnMouseWheel(Event
event) {
135 if (!box_.Contain(
event.mouse().x,
event.mouse().y)) {
158 boxes_.resize(
size());
164 bool Focusable()
const final {
return entries.size(); }
165 int size()
const {
return int(entries.size()); }
167 int hovered_ = selected();
168 std::vector<Box> boxes_;
239 option.entries = std::move(entries);
240 option.selected = selected;
An adapter. Reference a list of strings.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< ComponentBase > Component
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
std::vector< Element > Elements
Element focus(Element)
Set the child to be the one focused among its siblings.
Decorator reflect(Box &box)
Element vbox(Elements)
A container displaying elements vertically one by one.
static const Event TabReverse
static const Event PageUp
static const Event ArrowUp
static const Event ArrowDown
static const Event PageDown
static const Event Return
Option for the Radiobox component.
static RadioboxOption Simple()
Option for standard Radiobox.
std::function< Element(const EntryState &)> transform