2021-12-12 00:58:25 +08:00
|
|
|
#include <sstream> // for basic_istream, stringstream
|
|
|
|
#include <string> // for string, allocator, getline
|
|
|
|
#include <utility> // for move
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2021-12-12 00:58:25 +08:00
|
|
|
#include "ftxui/dom/elements.hpp" // for flexbox, Element, text, Elements, operator|, xflex, paragraph, paragraphAlignCenter, paragraphAlignJustify, paragraphAlignLeft, paragraphAlignRight
|
|
|
|
#include "ftxui/dom/flexbox_config.hpp" // for FlexboxConfig, FlexboxConfig::JustifyContent, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::SpaceBetween
|
2019-01-23 07:26:36 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
2021-12-12 00:58:25 +08:00
|
|
|
namespace {
|
2022-03-31 08:17:43 +08:00
|
|
|
Elements Split(const std::string& the_text) {
|
2021-08-09 05:25:20 +08:00
|
|
|
Elements output;
|
|
|
|
std::stringstream ss(the_text);
|
|
|
|
std::string word;
|
2022-03-31 08:17:43 +08:00
|
|
|
while (std::getline(ss, word, ' ')) {
|
2021-12-12 00:58:25 +08:00
|
|
|
output.push_back(text(word));
|
2022-03-31 08:17:43 +08:00
|
|
|
}
|
2019-01-23 07:26:36 +08:00
|
|
|
return output;
|
|
|
|
}
|
2021-12-12 00:58:25 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/// @brief Return an element drawing the paragraph on multiple lines.
|
|
|
|
/// @ingroup dom
|
|
|
|
/// @see flexbox.
|
2022-03-31 08:17:43 +08:00
|
|
|
Element paragraph(const std::string& the_text) {
|
|
|
|
return paragraphAlignLeft(the_text);
|
2021-12-12 00:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return an element drawing the paragraph on multiple lines, aligned on
|
|
|
|
/// the left.
|
|
|
|
/// @ingroup dom
|
|
|
|
/// @see flexbox.
|
2022-03-31 08:17:43 +08:00
|
|
|
Element paragraphAlignLeft(const std::string& the_text) {
|
2021-12-12 00:58:25 +08:00
|
|
|
static const auto config = FlexboxConfig().SetGap(1, 0);
|
2022-03-31 08:17:43 +08:00
|
|
|
return flexbox(Split(the_text), config);
|
2021-12-12 00:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return an element drawing the paragraph on multiple lines, aligned on
|
|
|
|
/// the right.
|
|
|
|
/// @ingroup dom
|
|
|
|
/// @see flexbox.
|
2022-03-31 08:17:43 +08:00
|
|
|
Element paragraphAlignRight(const std::string& the_text) {
|
2021-12-12 00:58:25 +08:00
|
|
|
static const auto config =
|
|
|
|
FlexboxConfig().SetGap(1, 0).Set(FlexboxConfig::JustifyContent::FlexEnd);
|
2022-03-31 08:17:43 +08:00
|
|
|
return flexbox(Split(the_text), config);
|
2021-12-12 00:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return an element drawing the paragraph on multiple lines, aligned on
|
|
|
|
/// the center.
|
|
|
|
/// @ingroup dom
|
|
|
|
/// @see flexbox.
|
2022-03-31 08:17:43 +08:00
|
|
|
Element paragraphAlignCenter(const std::string& the_text) {
|
2021-12-12 00:58:25 +08:00
|
|
|
static const auto config =
|
|
|
|
FlexboxConfig().SetGap(1, 0).Set(FlexboxConfig::JustifyContent::Center);
|
2022-03-31 08:17:43 +08:00
|
|
|
return flexbox(Split(the_text), config);
|
2021-12-12 00:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return an element drawing the paragraph on multiple lines, aligned
|
|
|
|
/// using a justified alignment.
|
|
|
|
/// the center.
|
|
|
|
/// @ingroup dom
|
|
|
|
/// @see flexbox.
|
2022-03-31 08:17:43 +08:00
|
|
|
Element paragraphAlignJustify(const std::string& the_text) {
|
2021-12-12 00:58:25 +08:00
|
|
|
static const auto config = FlexboxConfig().SetGap(1, 0).Set(
|
|
|
|
FlexboxConfig::JustifyContent::SpaceBetween);
|
2022-03-31 08:17:43 +08:00
|
|
|
Elements words = Split(the_text);
|
2021-12-12 00:58:25 +08:00
|
|
|
words.push_back(text("") | xflex);
|
|
|
|
return flexbox(std::move(words), config);
|
|
|
|
}
|
2019-01-23 07:26:36 +08:00
|
|
|
|
|
|
|
} // namespace ftxui
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|