mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 18:18:09 +08:00
Implement flexbox (#277)
This implement the flexbox elements, following the HTML one. Built from them, there is also the following elements: - `paragraph` - `paragraphAlignLeft` - `paragraphAlignRight` - `paragraphAlignCenter` - `paragraphAlignJustify` This is a breaking change.
This commit is contained in:
@@ -1,35 +1,50 @@
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, hflow, paragraph, border, Element, hbox, flex, vbox
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <string> // for allocator, string
|
||||
#include <iostream> // for cout, ostream
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for string, operator<<
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/dom/elements.hpp" // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
int main(int argc, const char* argv[]) {
|
||||
using namespace ftxui;
|
||||
std::string p =
|
||||
R"(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,
|
||||
});
|
||||
std::string reset_position;
|
||||
for (int i = 0;; ++i) {
|
||||
auto document = vbox({
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hbox({
|
||||
hflow(paragraph(p)),
|
||||
separator(),
|
||||
hflow(paragraph(p)),
|
||||
}),
|
||||
}) |
|
||||
border;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Full());
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
getchar();
|
||||
document = vbox(filler(), document);
|
||||
|
||||
// auto screen = Screen::Create(Dimension::Fit(document));
|
||||
// Render(screen, document);
|
||||
// screen.Print();
|
||||
// getchar();
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position;
|
||||
screen.Print();
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user