mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 16:38:09 +08:00
Add paragraph and fix hflow
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
18
ftxui/src/ftxui/dom/paragraph.cpp
Normal file
18
ftxui/src/ftxui/dom/paragraph.cpp
Normal 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
|
Reference in New Issue
Block a user