FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
src/ftxui/dom/paragraph.cpp
Aller à la documentation de ce fichier.
1// Copyright 2020 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 <sstream> // for basic_istream, stringstream
6#include <string> // for string, allocator, getline
7#include <utility> // for move
8
9#include "ftxui/dom/elements.hpp" // for flexbox, Element, text, Elements, operator|, xflex, paragraph, paragraphAlignCenter, paragraphAlignJustify, paragraphAlignLeft, paragraphAlignRight
10#include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig, FlexboxConfig::JustifyContent, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::SpaceBetween
11
12namespace ftxui {
13
14namespace {
15Elements Split(const std::string& the_text) {
16 Elements output;
17 std::stringstream ss(the_text);
18 std::string word;
19 while (std::getline(ss, word, ' ')) {
20 output.push_back(text(word));
21 }
22 return output;
23}
24
25Element Split(const std::string& paragraph,
26 const std::function<Element(std::string)>& f) {
27 Elements output;
28 std::stringstream ss(paragraph);
29 std::string line;
30 while (std::getline(ss, line, '\n')) {
31 output.push_back(f(line));
32 }
33 return vbox(std::move(output));
34}
35
36} // namespace
37
38/// @brief Renvoie un élément affichant le paragraphe sur plusieurs lignes.
39/// @ingroup dom
40/// @see flexbox.
41Element paragraph(const std::string& the_text) {
42 return paragraphAlignLeft(the_text);
43}
44
45/// @brief Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné à
46/// gauche.
47/// @ingroup dom
48/// @see flexbox.
49Element paragraphAlignLeft(const std::string& the_text) {
50 return Split(the_text, [](const std::string& line) {
51 static const auto config = FlexboxConfig().SetGap(1, 0);
52 return flexbox(Split(line), config);
53 });
54};
55
56/// @brief Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné à
57/// droite.
58/// @ingroup dom
59/// @see flexbox.
60Element paragraphAlignRight(const std::string& the_text) {
61 return Split(the_text, [](const std::string& line) {
62 static const auto config = FlexboxConfig().SetGap(1, 0).Set(
64 return flexbox(Split(line), config);
65 });
66}
67
68/// @brief Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné au
69/// centre.
70/// @ingroup dom
71/// @see flexbox.
72Element paragraphAlignCenter(const std::string& the_text) {
73 return Split(the_text, [](const std::string& line) {
74 static const auto config =
76 return flexbox(Split(line), config);
77 });
78}
79
80/// @brief Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné
81/// en utilisant un alignement justifié.
82/// @ingroup dom
83/// @see flexbox.
84Element paragraphAlignJustify(const std::string& the_text) {
85 return Split(the_text, [](const std::string& line) {
86 static const auto config = FlexboxConfig().SetGap(1, 0).Set(
88 Elements words = Split(line);
89 words.push_back(text("") | xflex);
90 return flexbox(std::move(words), config);
91 });
92}
93
94} // namespace ftxui
FlexboxConfig & SetGap(int gap_x, int gap_y)
Définit la direction de flex (flex direction) de la flexbox.
@ Center
Les éléments sont centrés le long de la ligne.
@ FlexEnd
Les éléments sont alignés à la fin de la direction du flexbox.
FlexboxConfig & Set(FlexboxConfig::Direction)
Définit la direction de la flexbox.
Element paragraphAlignRight(const std::string &text)
Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné à droite.
Element paragraphAlignCenter(const std::string &text)
Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné au centre.
Element text(std::wstring text)
Affiche un morceau de texte unicode.
Definition text.cpp:160
Element paragraphAlignLeft(const std::string &text)
Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné à gauche.
Element paragraphAlignJustify(const std::string &text)
Renvoie un élément affichant le paragraphe sur plusieurs lignes, aligné en utilisant un alignement ju...
Element vbox(Elements)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
FlexboxConfig est une structure de configuration qui définit les propriétés de mise en page pour un c...
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
Un conteneur affichant des éléments sur des lignes/colonnes et capable de passer à la colonne/ligne s...
Definition flexbox.cpp:251
std::shared_ptr< Node > Element
Definition elements.hpp:22
std::vector< Element > Elements
Definition elements.hpp:23
Elements paragraph(std::wstring text)