25class RadioboxBase :
public ComponentBase,
public RadioboxOption {
27 explicit RadioboxBase(
const RadioboxOption& option)
28 : RadioboxOption(option) {}
34 const bool is_menu_focused = Focused();
35 elements.reserve(
size());
36 for (
int i = 0; i <
size(); ++i) {
37 const bool is_focused = (focused_entry() == i) && is_menu_focused;
38 const bool is_selected = (hovered_ == i);
39 auto state = EntryState{
40 entries[i], selected() == i, is_selected, is_focused, i,
47 elements.push_back(element |
reflect(boxes_[i]));
53 bool OnEvent(Event event)
override {
55 if (!CaptureMouse(event)) {
59 if (event.is_mouse()) {
60 return OnMouseEvent(event);
64 const int old_hovered = hovered_;
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();
92 if (hovered_ != old_hovered) {
93 focused_entry() = hovered_;
99 if (event == Event::Character(
' ') || event ==
Event::Return) {
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)) {
139 const int old_hovered = hovered_;
150 if (hovered_ != old_hovered) {
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);
Un adaptateur. Référence une liste de chaînes de caractères.
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()
Option pour un bouton radio standard.
std::function< Element(const EntryState &)> transform
Component Radiobox(RadioboxOption options)
Une liste d'éléments, où un seul peut être sélectionné.
Option pour le composant Radiobox.
Decorator size(WidthOrHeight, Constraint, int value)
Applique une contrainte sur la taille d'un élément.
Element focus(Element)
Définit l'élément child comme étant celui qui est focalisé parmi ses frères.
Element vbox(Elements)
Un conteneur affichant les éléments verticalement un par un.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
L'espace de noms FTXUI ftxui::
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