23class RadioboxBase :
public ComponentBase,
public RadioboxOption {
25 explicit RadioboxBase(
const RadioboxOption& option)
26 : RadioboxOption(option) {}
32 const bool is_menu_focused = Focused();
33 elements.reserve(
size());
34 for (
int i = 0; i <
size(); ++i) {
35 const bool is_focused = (focused_entry() == i) && is_menu_focused;
36 const bool is_selected = (hovered_ == i);
37 auto state = EntryState{
38 entries[i], selected() == i, is_selected, is_focused, i,
45 elements.push_back(element |
reflect(boxes_[i]));
51 bool OnEvent(Event event)
override {
53 if (!CaptureMouse(event)) {
57 if (event.is_mouse()) {
58 return OnMouseEvent(event);
62 const int old_hovered = hovered_;
70 (hovered_) -= box_.y_max - box_.y_min;
73 (hovered_) += box_.y_max - box_.y_min;
79 (hovered_) =
size() - 1;
82 hovered_ = (hovered_ + 1) %
size();
85 hovered_ = (hovered_ +
size() - 1) %
size();
90 if (hovered_ != old_hovered) {
91 focused_entry() = hovered_;
97 if (event == Event::Character(
' ') || event ==
Event::Return) {
98 selected() = hovered_;
106 bool OnMouseEvent(Event event) {
109 return OnMouseWheel(event);
112 for (
int i = 0; i <
size(); ++i) {
113 if (!boxes_[i].Contain(event.mouse().x, event.mouse().y)) {
121 if (selected() != i) {
132 bool OnMouseWheel(Event event) {
133 if (!box_.Contain(event.mouse().x, event.mouse().y)) {
137 const int old_hovered = hovered_;
148 if (hovered_ != old_hovered) {
156 boxes_.resize(
size());
162 bool Focusable() const final {
return entries.size(); }
163 int size()
const {
return int(entries.size()); }
165 int hovered_ = selected();
166 std::vector<Box> boxes_;
237 option.
entries = std::move(entries);
static const Event TabReverse
static const Event PageUp
ConstStringListRef entries
static const Event ArrowUp
static const Event ArrowDown
static const Event PageDown
static const Event Return
static RadioboxOption Simple()
標準ラジオボックスのオプション。
std::function< Element(const EntryState &)> transform
Component Radiobox(RadioboxOption options)
1つだけ選択できる要素のリスト。
Element focus(Element)
子要素を兄弟要素の中でフォーカスされたものとして設定します。
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
std::vector< Element > Elements
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component