Add paragraph and fix hflow

This commit is contained in:
Arthur Sonzogni
2019-01-23 00:26:36 +01:00
parent 610b86183b
commit ce7867ab03
6 changed files with 59 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ add_library(dom
src/ftxui/dom/inverted.cpp
src/ftxui/dom/node.cpp
src/ftxui/dom/node_decorator.cpp
src/ftxui/dom/paragraph.cpp
src/ftxui/dom/separator.cpp
src/ftxui/dom/size.cpp
src/ftxui/dom/spinner.cpp

View File

@@ -19,6 +19,7 @@ Element gauge(float ratio);
Element border(Element);
Element window(Element title, Element content);
Element spinner(int charset_index, size_t image_index);
Elements paragraph(std::wstring text); // Use inside hflow(). Split by space.
// -- Decorator ---
Element bold(Element);

View File

@@ -36,18 +36,18 @@ class HFlow : public Node {
}
// Does the current row big enough to contain the element?
if (y + requirement.min.y > box.y_max)
if (y + requirement.min.y > box.y_max + 1)
break; // No? Ignore the element.
Box children_box;
children_box.x_min = x;
children_box.x_max = x + requirement.min.x;
children_box.x_max = x + requirement.min.x - 1;
children_box.y_min = y;
children_box.y_max = y + requirement.min.y;
children_box.y_max = y + requirement.min.y - 1;
child->SetBox(children_box);
x = x + requirement.min.x + 1;
y_next = std::max(y_next, y + requirement.min.y + 1);
x = x + requirement.min.x;
y_next = std::max(y_next, y + requirement.min.y);
}
}
};

View File

@@ -0,0 +1,18 @@
#include <sstream>
#include "ftxui/dom/elements.hpp"
namespace ftxui {
Elements paragraph(std::wstring the_text) {
Elements output;
std::wstringstream ss(the_text);
std::wstring word;
while (std::getline(ss, word, L' ')) {
if (word.size()) {
output.push_back(text(word + L' '));
}
}
return output;
}
} // namespace ftxui