Use shared_ptr instead of unique_ptr for elements.

This allow users to pass it into initializer list. Then clang-format
will produce 'acceptable' indentations.

This fixes:
https://github.com/ArthurSonzogni/FTXUI/issues/18
This commit is contained in:
ArthurSonzogni 2020-05-20 20:36:47 +02:00
parent 0aabc258a9
commit e1a71d5b9f
53 changed files with 520 additions and 523 deletions

View File

@ -57,27 +57,28 @@ class MyComponent : public Component {
container.Add(&input); container.Add(&input);
} }
// clang-format off
Element Render(std::wstring name, Component& component) { Element Render(std::wstring name, Component& component) {
return return hbox({
hbox(
text(name) | size(WIDTH, EQUAL, 8), text(name) | size(WIDTH, EQUAL, 8),
separator(), separator(),
component.Render() component.Render(),
); });
} }
Element Render() override { Element Render() override {
return return vbox({
vbox( Render(L"menu", menu),
Render(L"menu", menu), separator(), separator(),
Render(L"toggle", toggle), separator(), Render(L"toggle", toggle),
Render(L"checkbox", checkbox_container), separator(), separator(),
Render(L"radiobox", radiobox), separator(), Render(L"checkbox", checkbox_container),
Render(L"input", input) | size(WIDTH, LESS_THAN, 30) separator(),
) | border; Render(L"radiobox", radiobox),
separator(),
Render(L"input", input) | size(WIDTH, LESS_THAN, 30),
}) |
border;
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -41,49 +41,60 @@ class HTopComponent : public Component {
HTopComponent() {} HTopComponent() {}
~HTopComponent() override {} ~HTopComponent() override {}
// clang-format off
Element Render() override { Element Render() override {
return auto frequency = vbox({
hbox(
vbox(
// --- Frequency ---
text(L"Frequency [Mhz]") | hcenter, text(L"Frequency [Mhz]") | hcenter,
hbox( hbox({
vbox( vbox({
text(L"2400 "), filler(), text(L"2400 "),
text(L"1200 "), filler(), filler(),
text(L"0% ") text(L"1200 "),
), filler(),
graph(std::ref(my_graph)) text(L"0% "),
) | flex, }),
separator(), graph(std::ref(my_graph)) | flex,
// --- Utilization --- }) | flex,
});
auto utilization = vbox({
text(L"Utilization [%]") | hcenter, text(L"Utilization [%]") | hcenter,
hbox( hbox({
vbox( vbox({
text(L"100 "), filler(), text(L"100 "),
text(L"50 "), filler(), filler(),
text(L"0 ") text(L"50 "),
), filler(),
graph(std::ref(my_graph)) | color(Color::RedLight) text(L"0 "),
) | flex }),
) | flex, graph(std::ref(my_graph)) | color(Color::RedLight),
separator(), }) | flex,
// --- Ram --- });
vbox(
auto ram = vbox({
text(L"Ram [Mo]") | hcenter, text(L"Ram [Mo]") | hcenter,
hbox( hbox({
vbox( vbox({
text(L"8192"), filler(), text(L"8192"),
text(L"4096 "), filler(), filler(),
text(L"0 ") text(L"4096 "),
), filler(),
graph(std::ref(my_graph)) | color(Color::BlueLight) text(L"0 "),
) | flex }),
) | flex graph(std::ref(my_graph)) | color(Color::BlueLight),
) | flex | border; }) | flex,
});
return hbox({
vbox({
frequency | flex,
separator(),
utilization | flex,
}) | flex,
separator(),
ram | flex,
}) |
flex | border;
} }
// clang-format on
}; };
class CompilerComponent : public Component { class CompilerComponent : public Component {
@ -173,37 +184,38 @@ class CompilerComponent : public Component {
input_container.Add(&input); input_container.Add(&input);
} }
// clang-format off
Element Render() override { Element Render() override {
return auto compiler_win = window(text(L"Compiler"), compiler.Render() | frame);
vbox( auto flags_win = window(text(L"Flags"), flag.Render());
hbox( auto executable_win = window(text(L"Executable:"), executable.Render());
window(text(L"Compiler"), auto input_win =
compiler.Render() | frame | size(HEIGHT, LESS_THAN, 6)
),
window(text(L"Flags"), flag.Render()),
vbox(
window(text(L"Executable:"), executable.Render())
| size(WIDTH, EQUAL, 20),
window(text(L"Input"), window(text(L"Input"),
hbox( hbox({
vbox( vbox({
hbox(text(L"Add: "), input_add.Render()) hbox({
| size(WIDTH, EQUAL, 20) text(L"Add: "),
| size(HEIGHT, EQUAL, 1), input_add.Render(),
filler() }) | size(WIDTH, EQUAL, 20) |
), size(HEIGHT, EQUAL, 1),
filler(),
}),
separator(), separator(),
input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex,
) }));
) | size(WIDTH, EQUAL, 60) return vbox({
), hbox({
filler() compiler_win | size(HEIGHT, LESS_THAN, 6),
), flags_win,
hflow(RenderCommandLine()) vbox({
) | border; executable_win | size(WIDTH, EQUAL, 20),
input_win | size(WIDTH, EQUAL, 60),
}),
filler(),
}),
hflow(RenderCommandLine()),
}) |
border;
} }
// clang-format on
Elements RenderCommandLine() { Elements RenderCommandLine() {
Elements line; Elements line;
@ -230,29 +242,21 @@ class CompilerComponent : public Component {
}; };
class SpinnerComponent : public Component { class SpinnerComponent : public Component {
// clang-format off
Element Render() override { Element Render() override {
Elements entries; Elements entries;
for (int i = 0; i < 22; ++i) { for (int i = 0; i < 22; ++i) {
if (i != 0) if (i != 0)
entries.push_back( entries.push_back(spinner(i, shift / 2) | bold |
spinner(i, shift/2) size(WIDTH, GREATER_THAN, 2) | border);
| bold
| size(WIDTH, GREATER_THAN, 2)
| border
);
} }
return hflow(std::move(entries)) | border; return hflow(std::move(entries)) | border;
} }
// clang-format on
}; };
class ColorComponent : public Component { class ColorComponent : public Component {
// clang-format off
Element Render() override { Element Render() override {
return return hbox({
hbox( vbox({
vbox(
color(Color::Default, text(L"Default")), color(Color::Default, text(L"Default")),
color(Color::Black, text(L"Black")), color(Color::Black, text(L"Black")),
color(Color::GrayDark, text(L"GrayDark")), color(Color::GrayDark, text(L"GrayDark")),
@ -269,9 +273,9 @@ class ColorComponent : public Component {
color(Color::Red, text(L"Red")), color(Color::Red, text(L"Red")),
color(Color::RedLight, text(L"RedLight")), color(Color::RedLight, text(L"RedLight")),
color(Color::Yellow, text(L"Yellow")), color(Color::Yellow, text(L"Yellow")),
color(Color::YellowLight, text(L"YellowLight")) color(Color::YellowLight, text(L"YellowLight")),
), }),
vbox( vbox({
bgcolor(Color::Default, text(L"Default")), bgcolor(Color::Default, text(L"Default")),
bgcolor(Color::Black, text(L"Black")), bgcolor(Color::Black, text(L"Black")),
bgcolor(Color::GrayDark, text(L"GrayDark")), bgcolor(Color::GrayDark, text(L"GrayDark")),
@ -288,27 +292,29 @@ class ColorComponent : public Component {
bgcolor(Color::Red, text(L"Red")), bgcolor(Color::Red, text(L"Red")),
bgcolor(Color::RedLight, text(L"RedLight")), bgcolor(Color::RedLight, text(L"RedLight")),
bgcolor(Color::Yellow, text(L"Yellow")), bgcolor(Color::Yellow, text(L"Yellow")),
bgcolor(Color::YellowLight, text(L"YellowLight")) bgcolor(Color::YellowLight, text(L"YellowLight")),
) }),
) | hcenter | border; }) |
// clang-format on hcenter | border;
} }
}; };
class GaugeComponent : public Component { class GaugeComponent : public Component {
// clang-format off
Element RenderGauge(int delta) { Element RenderGauge(int delta) {
float progress = (shift + delta) % 1000 / 1000.f; float progress = (shift + delta) % 1000 / 1000.f;
return hbox(text(std::to_wstring(int(progress * 100)) + L"% ") | size(WIDTH, EQUAL, 5), return hbox({
gauge(progress)); text(std::to_wstring(int(progress * 100)) + L"% ") |
size(WIDTH, EQUAL, 5),
gauge(progress),
});
} }
Element Render() override { Element Render() override {
return return vbox({
vbox(
RenderGauge(0) | color(Color::Black), RenderGauge(0) | color(Color::Black),
RenderGauge(100) | color(Color::GrayDark), RenderGauge(100) | color(Color::GrayDark),
RenderGauge(50) | color(Color::GrayLight), RenderGauge(50) | color(Color::GrayLight),
RenderGauge(6894) | color(Color::White), separator(), RenderGauge(6894) | color(Color::White),
separator(),
RenderGauge(6841) | color(Color::Blue), RenderGauge(6841) | color(Color::Blue),
RenderGauge(9813) | color(Color::BlueLight), RenderGauge(9813) | color(Color::BlueLight),
RenderGauge(98765) | color(Color::Cyan), RenderGauge(98765) | color(Color::Cyan),
@ -320,10 +326,10 @@ class GaugeComponent : public Component {
RenderGauge(568) | color(Color::Red), RenderGauge(568) | color(Color::Red),
RenderGauge(2222) | color(Color::RedLight), RenderGauge(2222) | color(Color::RedLight),
RenderGauge(220) | color(Color::Yellow), RenderGauge(220) | color(Color::Yellow),
RenderGauge(348) | color(Color::YellowLight) RenderGauge(348) | color(Color::YellowLight),
) | border; }) |
border;
}; };
// clang-format on
}; };
class Tab : public Component { class Tab : public Component {
@ -354,8 +360,11 @@ class Tab : public Component {
} }
Element Render() override { Element Render() override {
return vbox(text(L"FTXUI Demo") | bold | hcenter, return vbox({
tab_selection.Render() | hcenter, container.Render()); text(L"FTXUI Demo") | bold | hcenter,
tab_selection.Render() | hcenter,
container.Render(),
});
} }
}; };

View File

@ -33,18 +33,13 @@ class MyComponent : public Component {
Input input_2; Input input_2;
Input input_3; Input input_3;
// clang-format off
Element Render() override { Element Render() override {
return return border(vbox({
border( hbox({text(L" input_1 : "), input_1.Render()}),
vbox( hbox({text(L" input_2 : "), input_2.Render()}),
hbox(text(L" input_1 : "), input_1.Render()), hbox({text(L" input_3 : "), input_3.Render()}),
hbox(text(L" input_2 : "), input_2.Render()), }));
hbox(text(L" input_3 : "), input_3.Render())
)
);
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -40,38 +40,39 @@ class MyComponent : public Component {
Menu left_menu; Menu left_menu;
Menu right_menu; Menu right_menu;
// clang-format off
Element Render() override { Element Render() override {
int sum = left_menu.selected * 10 + right_menu.selected; int sum = left_menu.selected * 10 + right_menu.selected;
return return border(vbox({
border(
vbox(
// -------- Top panel -------------- // -------- Top panel --------------
hbox( hbox({
// -------- Left Menu -------------- // -------- Left Menu --------------
vbox( vbox({
hcenter(bold(text(L"Percentage by 10%"))), hcenter(bold(text(L"Percentage by 10%"))),
separator(), separator(),
left_menu.Render() left_menu.Render(),
) | flex, }) | flex,
// -------- Right Menu -------------- // -------- Right Menu --------------
vbox( vbox({
hcenter(bold(text(L"Percentage by 1%"))), hcenter(bold(text(L"Percentage by 1%"))),
separator(), separator(),
right_menu.Render() right_menu.Render(),
) | flex, }) | flex,
filler() filler(),
), }),
separator(), separator(),
// -------- Bottom panel -------------- // -------- Bottom panel --------------
vbox( vbox({
hbox(text(L" gauge : "), gauge(sum/100.0)), hbox({
hbox(text(L" text : "), text(to_wstring(std::to_string(sum) + " %"))) text(L" gauge : "),
) | flex gauge(sum / 100.0),
) }),
); hbox({
text(L" text : "),
text(to_wstring(std::to_string(sum) + " %")),
}),
}) | flex,
}));
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -57,14 +57,14 @@ class MyComponent : public Component {
// clang-format off // clang-format off
Element Render() override { Element Render() override {
return return
hbox( hbox({
menu_1.Render() | flex, separator(), menu_1.Render() | flex, separator(),
menu_2.Render() | flex, separator(), menu_2.Render() | flex, separator(),
menu_3.Render() | flex, separator(), menu_3.Render() | flex, separator(),
menu_4.Render() | flex, separator(), menu_4.Render() | flex, separator(),
menu_5.Render() | flex, separator(), menu_5.Render() | flex, separator(),
menu_6.Render() | flex menu_6.Render() | flex,
) | border; }) | border;
} }
// clang-format on // clang-format on
}; };

View File

@ -38,19 +38,24 @@ class MyComponent : public Component {
Toggle toggle_3_; Toggle toggle_3_;
Toggle toggle_4_; Toggle toggle_4_;
// clang-format off
Element Render() override { Element Render() override {
return return vbox({
vbox(
text(L"Choose your options:"), text(L"Choose your options:"),
text(L""), text(L""),
hbox(text(L" * Poweroff on startup : "), toggle_1_.Render()), hbox(text(L" * Poweroff on startup : "), toggle_1_.Render()),
hbox(text(L" * Out of process : "), toggle_2_.Render()), hbox(text(L" * Out of process : "), toggle_2_.Render()),
hbox(text(L" * Price of the information : "), toggle_3_.Render()), hbox(text(L" * Price of the information : "), toggle_3_.Render()),
hbox(text(L" * Number of elements : "), toggle_4_.Render()) hbox(text(L" * Number of elements : "), toggle_4_.Render()),
); });
}
bool OnEvent(Event event) {
if (event == Event::Return) {
on_enter();
return true;
}
return Component::OnEvent(event);
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -11,41 +11,33 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = hbox({
auto document =
hbox(
window(text(L" main frame ") | hcenter, window(text(L" main frame ") | hcenter,
vbox( vbox({
text(L"Line 1"), text(L"Line 1"),
text(L"Line 2"), text(L"Line 2"),
text(L"Line 3"), text(L"Line 3"),
vbox( vbox({
text(L"Line 4"), text(L"Line 4"),
text(L"Line 5"), text(L"Line 5"),
text(L"Line 6") text(L"Line 6"),
) | border, }) | border,
hbox( hbox({
window(text(L"frame 2"), window(text(L"frame 2"), vbox({
vbox(
text(L"Line 4"), text(L"Line 4"),
text(L"Line 5"), text(L"Line 5"),
text(L"Line 6") text(L"Line 6"),
) })),
), window(text(L"frame 3"), vbox({
window(text(L"frame 3"),
vbox(
text(L"Line 7"), text(L"Line 7"),
text(L"Line 8"), text(L"Line 8"),
text(L"Line 9") text(L"Line 9"),
) })),
) }),
), text(L"footer footer footer footer footer"),
text(L"footer footer footer footer footer") })),
) filler(),
), });
filler()
);
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString() << std::endl; std::cout << screen.ToString() << std::endl;

View File

@ -9,19 +9,16 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = dbox({
auto document = vbox({
dbox(
vbox(
text(L"line_1"), text(L"line_1"),
text(L"line_2"), text(L"line_2"),
text(L"line_3"), text(L"line_3"),
text(L"line_4"), text(L"line_4"),
text(L"line_5") text(L"line_5"),
) | border, }) | border,
text(L"overlay") | border | center text(L"overlay") | border | center,
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -17,14 +17,11 @@ int main(int argc, const char* argv[]) {
for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) { for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
std::wstring data_downloaded = std::wstring data_downloaded =
std::to_wstring(int(percentage * 5000)) + L"/5000"; std::to_wstring(int(percentage * 5000)) + L"/5000";
// clang-format off auto document = hbox({
auto document =
hbox(
text(L"downloading:"), text(L"downloading:"),
gauge(percentage) | flex, gauge(percentage) | flex,
text(L" " + data_downloaded) text(L" " + data_downloaded),
); });
// clang-format on
auto screen = Screen(100, 1); auto screen = Screen(100, 1);
Render(screen, document.get()); Render(screen, document.get());
std::cout << reset_position << screen.ToString() << std::flush; std::cout << reset_position << screen.ToString() << std::flush;

View File

@ -45,23 +45,23 @@ int main(int argc, const char* argv[]) {
std::string reset_position; std::string reset_position;
for (int i = 0;; ++i) { for (int i = 0;; ++i) {
// clang-format off
auto document = auto document =
hbox( hbox({
vbox( vbox({
graph(std::ref(my_graph)), separator(), graph(std::ref(my_graph)),
graph(triangle) | inverted
) | flex,
separator(), separator(),
vbox( graph(triangle) | inverted,
graph(std::ref(my_graph)) | color(Color::BlueLight), separator(), }) | flex,
graph(std::ref(my_graph)) | color(Color::RedLight), separator(), separator(),
graph(std::ref(my_graph)) | color(Color::YellowLight) vbox({
) | flex graph(std::ref(my_graph)) | color(Color::BlueLight),
) separator(),
| border graph(std::ref(my_graph)) | color(Color::RedLight),
| size(HEIGHT, GREATER_THAN, 40); separator(),
// clang-format on graph(std::ref(my_graph)) | color(Color::YellowLight),
}) | flex,
}) |
border | size(HEIGHT, GREATER_THAN, 40);
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -12,25 +12,35 @@ int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
auto make_box = [](size_t dimx, size_t dimy) { auto make_box = [](size_t dimx, size_t dimy) {
std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy); std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy);
// clang-format off
return window(text(title) | hcenter | bold, return window(text(title) | hcenter | bold,
text(L"content") | hcenter | dim) | text(L"content") | hcenter | dim) |
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy); size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
// clang-format on
}; };
// clang-format off auto style = size(WIDTH, GREATER_THAN, 20) | border |
auto document = size(HEIGHT, GREATER_THAN, 30) | size(WIDTH, LESS_THAN, 50);
hflow(make_box(7, 7), make_box(7, 5), make_box(5, 7), make_box(10, 4),
make_box(10, 4), make_box(10, 4), make_box(10, 4), make_box(11, 4), auto document = hflow({
make_box(11, 4), make_box(11, 4), make_box(11, 4), make_box(12, 4), make_box(7, 7),
make_box(12, 5), make_box(12, 4), make_box(13, 4), make_box(13, 3), make_box(7, 5),
make_box(13, 3), make_box(10, 3)) make_box(5, 7),
| size(WIDTH, GREATER_THAN, 20) make_box(10, 4),
| border make_box(10, 4),
| size(HEIGHT, GREATER_THAN, 30) make_box(10, 4),
| size(WIDTH, LESS_THAN, 50); make_box(10, 4),
// clang-format on make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(11, 4),
make_box(12, 4),
make_box(12, 5),
make_box(12, 4),
make_box(13, 4),
make_box(13, 3),
make_box(13, 3),
make_box(10, 3),
}) |
style;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -15,11 +15,11 @@ int main(int argc, const char* argv[]) {
using namespace std::chrono_literals; using namespace std::chrono_literals;
auto img1 = []() { return text(L"img") | border; }; auto img1 = []() { return text(L"img") | border; };
auto img2 = []() { return vbox(text(L"big"), text(L"image")) | border; }; auto img2 = []() { return vbox({text(L"big"), text(L"image")}) | border; };
std::string reset_position; std::string reset_position;
for (int i = 0;; ++i) { for (int i = 0;; ++i) {
auto document = auto document = //
hflow( hflow(
paragraph(L"Hello world! Here is an image:"), img1(), paragraph(L"Hello world! Here is an image:"), img1(),
paragraph(L" Here is a text "), text(L"underlined ") | underlined, paragraph(L" Here is a text "), text(L"underlined ") | underlined,

View File

@ -49,30 +49,36 @@ int main(int argc, const char* argv[]) {
return text(to_wstring(number)) | size(WIDTH, EQUAL, 3); return text(to_wstring(number)) | size(WIDTH, EQUAL, 3);
}; };
// clang-format off
auto renderTask = [&](const Task& task) { auto renderTask = [&](const Task& task) {
auto style = (task.downloaded == task.size) ? dim : bold; auto style = (task.downloaded == task.size) ? dim : bold;
return return hbox({
hbox(
text(task.name) | style, text(task.name) | style,
separator(), separator(),
to_text(task.downloaded), to_text(task.downloaded),
text(L"/"), text(L"/"),
to_text(task.size), to_text(task.size),
separator(), separator(),
gauge(task.downloaded / float(task.size)) gauge(task.downloaded / float(task.size)),
); });
}; };
auto renderSummary = [&]() { auto renderSummary = [&]() {
return auto summary = vbox({
window(text(L" Summary "), hbox({
vbox( text(L"- done: "),
hbox(text(L"- done: "), to_text(nb_done) | bold) | color(Color::Green), to_text(nb_done) | bold,
hbox(text(L"- active: "), to_text(nb_active) | bold ) | color(Color::RedLight), }) | color(Color::Green),
hbox(text(L"- queue: "), to_text(nb_queued) | bold) | color(Color::Red) hbox({
) text(L"- active: "),
); to_text(nb_active) | bold,
}) | color(Color::RedLight),
hbox({
text(L"- queue: "),
to_text(nb_queued) | bold,
}) | color(Color::Red),
});
return window(text(L" Summary "), summary);
}; };
auto render = [&]() { auto render = [&]() {
@ -80,18 +86,17 @@ int main(int argc, const char* argv[]) {
for (auto& task : displayed_task) for (auto& task : displayed_task)
entries.push_back(renderTask(task)); entries.push_back(renderTask(task));
return return vbox({
vbox(
// List of tasks. // List of tasks.
window(text(L" Task "), window(text(L" Task "), vbox(std::move(entries))),
vbox(std::move(entries))
),
// Summary. // Summary.
hbox(renderSummary(), filler()) hbox({
); renderSummary(),
filler(),
}),
});
}; };
// clang-format on
auto updateModel = [&]() { auto updateModel = [&]() {
for (auto& task : displayed_task) { for (auto& task : displayed_task) {

View File

@ -13,25 +13,22 @@ int main(int argc, const char* argv[]) {
std::wstring p = 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.)"; 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.)";
// clang-format off auto document = vbox({
auto document = hbox({
vbox(
hbox(
hflow(paragraph(p)) | border, hflow(paragraph(p)) | border,
hflow(paragraph(p)) | border, hflow(paragraph(p)) | border,
hflow(paragraph(p)) | border
) | flex,
hbox(
hflow(paragraph(p)) | border, hflow(paragraph(p)) | border,
hflow(paragraph(p)) | border }) | flex,
) | flex, hbox({
hbox( hflow(paragraph(p)) | border,
hflow(paragraph(p)) | border hflow(paragraph(p)) | border,
) | flex }) | flex,
); hbox({
// clang-format on hflow(paragraph(p)) | border,
}) | flex,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Full());
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();
getchar(); getchar();

View File

@ -9,20 +9,18 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = hbox({
auto document =
hbox(
text(L"left-column"), text(L"left-column"),
separator(), separator(),
vbox( vbox({
center(text(L"right-top")) | flex, center(text(L"right-top")) | flex,
separator(), separator(),
center(text(L"bottom-bottom")) center(text(L"bottom-bottom")),
) | flex, }) | flex,
separator(), separator(),
text(L"right-column") text(L"right-column"),
) | border; }) |
// clang-format on border;
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -10,7 +10,6 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto make_box = [](const std::wstring title) { auto make_box = [](const std::wstring title) {
return return
window( window(
@ -26,7 +25,7 @@ int main(int argc, const char* argv[]) {
| size(WIDTH, EQUAL, x) | size(WIDTH, EQUAL, x)
); );
} }
// clang-format on
auto document = hbox(std::move(content)); auto document = hbox(std::move(content));
auto screen = Screen::Create(Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -20,17 +20,17 @@ int main(int argc, const char* argv[]) {
for (int i = 0; i < 22; ++i) { for (int i = 0; i < 22; ++i) {
if (i != 0) if (i != 0)
entries.push_back(separator()); entries.push_back(separator());
// clang-format off entries.push_back( //
entries.push_back( hbox({
hbox(
text(to_wstring(i)) | size(WIDTH, EQUAL, 2), text(to_wstring(i)) | size(WIDTH, EQUAL, 2),
separator(), separator(),
spinner(i, index) | bold spinner(i, index) | bold,
) }));
);
// clang-format on
} }
auto document = hbox(vbox(std::move(entries)) | border, filler()); auto document = hbox({
vbox(std::move(entries)) | border,
filler(),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());
std::cout << reset_position << screen.ToString() << std::flush; std::cout << reset_position << screen.ToString() << std::flush;

View File

@ -9,14 +9,12 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = //
auto document = hbox({
hbox(
text(L"This text is "), text(L"This text is "),
text(L"blink") | blink, text(L"blink") | blink,
text(L". Do you like it?") text(L". Do you like it?"),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -9,14 +9,12 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = //
auto document = hbox({
hbox(
text(L"This text is "), text(L"This text is "),
text(L"bold") | bold, text(L"bold") | bold,
text(L". Do you like it?") text(L". Do you like it?"),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -9,14 +9,12 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = //
auto document = hbox({
hbox(
text(L"This text is "), text(L"This text is "),
text(L"dim") | dim, text(L"dim") | dim,
text(L". Do you like it?") text(L". Do you like it?"),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -11,7 +11,7 @@ int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off // clang-format off
auto document = auto document =
hbox( hbox({
text(L"normal") , text(L" ") , text(L"normal") , text(L" ") ,
text(L"bold") | bold , text(L" ") , text(L"bold") | bold , text(L" ") ,
text(L"dim") | dim , text(L" ") , text(L"dim") | dim , text(L" ") ,
@ -19,8 +19,8 @@ int main(int argc, const char* argv[]) {
text(L"underlined")| underlined , text(L" ") , text(L"underlined")| underlined , text(L" ") ,
text(L"blink") | blink , text(L" ") , text(L"blink") | blink , text(L" ") ,
text(L"color") | color(Color::Blue) , text(L" ") , text(L"color") | color(Color::Blue) , text(L" ") ,
text(L"bgcolor") | bgcolor(Color::Blue) text(L"bgcolor") | bgcolor(Color::Blue),
); });
// clang-format on // clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -9,14 +9,11 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = hbox({
auto document =
hbox(
text(L"This text is "), text(L"This text is "),
text(L"inverted") | inverted, text(L"inverted") | inverted,
text(L". Do you like it?") text(L". Do you like it?"),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -9,14 +9,12 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = //
auto document = hbox({
hbox(
text(L"This text is "), text(L"This text is "),
text(L"underlined") | underlined, text(L"underlined") | underlined,
text(L". Do you like it?") text(L". Do you like it?"),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -9,34 +9,31 @@
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off auto document = //
auto document = vbox({
vbox( hbox({
hbox(
text(L"north-west"), text(L"north-west"),
filler(), filler(),
text(L"north-east") text(L"north-east"),
), }),
filler(), filler(),
hbox( hbox({
hbox(
filler(), filler(),
text(L"center"), text(L"center"),
filler()
)
),
filler(), filler(),
hbox( }),
filler(),
hbox({
text(L"south-west"), text(L"south-west"),
filler(), filler(),
text(L"south-east") text(L"south-east"),
) }),
); });
// clang-format on
auto screen = Screen::Create(Dimension::Full()); auto screen = Screen::Create(Dimension::Full());
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();
getchar();
return 0; return 0;
} }

View File

@ -6,20 +6,22 @@
#define FTXUI_DOM_ELEMENTS_HPP #define FTXUI_DOM_ELEMENTS_HPP
#include <functional> #include <functional>
#include <memory>
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/screen/color.hpp" #include "ftxui/screen/color.hpp"
#include "ftxui/screen/screen.hpp"
namespace ftxui { namespace ftxui {
class Node;
using Element = std::unique_ptr<Node>; using Element = std::shared_ptr<Node>;
using Elements = std::vector<Element>; using Elements = std::vector<Element>;
using Decorator = std::function<Element(Element)>; using Decorator = std::function<Element(Element)>;
using GraphFunction = std::function<std::vector<int>(int, int)>; using GraphFunction = std::function<std::vector<int>(int, int)>;
// --- Widget --- // --- Widget ---
Element text(std::wstring text); Element text(std::wstring text);
Element separator(); Element separator(void);
Element separator(Pixel); Element separator(Pixel);
Element gauge(float ratio); Element gauge(float ratio);
Element border(Element); Element border(Element);

View File

@ -14,10 +14,13 @@
namespace ftxui { namespace ftxui {
using Element = std::shared_ptr<Node>;
using Elements = std::vector<std::shared_ptr<Node>>;
class Node { class Node {
public: public:
Node(); Node();
Node(std::vector<std::unique_ptr<Node>> children); Node(Elements children);
virtual ~Node(); virtual ~Node();
// Step 1: Compute layout requirement. Tell parent what dimensions this // Step 1: Compute layout requirement. Tell parent what dimensions this
@ -33,7 +36,7 @@ class Node {
// Step 3: Draw this element. // Step 3: Draw this element.
virtual void Render(Screen& screen); virtual void Render(Screen& screen);
std::vector<std::unique_ptr<Node>> children; std::vector<Element> children;
protected: protected:
Requirement requirement_; Requirement requirement_;

View File

@ -31,7 +31,7 @@ struct Pixel {
struct Dimension { struct Dimension {
static Dimension Fixed(int); static Dimension Fixed(int);
static Dimension Fit(std::unique_ptr<Node>&); static Dimension Fit(std::shared_ptr<Node>&);
static Dimension Full(); static Dimension Full();
int dimx; int dimx;

View File

@ -22,8 +22,8 @@ class Blink : public NodeDecorator {
} }
}; };
std::unique_ptr<Node> blink(Element child) { Element blink(Element child) {
return std::make_unique<Blink>(unpack(std::move(child))); return std::make_shared<Blink>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -22,8 +22,8 @@ class Bold : public NodeDecorator {
} }
}; };
std::unique_ptr<Node> bold(Element child) { Element bold(Element child) {
return std::make_unique<Bold>(unpack(std::move(child))); return std::make_shared<Bold>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -105,17 +105,17 @@ class Border : public Node {
} }
}; };
std::unique_ptr<Node> border(Element child) { Element border(Element child) {
return std::make_unique<Border>(unpack(std::move(child))); return std::make_shared<Border>(unpack(std::move(child)));
} }
std::unique_ptr<Node> window(Element title, Element content) { Element window(Element title, Element content) {
return std::make_unique<Border>(unpack(std::move(content), std::move(title))); return std::make_shared<Border>(unpack(std::move(content), std::move(title)));
} }
Decorator borderWith(Pixel pixel) { Decorator borderWith(Pixel pixel) {
return [pixel](Element child) { return [pixel](Element child) {
return std::make_unique<Border>(unpack(std::move(child)), pixel); return std::make_shared<Border>(unpack(std::move(child)), pixel);
}; };
} }

View File

@ -42,12 +42,12 @@ class FgColor : public NodeDecorator {
Color color_; Color color_;
}; };
std::unique_ptr<Node> color(Color c, Element child) { Element color(Color c, Element child) {
return std::make_unique<FgColor>(unpack(std::move(child)), c); return std::make_shared<FgColor>(unpack(std::move(child)), c);
} }
std::unique_ptr<Node> bgcolor(Color c, Element child) { Element bgcolor(Color c, Element child) {
return std::make_unique<BgColor>(unpack(std::move(child)), c); return std::make_shared<BgColor>(unpack(std::move(child)), c);
} }
Decorator color(Color c) { Decorator color(Color c) {

View File

@ -7,19 +7,19 @@
namespace ftxui { namespace ftxui {
std::unique_ptr<Node> hcenter(Element child) { Element hcenter(Element child) {
return hbox(filler(), std::move(child), filler()); return hbox(filler(), std::move(child), filler());
} }
std::unique_ptr<Node> vcenter(Element child) { Element vcenter(Element child) {
return vbox(filler(), std::move(child), filler()); return vbox(filler(), std::move(child), filler());
} }
std::unique_ptr<Node> center(Element child) { Element center(Element child) {
return hcenter(vcenter(std::move(child))); return hcenter(vcenter(std::move(child)));
} }
std::unique_ptr<Node> align_right(Element child) { Element align_right(Element child) {
return hbox(filler(), std::move(child)); return hbox(filler(), std::move(child));
} }

View File

@ -41,8 +41,8 @@ class DBox : public Node {
} }
}; };
std::unique_ptr<Node> dbox(Elements children) { Element dbox(Elements children) {
return std::make_unique<DBox>(std::move(children)); return std::make_shared<DBox>(std::move(children));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -24,8 +24,8 @@ class Dim : public NodeDecorator {
} }
}; };
std::unique_ptr<Node> dim(Element child) { Element dim(Element child) {
return std::make_unique<Dim>(unpack(std::move(child))); return std::make_shared<Dim>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -47,16 +47,16 @@ class NotFlex : public Flex {
} }
}; };
std::unique_ptr<Node> filler() { Element filler() {
return std::make_unique<Flex>(); return std::make_shared<Flex>();
} }
std::unique_ptr<Node> flex(Element child) { Element flex(Element child) {
return std::make_unique<Flex>(std::move(child)); return std::make_shared<Flex>(std::move(child));
} }
std::unique_ptr<Node> notflex(Element child) { Element notflex(Element child) {
return std::make_unique<NotFlex>(std::move(child)); return std::make_shared<NotFlex>(std::move(child));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -14,7 +14,7 @@ namespace ftxui {
class Select : public Node { class Select : public Node {
public: public:
Select(std::vector<std::unique_ptr<Node>> children) Select(std::vector<std::shared_ptr<Node>> children)
: Node(std::move(children)) {} : Node(std::move(children)) {}
void ComputeRequirement() override { void ComputeRequirement() override {
@ -34,15 +34,15 @@ class Select : public Node {
} }
}; };
std::unique_ptr<Node> select(Element child) { Element select(Element child) {
return std::make_unique<Select>(unpack(std::move(child))); return std::make_shared<Select>(unpack(std::move(child)));
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class Focus : public Select { class Focus : public Select {
public: public:
Focus(std::vector<std::unique_ptr<Node>> children) Focus(std::vector<Element> children)
: Select(std::move(children)) {} : Select(std::move(children)) {}
void ComputeRequirement() override { void ComputeRequirement() override {
@ -56,15 +56,15 @@ class Focus : public Select {
} }
}; };
std::unique_ptr<Node> focus(Element child) { Element focus(Element child) {
return std::make_unique<Focus>(unpack(std::move(child))); return std::make_shared<Focus>(unpack(std::move(child)));
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class Frame : public Node { class Frame : public Node {
public: public:
Frame(std::vector<std::unique_ptr<Node>> children) Frame(std::vector<Element> children)
: Node(std::move(children)) {} : Node(std::move(children)) {}
void ComputeRequirement() override { void ComputeRequirement() override {
@ -123,8 +123,8 @@ class Frame : public Node {
} }
}; };
std::unique_ptr<Node> frame(Element child) { Element frame(Element child) {
return std::make_unique<Frame>(unpack(std::move(child))); return std::make_shared<Frame>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -35,8 +35,8 @@ class Gauge : public Node {
float progress_; float progress_;
}; };
std::unique_ptr<Node> gauge(float progress) { Element gauge(float progress) {
return std::make_unique<Gauge>(progress); return std::make_shared<Gauge>(progress);
} }
} // namespace ftxui } // namespace ftxui

View File

@ -42,8 +42,8 @@ class Graph : public Node {
GraphFunction graph_function_; GraphFunction graph_function_;
}; };
std::unique_ptr<Node> graph(GraphFunction graph_function) { Element graph(GraphFunction graph_function) {
return std::make_unique<Graph>(graph_function); return std::make_shared<Graph>(graph_function);
} }
} // namespace ftxui } // namespace ftxui

View File

@ -68,8 +68,8 @@ class HBox : public Node {
} }
}; };
std::unique_ptr<Node> hbox(Elements children) { Element hbox(Elements children) {
return std::make_unique<HBox>(std::move(children)); return std::make_shared<HBox>(std::move(children));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -58,8 +58,8 @@ class HFlow : public Node {
} }
}; };
std::unique_ptr<Node> hflow(Elements children) { Element hflow(Elements children) {
return std::make_unique<HFlow>(std::move(children)); return std::make_shared<HFlow>(std::move(children));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -24,8 +24,8 @@ class Inverted : public NodeDecorator {
} }
}; };
std::unique_ptr<Node> inverted(Element child) { Element inverted(Element child) {
return std::make_unique<Inverted>(unpack(std::move(child))); return std::make_shared<Inverted>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -9,8 +9,7 @@ namespace ftxui {
using ftxui::Screen; using ftxui::Screen;
Node::Node() {} Node::Node() {}
Node::Node(std::vector<std::unique_ptr<Node>> children) Node::Node(Elements children) : children(std::move(children)) {}
: children(std::move(children)) {}
Node::~Node() {} Node::~Node() {}
void Node::ComputeRequirement() { void Node::ComputeRequirement() {

View File

@ -5,7 +5,6 @@
#ifndef FTXUI_DOM_NODE_DECORATOR_H_ #ifndef FTXUI_DOM_NODE_DECORATOR_H_
#define FTXUI_DOM_NODE_DECORATOR_H_ #define FTXUI_DOM_NODE_DECORATOR_H_
#include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {

View File

@ -49,12 +49,12 @@ class SeparatorWithPixel : public Separator {
Pixel p; Pixel p;
}; };
std::unique_ptr<Node> separator() { Element separator() {
return std::make_unique<Separator>(); return std::make_shared<Separator>();
} }
std::unique_ptr<Node> separator(Pixel pixel) { Element separator(Pixel pixel) {
return std::make_unique<SeparatorWithPixel>(pixel); return std::make_shared<SeparatorWithPixel>(pixel);
} }
} // namespace ftxui } // namespace ftxui

View File

@ -76,7 +76,7 @@ class Size : public Node {
Decorator size(Direction direction, Constraint constraint, int value) { Decorator size(Direction direction, Constraint constraint, int value) {
return [=](Element e) { return [=](Element e) {
return std::make_unique<Size>(std::move(e), direction, constraint, value); return std::make_shared<Size>(std::move(e), direction, constraint, value);
}; };
} }

View File

@ -245,7 +245,7 @@ static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
L" LOLLOL ", L" LOLLOL ",
}}}; }}};
std::unique_ptr<Node> spinner(int c, size_t index) { Element spinner(int c, size_t index) {
if (c == 0) { if (c == 0) {
index %= 40; index %= 40;
if (index > 20) if (index > 20)

View File

@ -36,8 +36,8 @@ class Text : public Node {
std::wstring text_; std::wstring text_;
}; };
std::unique_ptr<Node> text(std::wstring text) { Element text(std::wstring text) {
return std::make_unique<Text>(text); return std::make_shared<Text>(text);
} }
} // namespace ftxui } // namespace ftxui

View File

@ -24,8 +24,8 @@ class Underlined : public NodeDecorator {
} }
}; };
std::unique_ptr<Node> underlined(Element child) { Element underlined(Element child) {
return std::make_unique<Underlined>(unpack(std::move(child))); return std::make_shared<Underlined>(unpack(std::move(child)));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -69,8 +69,8 @@ class VBox : public Node {
} }
}; };
std::unique_ptr<Node> vbox(Elements children) { Element vbox(Elements children) {
return std::make_unique<VBox>(std::move(children)); return std::make_shared<VBox>(std::move(children));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -52,7 +52,7 @@ Dimension Dimension::Fixed(int v) {
return Dimension{v, v}; return Dimension{v, v};
} }
Dimension Dimension::Fit(std::unique_ptr<Node>& e) { Dimension Dimension::Fit(std::shared_ptr<Node>& e) {
e->ComputeRequirement(); e->ComputeRequirement();
Terminal::Dimensions size = Terminal::Size(); Terminal::Dimensions size = Terminal::Size();
return Dimension{std::min(e->requirement().min.x, size.dimx), return Dimension{std::min(e->requirement().min.x, size.dimx),

View File

@ -18,13 +18,13 @@ main.cpp
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
using namespace ftxui; using namespace ftxui;
auto document = auto document =
hbox( hbox({
text(L"left") | bold | border, text(L"left") | bold | border,
text(L"middle") | flex | border, text(L"middle") | flex | border,
text(L"right") | border text(L"right") | border,
); });
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document);
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -18,13 +18,13 @@ main.cpp
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
using namespace ftxui; using namespace ftxui;
auto document = auto document =
hbox( hbox({
text(L"left") | bold | border, text(L"left") | bold | border,
text(L"middle") | flex | border, text(L"middle") | flex | border,
text(L"right") | border text(L"right") | border,
); });
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document);
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -132,17 +132,19 @@ Display a vertical or horizontal line to visually split the content of a
container in two. container in two.
~~~cpp ~~~cpp
border(hbox( border(
vbox( hbox({
vbox({
text(L"left top"), text(L"left top"),
text(L"left bottom") text(L"left bottom"),
), }),
separator(), separator(),
vbox( vbox({
text(L"right top"), text(L"right top"),
text(L"right bottom") text(L"right bottom"),
) }),
)); })
);
~~~ ~~~
~~~bash ~~~bash
@ -213,11 +215,11 @@ An horizontal flow layout is implemented by:
#### Examples #### Examples
~~~cpp ~~~cpp
hbox( hbox({
text(L"left") | border , text(L"left") | border ,
text(L"middle") | border | flex, text(L"middle") | border | flex,
text(L"right") | border text(L"right") | border,
); });
~~~ ~~~
~~~bash ~~~bash
┌────┐┌─────────────────────────────────────────────────────────────────┐┌─────┐ ┌────┐┌─────────────────────────────────────────────────────────────────┐┌─────┐
@ -226,11 +228,11 @@ An horizontal flow layout is implemented by:
~~~ ~~~
~~~cpp ~~~cpp
hbox( hbox({
text(L"left") | border , text(L"left") | border ,
text(L"middle") | border | flex, text(L"middle") | border | flex,
text(L"right") | border | flex text(L"right") | border | flex,
); });
~~~ ~~~
~~~bash ~~~bash
┌────┐┌───────────────────────────────────┐┌───────────────────────────────────┐ ┌────┐┌───────────────────────────────────┐┌───────────────────────────────────┐