mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Add paragraph and fix hflow
This commit is contained in:
parent
610b86183b
commit
ce7867ab03
@ -19,3 +19,4 @@ example(style_underlined)
|
||||
example(size)
|
||||
example(vbox_hbox)
|
||||
example(hflow)
|
||||
example(paragraph)
|
||||
|
33
examples/dom/paragraph.cpp
Normal file
33
examples/dom/paragraph.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/screen/string.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
std::wstring p = LR"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
|
||||
|
||||
auto document =
|
||||
vbox(
|
||||
hbox(
|
||||
hflow(paragraph(p)) | border,
|
||||
hflow(paragraph(p)) | border,
|
||||
hflow(paragraph(p)) | border
|
||||
) | flex,
|
||||
hbox(
|
||||
hflow(paragraph(p)) | border,
|
||||
hflow(paragraph(p)) | border
|
||||
) | flex,
|
||||
hbox(
|
||||
hflow(paragraph(p)) | border
|
||||
) | flex
|
||||
);
|
||||
|
||||
auto screen = Screen::TerminalFullscreen();
|
||||
Render(screen, document.get());
|
||||
std::cout << screen.ToString();
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user