25class Text :
public Node {
27 explicit Text(std::string text) : text_(std::move(text)) {}
28 explicit Text(std::string_view sv) :
Text(std::string(sv)) {}
30 void ComputeRequirement()
override {
32 requirement_.min_y = 1;
33 has_selection =
false;
36 void Select(Selection& selection)
override {
41 const Selection selection_saturated = selection.SaturateHorizontal(box_);
44 selection_start_ = selection_saturated.GetBox().x_min;
45 selection_end_ = selection_saturated.GetBox().x_max;
53 if (selection_start_ <= x && x <= selection_end_) {
58 selection.AddPart(ss.str(), box_.y_min, selection_start_, selection_end_);
61 void Render(Screen& screen)
override {
63 const int y = box_.y_min;
76 screen.PixelAt(x, y).character = cell;
79 auto selectionTransform = screen.GetSelectionStyle();
80 if ((x >= selection_start_) && (x <= selection_end_)) {
81 selectionTransform(screen.PixelAt(x, y));
91 bool has_selection =
false;
92 int selection_start_ = 0;
93 int selection_end_ = -1;
96class VText :
public Node {
98 explicit VText(std::string text)
99 : text_(std::move(text)), width_{std::min(string_width(text_), 1)} {}
101 explicit VText(std::string_view sv) : VText(std::string(sv)) {}
103 void ComputeRequirement()
override {
104 requirement_.min_x = width_;
108 void Render(Screen& screen)
override {
109 const int x = box_.x_min;
111 if (x + width_ - 1 > box_.x_max) {
115 if (y > box_.y_max) {
118 screen.PixelAt(x, y).character = it;
146 return std::make_shared<Text>(std::string(text));
165 return std::make_shared<Text>(
to_string(text));
184 return text(std::wstring(sv));
214 return std::make_shared<VText>(std::string(text));
244 return std::make_shared<VText>(
to_string(text));
274 return vtext(std::wstring(text));
Element text(std::wstring text)
Display a piece of unicode text.
Element vtext(std::wstring text)
Display a piece unicode text vertically.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
static auto Intersection(Box a, Box b) -> Box
A rectangular grid of Pixel.
The FTXUI ftxui:: namespace.
std::shared_ptr< Node > Element
std::vector< std::string > Utf8ToGlyphs(std::string_view input)
std::string to_string(std::wstring_view s)
Convert a std::wstring into a UTF8 std::string.
int string_width(std::string_view)