FTXUI  2.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
paragraph.cpp
Go to the documentation of this file.
1#include <sstream> // for basic_istream, stringstream
2#include <string> // for string, allocator, getline
3#include <utility> // for move
4
5#include "ftxui/dom/elements.hpp" // for flexbox, Element, text, Elements, operator|, xflex, paragraph, paragraphAlignCenter, paragraphAlignJustify, paragraphAlignLeft, paragraphAlignRight
6#include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig, FlexboxConfig::JustifyContent, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::SpaceBetween
7
8namespace ftxui {
9
10namespace {
11Elements Split(std::string the_text) {
12 Elements output;
13 std::stringstream ss(the_text);
14 std::string word;
15 while (std::getline(ss, word, ' '))
16 output.push_back(text(word));
17 return output;
18}
19} // namespace
20
21/// @brief Return an element drawing the paragraph on multiple lines.
22/// @ingroup dom
23/// @see flexbox.
24Element paragraph(std::string the_text) {
25 return paragraphAlignLeft(std::move(the_text));
26}
27
28/// @brief Return an element drawing the paragraph on multiple lines, aligned on
29/// the left.
30/// @ingroup dom
31/// @see flexbox.
32Element paragraphAlignLeft(std::string the_text) {
33 static const auto config = FlexboxConfig().SetGap(1, 0);
34 return flexbox(Split(std::move(the_text)), config);
35}
36
37/// @brief Return an element drawing the paragraph on multiple lines, aligned on
38/// the right.
39/// @ingroup dom
40/// @see flexbox.
41Element paragraphAlignRight(std::string the_text) {
42 static const auto config =
44 return flexbox(Split(std::move(the_text)), config);
45}
46
47/// @brief Return an element drawing the paragraph on multiple lines, aligned on
48/// the center.
49/// @ingroup dom
50/// @see flexbox.
51Element paragraphAlignCenter(std::string the_text) {
52 static const auto config =
54 return flexbox(Split(std::move(the_text)), config);
55}
56
57/// @brief Return an element drawing the paragraph on multiple lines, aligned
58/// using a justified alignment.
59/// the center.
60/// @ingroup dom
61/// @see flexbox.
62Element paragraphAlignJustify(std::string the_text) {
63 static const auto config = FlexboxConfig().SetGap(1, 0).Set(
65 Elements words = Split(std::move(the_text));
66 words.push_back(text("") | xflex);
67 return flexbox(std::move(words), config);
68}
69
70} // namespace ftxui
71
72// Copyright 2020 Arthur Sonzogni. All rights reserved.
73// Use of this source code is governed by the MIT license that can be found in
74// the LICENSE file.
Element paragraphAlignCenter(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition paragraph.cpp:51
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition flex.cpp:125
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
std::shared_ptr< Node > Element
Definition elements.hpp:18
Element paragraphAlignJustify(std::string text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition paragraph.cpp:62
Element paragraphAlignRight(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition paragraph.cpp:41
std::vector< Element > Elements
Definition elements.hpp:19
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:106
Elements paragraph(std::wstring text)
Element paragraphAlignLeft(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition paragraph.cpp:32
FlexboxConfig & SetGap(int gap_x, int gap_y)
@ Center
Items are centered along the line.
@ FlexEnd
Items are aligned to the end of flexbox's direction.
@ SpaceBetween
Items are evenly distributed in the line; first item is on the start.
FlexboxConfig & Set(FlexboxConfig::Direction)