27 class RadioboxBase :
public ComponentBase,
public RadioboxOption {
29 explicit RadioboxBase(RadioboxOption option) : RadioboxOption(option) {}
35 const bool is_menu_focused = Focused();
36 elements.reserve(
size());
37 for (
int i = 0; i <
size(); ++i) {
38 const bool is_focused = (focused_entry() == i) && is_menu_focused;
39 const bool is_selected = (hovered_ == i);
40 auto focus_management = !is_selected ?
nothing
41 : is_menu_focused ?
focus
43 auto state = EntryState{
52 elements.push_back(element | focus_management |
reflect(boxes_[i]));
58 bool OnEvent(Event event)
override {
60 if (!CaptureMouse(event)) {
64 if (event.is_mouse()) {
65 return OnMouseEvent(event);
69 const int old_hovered = hovered_;
77 (hovered_) -= box_.y_max - box_.y_min;
80 (hovered_) += box_.y_max - box_.y_min;
86 (hovered_) =
size() - 1;
89 hovered_ = (hovered_ + 1) %
size();
92 hovered_ = (hovered_ +
size() - 1) %
size();
97 if (hovered_ != old_hovered) {
98 focused_entry() = hovered_;
105 selected() = hovered_;
113 bool OnMouseEvent(Event event) {
116 return OnMouseWheel(event);
119 for (
int i = 0; i <
size(); ++i) {
120 if (!boxes_[i].Contain(event.mouse().x, event.mouse().y)) {
128 if (selected() != i) {
139 bool OnMouseWheel(Event event) {
140 if (!box_.Contain(event.mouse().x, event.mouse().y)) {
144 const int old_hovered = hovered_;
155 if (hovered_ != old_hovered) {
163 boxes_.resize(
size());
169 bool Focusable() const final {
return entries.size(); }
170 int size()
const {
return int(entries.size()); }
172 int hovered_ = selected();
173 std::vector<Box> boxes_;
209 return Make<RadioboxBase>(std::move(option));
245 return Make<RadioboxBase>(std::move(option));
An adapter. Reference a list of strings.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Element nothing(Element element)
A decoration doing absolutely nothing.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
std::vector< Element > Elements
Element select(Element)
Set the child to be the one selected among its siblings.
Element focus(Element)
Set the child to be the one in focus globally.
Decorator reflect(Box &box)
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element vbox(Elements)
A container displaying elements vertically one by one.
static const Event TabReverse
static const Event PageUp
static Event Character(std::string)
An event corresponding to a given typed character.
static const Event ArrowUp
static const Event ArrowDown
static const Event PageDown
static const Event Return
Option for the Radiobox component.
ConstStringListRef entries
static RadioboxOption Simple()
Option for standard Radiobox.
std::function< Element(const EntryState &)> transform