FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
src/ftxui/component/collapsible.cpp
Aller à la documentation de ce fichier.
1// Copyright 2021 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT qui peut être trouvée dans
3// le fichier LICENSE.
4#include <functional> // for function
5#include <utility> // for move
6
7#include "ftxui/component/component.hpp" // for Checkbox, Maybe, Make, Vertical, Collapsible
8#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
9#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
10#include "ftxui/dom/elements.hpp" // for operator|=, text, hbox, Element, bold, inverted
11#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef
12
13namespace ftxui {
14
15/// @brief Un composant repliable. Il affiche une case à cocher avec une flèche. Une fois
16/// activé, l'enfant est affiché.
17/// @param label Le libellé de la case à cocher.
18/// @param child L'enfant à afficher.
19/// @param show Contient l'état indiquant si l'enfant est affiché ou non.
20///
21/// ### Exemple
22/// ```cpp
23/// auto component = Collapsible("Show details", details);
24/// ```
25///
26/// ### Sortie
27/// ```
28///
29/// ▼ Show details
30/// <details component>
31/// ```
32// NOLINTNEXTLINE
34 class Impl : public ComponentBase {
35 public:
36 Impl(ConstStringRef label, Component child, Ref<bool> show) : show_(show) {
38 opt.transform = [](EntryState s) { // NOLINT
39 auto prefix = text(s.state ? "▼ " : "▶ "); // NOLINT
40 auto t = text(s.label);
41 if (s.active) {
42 t |= bold;
43 }
44 if (s.focused) {
45 t |= inverted;
46 }
47 return hbox({prefix, t});
48 };
49 Add(Container::Vertical({
50 Checkbox(std::move(label), show_.operator->(), opt),
51 Maybe(std::move(child), show_.operator->()),
52 }));
53 }
54 Ref<bool> show_;
55 };
56
57 return Make<Impl>(std::move(label), std::move(child), show);
58}
59
60} // namespace ftxui
Un adaptateur. Possède ou référence une chaîne constante. Par commodité, cette classe convertit plusi...
Definition ref.hpp:94
Un adaptateur. Possède ou référence un objet mutable.
Definition ref.hpp:46
std::function< Element(const EntryState &)> transform
Il implémente son propre rendu en tant que ftxui::Element. Il implémente la navigation au clavier en ...
Option pour le composant Checkbox.
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:27
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
Un composant repliable. Il affiche une case à cocher avec une flèche. Une fois activé,...
std::shared_ptr< ComponentBase > Component
arguments pour la transformation depuis |ButtonOption|, |CheckboxOption|, |RadioboxOption|,...