Update examples to use std::string. (#182)

In examples and tests, use std::string.

In addtion:
1. Address follow-up from:
https://github.com/ArthurSonzogni/FTXUI/pull/179
2. Fix a bug when Input is used with std::string.
This commit is contained in:
Arthur Sonzogni
2021-08-09 00:27:37 +02:00
committed by GitHub
parent 3b4ab618a3
commit 9a54528bca
60 changed files with 817 additions and 836 deletions

View File

@@ -6,7 +6,6 @@
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for ButtonOption
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for separator, gauge, Element, operator|, vbox, border
using namespace ftxui;
@@ -27,7 +26,7 @@ int main(int argc, const char* argv[]) {
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text(L"value = " + std::to_wstring(value)),
text("value = " + std::to_string(value)),
separator(),
gauge(value * 0.01f),
separator(),

View File

@@ -1,13 +1,12 @@
#include <memory> // for __shared_ptr_access, allocator_traits<>::value_type, shared_ptr
#include <string> // for operator+
#include <memory> // for shared_ptr, __shared_ptr_access, allocator_traits<>::value_type
#include <string> // for operator+, to_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for Element, operator|, size, border, frame, HEIGHT, LESS_THAN
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
using namespace ftxui;
@@ -21,7 +20,8 @@ int main(int argc, const char* argv[]) {
auto container = Container::Vertical({});
for (int i = 0; i < size; ++i) {
states[i].checked = false;
container->Add(Checkbox(L"Checkbox" + to_wstring(i), &states[i].checked));
container->Add(
Checkbox("Checkbox" + std::to_string(i), &states[i].checked));
}
auto component = Renderer(container, [&] {

View File

@@ -1,13 +1,12 @@
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for operator+, to_wstring
#include <string> // for operator+, to_string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for ButtonOption
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for separator, Element, operator|, vbox, border
#include "ftxui/dom/elements.hpp" // for text, separator, Element, operator|, vbox, border
using namespace ftxui;
@@ -38,9 +37,9 @@ int main(int argc, const char* argv[]) {
// children reacts to events is maintained.
auto leftpane = Renderer(left_buttons, [&] {
return vbox({
text(L"This is the left control"),
text("This is the left control"),
separator(),
text(L"Left button count: " + std::to_wstring(left_count)),
text("Left button count: " + std::to_string(left_count)),
left_buttons->Render(),
}) |
border;
@@ -48,9 +47,9 @@ int main(int argc, const char* argv[]) {
auto rightpane = Renderer(right_buttons, [&] {
return vbox({
text(L"This is the right control"),
text("This is the right control"),
separator(),
text(L"Right button count: " + std::to_wstring(right_count)),
text("Right button count: " + std::to_string(right_count)),
right_buttons->Render(),
}) |
border;

View File

@@ -1,20 +1,18 @@
#include <functional> // for function
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Slider, Checkbox, Vertical, Renderer, Button, Menu, Radiobox, Toggle
#include "ftxui/component/component.hpp" // for Slider, Checkbox, Vertical, Renderer, Button, Input, Menu, Radiobox, Toggle
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, xflex, WIDTH, hbox, vbox, EQUAL, border, GREATER_THAN
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, xflex, text, WIDTH, hbox, vbox, EQUAL, border, GREATER_THAN
using namespace ftxui;
// Display a component nicely with a title on the left.
Component Wrap(std::wstring name, Component component) {
Component Wrap(std::string name, Component component) {
return Renderer(component, [name, component] {
return hbox({
text(name) | size(WIDTH, EQUAL, 8),
@@ -30,24 +28,24 @@ int main(int argc, const char* argv[]) {
// -- Menu
// ----------------------------------------------------------------------
const std::vector<std::wstring> menu_entries = {
L"Menu 1",
L"Menu 2",
L"Menu 3",
L"Menu 4",
const std::vector<std::string> menu_entries = {
"Menu 1",
"Menu 2",
"Menu 3",
"Menu 4",
};
int menu_selected = 0;
auto menu = Menu(&menu_entries, &menu_selected);
menu = Wrap(L"Menu", menu);
menu = Wrap("Menu", menu);
// -- Toggle------------------------------------------------------------------
int toggle_selected = 0;
std::vector<std::wstring> toggle_entries = {
L"Toggle_1",
L"Toggle_2",
std::vector<std::string> toggle_entries = {
"Toggle_1",
"Toggle_2",
};
auto toggle = Toggle(&toggle_entries, &toggle_selected);
toggle = Wrap(L"Toggle", toggle);
toggle = Wrap("Toggle", toggle);
// -- Checkbox ---------------------------------------------------------------
bool checkbox_1_selected = false;
@@ -57,40 +55,40 @@ int main(int argc, const char* argv[]) {
Checkbox("checkbox1", &checkbox_1_selected),
Checkbox("checkbox2", &checkbox_2_selected),
});
checkboxes = Wrap(L"Checkbox", checkboxes);
checkboxes = Wrap("Checkbox", checkboxes);
// -- Radiobox ---------------------------------------------------------------
int radiobox_selected = 0;
std::vector<std::wstring> radiobox_entries = {
L"Radiobox 1",
L"Radiobox 2",
L"Radiobox 3",
L"Radiobox 4",
std::vector<std::string> radiobox_entries = {
"Radiobox 1",
"Radiobox 2",
"Radiobox 3",
"Radiobox 4",
};
auto radiobox = Radiobox(&radiobox_entries, &radiobox_selected);
radiobox = Wrap(L"Radiobox", radiobox);
radiobox = Wrap("Radiobox", radiobox);
// -- Input ------------------------------------------------------------------
std::wstring input_label;
auto input = Input(&input_label, L"placeholder");
input = Wrap(L"Input", input);
std::string input_label;
auto input = Input(&input_label, "placeholder");
input = Wrap("Input", input);
// -- Button -----------------------------------------------------------------
std::wstring button_label = L"Quit";
std::string button_label = "Quit";
std::function<void()> on_button_clicked_;
auto button = Button(&button_label, screen.ExitLoopClosure());
button = Wrap(L"Button", button);
button = Wrap("Button", button);
// -- Slider -----------------------------------------------------------------
int slider_value_1 = 12;
int slider_value_2 = 56;
int slider_value_3 = 128;
auto sliders = Container::Vertical({
Slider(L"R:", &slider_value_1, 0, 256, 1),
Slider(L"G:", &slider_value_2, 0, 256, 1),
Slider(L"B:", &slider_value_3, 0, 256, 1),
Slider("R:", &slider_value_1, 0, 256, 1),
Slider("G:", &slider_value_2, 0, 256, 1),
Slider("B:", &slider_value_3, 0, 256, 1),
});
sliders = Wrap(L"Slider", sliders);
sliders = Wrap("Slider", sliders);
// -- Layout -----------------------------------------------------------------
auto layout = Container::Vertical({

View File

@@ -3,7 +3,7 @@
#include <cmath> // for sin
#include <functional> // for ref, reference_wrapper, function
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for wstring, basic_string, operator+, char_traits, to_wstring
#include <string> // for string, basic_string, operator+, char_traits, to_string
#include <thread> // for sleep_for, thread
#include <utility> // for move
#include <vector> // for vector
@@ -12,10 +12,8 @@
#include "ftxui/component/component.hpp" // for Checkbox, Renderer, Horizontal, Vertical, Menu, Radiobox, Tab, Toggle
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/event.hpp" // for Event, Event::Custom
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for operator|, color, bgcolor, filler, Element, size, vbox, flex, hbox, graph, separator, EQUAL, WIDTH, hcenter, bold, border, window, HEIGHT, Elements, hflow, flex_grow, frame, gauge, LESS_THAN, spinner, dim, GREATER_THAN
#include "ftxui/screen/color.hpp" // for Color, Color::BlueLight, Color::RedLight, Color::Black, Color::Blue, Color::Cyan, Color::CyanLight, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::White, Color::Yellow, Color::YellowLight, Color::Default
@@ -41,42 +39,42 @@ int main(int argc, const char* argv[]) {
auto htop = Renderer([&] {
auto frequency = vbox({
text(L"Frequency [Mhz]") | hcenter,
text("Frequency [Mhz]") | hcenter,
hbox({
vbox({
text(L"2400 "),
text("2400 "),
filler(),
text(L"1200 "),
text("1200 "),
filler(),
text(L"0 "),
text("0 "),
}),
graph(std::ref(my_graph)) | flex,
}) | flex,
});
auto utilization = vbox({
text(L"Utilization [%]") | hcenter,
text("Utilization [%]") | hcenter,
hbox({
vbox({
text(L"100 "),
text("100 "),
filler(),
text(L"50 "),
text("50 "),
filler(),
text(L"0 "),
text("0 "),
}),
graph(std::ref(my_graph)) | color(Color::RedLight),
}) | flex,
});
auto ram = vbox({
text(L"Ram [Mo]") | hcenter,
text("Ram [Mo]") | hcenter,
hbox({
vbox({
text(L"8192"),
text("8192"),
filler(),
text(L"4096 "),
text("4096 "),
filler(),
text(L"0 "),
text("0 "),
}),
graph(std::ref(my_graph)) | color(Color::BlueLight),
}) | flex,
@@ -94,56 +92,56 @@ int main(int argc, const char* argv[]) {
flex | border;
});
const std::vector<std::wstring> compiler_entries = {
L"gcc",
L"clang",
L"emcc",
L"game_maker",
L"Ada compilers",
L"ALGOL 60 compilers",
L"ALGOL 68 compilers",
L"Assemblers (Intel *86)",
L"Assemblers (Motorola 68*)",
L"Assemblers (Zilog Z80)",
L"Assemblers (other)",
L"BASIC Compilers",
L"BASIC interpreters",
L"Batch compilers",
L"C compilers",
L"Source-to-source compilers",
L"C++ compilers",
L"C# compilers",
L"COBOL compilers",
L"Common Lisp compilers",
L"D compilers",
L"DIBOL/DBL compilers",
L"ECMAScript interpreters",
L"Eiffel compilers",
L"Fortran compilers",
L"Go compilers",
L"Haskell compilers",
L"Java compilers",
L"Pascal compilers",
L"Perl Interpreters",
L"PHP compilers",
L"PL/I compilers",
L"Python compilers",
L"Scheme compilers and interpreters",
L"Smalltalk compilers",
L"Tcl Interpreters",
L"VMS Interpreters",
L"Rexx Interpreters",
L"CLI compilers",
const std::vector<std::string> compiler_entries = {
"gcc",
"clang",
"emcc",
"game_maker",
"Ada compilers",
"ALGOL 60 compilers",
"ALGOL 68 compilers",
"Assemblers (Intel *86)",
"Assemblers (Motorola 68*)",
"Assemblers (Zilog Z80)",
"Assemblers (other)",
"BASIC Compilers",
"BASIC interpreters",
"Batch compilers",
"C compilers",
"Source-to-source compilers",
"C++ compilers",
"C# compilers",
"COBOL compilers",
"Common Lisp compilers",
"D compilers",
"DIBOL/DBL compilers",
"ECMAScript interpreters",
"Eiffel compilers",
"Fortran compilers",
"Go compilers",
"Haskell compilers",
"Java compilers",
"Pascal compilers",
"Perl Interpreters",
"PHP compilers",
"PL/I compilers",
"Python compilers",
"Scheme compilers and interpreters",
"Smalltalk compilers",
"Tcl Interpreters",
"VMS Interpreters",
"Rexx Interpreters",
"CLI compilers",
};
int compiler_selected = 0;
Component compiler = Radiobox(&compiler_entries, &compiler_selected);
std::array<std::wstring, 4> options_label = {
L"-Wall",
L"-Werror",
L"-lpthread",
L"-O3",
std::array<std::string, 4> options_label = {
"-Wall",
"-Werror",
"-lpthread",
"-O3",
};
std::array<bool, 4> options_state = {
false,
@@ -152,19 +150,19 @@ int main(int argc, const char* argv[]) {
false,
};
std::vector<std::wstring> input_entries;
std::vector<std::string> input_entries;
int input_selected = 0;
Component input = Menu(&input_entries, &input_selected);
auto input_option = InputOption();
std::wstring input_add_content;
std::string input_add_content;
input_option.on_enter = [&] {
input_entries.push_back(input_add_content);
input_add_content = L"";
input_add_content = "";
};
Component input_add = Input(&input_add_content, "input files", input_option);
std::wstring executable_content_ = L"";
std::string executable_content_ = "";
Component executable_ = Input(&executable_content_, "executable");
Component flags = Container::Vertical({
@@ -193,33 +191,33 @@ int main(int argc, const char* argv[]) {
// flags
for (int i = 0; i < 4; ++i) {
if (options_state[i]) {
line.push_back(text(L" "));
line.push_back(text(" "));
line.push_back(text(options_label[i]) | dim);
}
}
// Executable
if (!executable_content_.empty()) {
line.push_back(text(L" -o ") | bold);
line.push_back(text(" -o ") | bold);
line.push_back(text(executable_content_) | color(Color::BlueLight) |
bold);
}
// Input
for (auto& it : input_entries) {
line.push_back(text(L" " + it) | color(Color::RedLight));
line.push_back(text(" " + it) | color(Color::RedLight));
}
return line;
};
auto compiler_renderer = Renderer(compiler_component, [&] {
auto compiler_win = window(text(L"Compiler"), compiler->Render() | frame);
auto flags_win = window(text(L"Flags"), flags->Render());
auto executable_win = window(text(L"Executable:"), executable_->Render());
auto compiler_win = window(text("Compiler"), compiler->Render() | frame);
auto flags_win = window(text("Flags"), flags->Render());
auto executable_win = window(text("Executable:"), executable_->Render());
auto input_win =
window(text(L"Input"),
window(text("Input"),
hbox({
vbox({
hbox({
text(L"Add: "),
text("Add: "),
input_add->Render(),
}) | size(WIDTH, EQUAL, 20) |
size(HEIGHT, EQUAL, 1),
@@ -255,42 +253,42 @@ int main(int argc, const char* argv[]) {
auto color_tab_renderer = Renderer([] {
return hbox({
vbox({
color(Color::Default, text(L"Default")),
color(Color::Black, text(L"Black")),
color(Color::GrayDark, text(L"GrayDark")),
color(Color::GrayLight, text(L"GrayLight")),
color(Color::White, text(L"White")),
color(Color::Blue, text(L"Blue")),
color(Color::BlueLight, text(L"BlueLight")),
color(Color::Cyan, text(L"Cyan")),
color(Color::CyanLight, text(L"CyanLight")),
color(Color::Green, text(L"Green")),
color(Color::GreenLight, text(L"GreenLight")),
color(Color::Magenta, text(L"Magenta")),
color(Color::MagentaLight, text(L"MagentaLight")),
color(Color::Red, text(L"Red")),
color(Color::RedLight, text(L"RedLight")),
color(Color::Yellow, text(L"Yellow")),
color(Color::YellowLight, text(L"YellowLight")),
color(Color::Default, text("Default")),
color(Color::Black, text("Black")),
color(Color::GrayDark, text("GrayDark")),
color(Color::GrayLight, text("GrayLight")),
color(Color::White, text("White")),
color(Color::Blue, text("Blue")),
color(Color::BlueLight, text("BlueLight")),
color(Color::Cyan, text("Cyan")),
color(Color::CyanLight, text("CyanLight")),
color(Color::Green, text("Green")),
color(Color::GreenLight, text("GreenLight")),
color(Color::Magenta, text("Magenta")),
color(Color::MagentaLight, text("MagentaLight")),
color(Color::Red, text("Red")),
color(Color::RedLight, text("RedLight")),
color(Color::Yellow, text("Yellow")),
color(Color::YellowLight, text("YellowLight")),
}),
vbox({
bgcolor(Color::Default, text(L"Default")),
bgcolor(Color::Black, text(L"Black")),
bgcolor(Color::GrayDark, text(L"GrayDark")),
bgcolor(Color::GrayLight, text(L"GrayLight")),
bgcolor(Color::White, text(L"White")),
bgcolor(Color::Blue, text(L"Blue")),
bgcolor(Color::BlueLight, text(L"BlueLight")),
bgcolor(Color::Cyan, text(L"Cyan")),
bgcolor(Color::CyanLight, text(L"CyanLight")),
bgcolor(Color::Green, text(L"Green")),
bgcolor(Color::GreenLight, text(L"GreenLight")),
bgcolor(Color::Magenta, text(L"Magenta")),
bgcolor(Color::MagentaLight, text(L"MagentaLight")),
bgcolor(Color::Red, text(L"Red")),
bgcolor(Color::RedLight, text(L"RedLight")),
bgcolor(Color::Yellow, text(L"Yellow")),
bgcolor(Color::YellowLight, text(L"YellowLight")),
bgcolor(Color::Default, text("Default")),
bgcolor(Color::Black, text("Black")),
bgcolor(Color::GrayDark, text("GrayDark")),
bgcolor(Color::GrayLight, text("GrayLight")),
bgcolor(Color::White, text("White")),
bgcolor(Color::Blue, text("Blue")),
bgcolor(Color::BlueLight, text("BlueLight")),
bgcolor(Color::Cyan, text("Cyan")),
bgcolor(Color::CyanLight, text("CyanLight")),
bgcolor(Color::Green, text("Green")),
bgcolor(Color::GreenLight, text("GreenLight")),
bgcolor(Color::Magenta, text("Magenta")),
bgcolor(Color::MagentaLight, text("MagentaLight")),
bgcolor(Color::Red, text("Red")),
bgcolor(Color::RedLight, text("RedLight")),
bgcolor(Color::Yellow, text("Yellow")),
bgcolor(Color::YellowLight, text("YellowLight")),
}),
}) |
hcenter | border;
@@ -299,7 +297,7 @@ int main(int argc, const char* argv[]) {
auto render_gauge = [&shift](int delta) {
float progress = (shift + delta) % 1000 / 1000.f;
return hbox({
text(std::to_wstring(int(progress * 100)) + L"% ") |
text(std::to_string(int(progress * 100)) + "% ") |
size(WIDTH, EQUAL, 5),
gauge(progress),
});
@@ -329,8 +327,8 @@ int main(int argc, const char* argv[]) {
});
int tab_index = 0;
std::vector<std::wstring> tab_entries = {
L"htop", L"color", L"spinner", L"gauge", L"compiler",
std::vector<std::string> tab_entries = {
"htop", "color", "spinner", "gauge", "compiler",
};
auto tab_selection = Toggle(&tab_entries, &tab_index);
auto tab_content = Container::Tab(
@@ -350,7 +348,7 @@ int main(int argc, const char* argv[]) {
auto main_renderer = Renderer(main_container, [&] {
return vbox({
text(L"FTXUI Demo") | bold | hcenter,
text("FTXUI Demo") | bold | hcenter,
tab_selection->Render() | hcenter,
tab_content->Render() | flex,
});

View File

@@ -5,17 +5,15 @@
#include "ftxui/component/component.hpp" // for Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for hbox, separator, Element, operator|, vbox, border
int main(int argc, const char* argv[]) {
using namespace ftxui;
std::wstring first_name;
std::wstring last_name;
std::wstring password;
std::string first_name;
std::string last_name;
std::string password;
Component input_first_name = Input(&first_name, "first name");
Component input_last_name = Input(&last_name, "last name");
@@ -32,11 +30,11 @@ int main(int argc, const char* argv[]) {
auto renderer = Renderer(component, [&] {
return vbox({
text(L"Hello " + first_name + L" " + last_name),
text("Hello " + first_name + " " + last_name),
separator(),
hbox(text(L" First name : "), input_first_name->Render()),
hbox(text(L" Last name : "), input_last_name->Render()),
hbox(text(L" Password : "), input_password->Render()),
hbox(text(" First name : "), input_first_name->Render()),
hbox(text(" Last name : "), input_last_name->Render()),
hbox(text(" Password : "), input_password->Render()),
}) |
border;
});

View File

@@ -1,6 +1,6 @@
#include <functional> // for function
#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
#include <string> // for wstring, basic_string, allocator
#include <string> // for string, basic_string, allocator
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -12,10 +12,10 @@ int main(int argc, const char* argv[]) {
using namespace ftxui;
auto screen = ScreenInteractive::TerminalOutput();
std::vector<std::wstring> entries = {
L"entry 1",
L"entry 2",
L"entry 3",
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;

View File

@@ -1,6 +1,6 @@
#include <functional> // for function
#include <memory> // for allocator, __shared_ptr_access
#include <string> // for wstring, basic_string, operator+, to_string
#include <string> // for string, basic_string, operator+, to_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -8,21 +8,17 @@
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for MenuOption
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/dom/elements.hpp" // for text, separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border
int main(int argc, const char* argv[]) {
using namespace ftxui;
auto screen = ScreenInteractive::TerminalOutput();
std::vector<std::wstring> left_menu_entries = {
L"0%", L"10%", L"20%", L"30%", L"40%",
L"50%", L"60%", L"70%", L"80%", L"90%",
std::vector<std::string> left_menu_entries = {
"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%",
};
std::vector<std::wstring> right_menu_entries = {
L"0%", L"1%", L"2%", L"3%", L"4%", L"5%",
L"6%", L"7%", L"8%", L"9%", L"10%",
std::vector<std::string> right_menu_entries = {
"0%", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%", "10%",
};
auto menu_option = MenuOption();
@@ -47,14 +43,14 @@ int main(int argc, const char* argv[]) {
hbox({
// -------- Left Menu --------------
vbox({
hcenter(bold(text(L"Percentage by 10%"))),
hcenter(bold(text("Percentage by 10%"))),
separator(),
left_menu_->Render(),
}),
separator(),
// -------- Right Menu --------------
vbox({
hcenter(bold(text(L"Percentage by 1%"))),
hcenter(bold(text("Percentage by 1%"))),
separator(),
right_menu_->Render(),
}),
@@ -64,12 +60,12 @@ int main(int argc, const char* argv[]) {
// -------- Bottom panel --------------
vbox({
hbox({
text(L" gauge : "),
text(" gauge : "),
gauge(sum / 100.0),
}),
hbox({
text(L" text : "),
text(to_wstring(std::to_string(sum) + " %")),
text(" text : "),
text(std::to_string(sum) + " %"),
}),
}),
}) |

View File

@@ -1,19 +1,17 @@
#include <stdlib.h> // for EXIT_SUCCESS
#include <memory> // for allocator, __shared_ptr_access
#include <string> // for wstring, operator+, basic_string, char_traits
#include <vector> // for vector, __alloc_traits<>::value_type
#include <string> // for string, operator+, basic_string, to_string, char_traits
#include <vector> // for vector, __alloc_traits<>::value_type
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Menu, Renderer, Horizontal, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for Element, operator|, window, flex, vbox
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/dom/elements.hpp" // for text, Element, operator|, window, flex, vbox
using namespace ftxui;
Component Window(std::wstring title, Component component) {
Component Window(std::string title, Component component) {
return Renderer(component, [component, title] { //
return window(text(title), component->Render()) | flex;
});
@@ -21,46 +19,46 @@ Component Window(std::wstring title, Component component) {
int main(int argc, const char* argv[]) {
int menu_selected[] = {0, 0, 0};
std::vector<std::vector<std::wstring>> menu_entries = {
std::vector<std::vector<std::string>> menu_entries = {
{
L"Ananas",
L"Raspberry",
L"Citrus",
"Ananas",
"Raspberry",
"Citrus",
},
{
L"Potatoes",
L"Weat",
L"Rise",
"Potatoes",
"Weat",
"Rise",
},
{
L"Carrot",
L"Lettuce",
L"Tomato",
"Carrot",
"Lettuce",
"Tomato",
},
};
int menu_selected_global = 0;
auto menu_global = Container::Vertical(
{
Window(L"Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
Window(L"Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
Window(L"Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
Window("Menu 1", Menu(&menu_entries[0], &menu_selected[0])),
Window("Menu 2", Menu(&menu_entries[1], &menu_selected[1])),
Window("Menu 3", Menu(&menu_entries[2], &menu_selected[2])),
},
&menu_selected_global);
auto info = Renderer([&] {
int g = menu_selected_global;
std::wstring value = menu_entries[g][menu_selected[g]];
return window(text(L"Content"), //
std::string value = menu_entries[g][menu_selected[g]];
return window(text("Content"), //
vbox({
text(L"menu_selected_global = " + to_wstring(g)),
text(L"menu_selected[0] = " +
to_wstring(menu_selected[0])),
text(L"menu_selected[1] = " +
to_wstring(menu_selected[1])),
text(L"menu_selected[2] = " +
to_wstring(menu_selected[2])),
text(L"Value = " + value),
text("menu_selected_global = " + std::to_string(g)),
text("menu_selected[0] = " +
std::to_string(menu_selected[0])),
text("menu_selected[1] = " +
std::to_string(menu_selected[1])),
text("menu_selected[2] = " +
std::to_string(menu_selected[2])),
text("Value = " + value),
})) |
flex;
});

View File

@@ -1,6 +1,6 @@
#include <functional> // for function
#include <memory> // for shared_ptr, __shared_ptr_access, allocator
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -15,8 +15,8 @@ int main(int argc, const char* argv[]) {
using namespace ftxui;
auto screen = ScreenInteractive::TerminalOutput();
std::vector<std::wstring> entries = {
L"Monkey", L"Dog", L"Cat", L"Bird", L"Elephant",
std::vector<std::string> entries = {
"Monkey", "Dog", "Cat", "Bird", "Elephant",
};
int menu_1_selected_ = 0;
int menu_2_selected_ = 0;

View File

@@ -1,13 +1,12 @@
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for wstring, basic_string, char_traits, operator+
#include <string> // for string, basic_string, char_traits, operator+
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Renderer, Horizontal, Tab
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT
#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, text, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT
int main(int argc, const char* argv[]) {
using namespace ftxui;
@@ -17,7 +16,7 @@ int main(int argc, const char* argv[]) {
int depth = 0;
// The current rating of FTXUI.
std::wstring rating = L"3/5 stars";
std::string rating = "3/5 stars";
// At depth=0, two buttons. One for rating FTXUI and one for quitting.
auto button_rate_ftxui = Button("Rate FTXUI", [&] { depth = 1; });
@@ -29,9 +28,9 @@ int main(int argc, const char* argv[]) {
});
auto depth_0_renderer = Renderer(depth_0_container, [&] {
return vbox({
text(L"Modal dialog example"),
text("Modal dialog example"),
separator(),
text(L"☆☆☆ FTXUI:" + rating + L" ☆☆☆") | bold,
text("☆☆☆ FTXUI:" + rating + " ☆☆☆") | bold,
filler(),
hbox({
button_rate_ftxui->Render(),
@@ -43,10 +42,10 @@ int main(int argc, const char* argv[]) {
});
// At depth=1, The "modal" window.
std::vector<std::wstring> rating_labels = {
L"1/5 stars", L"2/5 stars", L"3/5 stars", L"4/5 stars", L"5/5 stars",
std::vector<std::string> rating_labels = {
"1/5 stars", "2/5 stars", "3/5 stars", "4/5 stars", "5/5 stars",
};
auto on_rating = [&](std::wstring new_rating) {
auto on_rating = [&](std::string new_rating) {
rating = new_rating;
depth = 0;
};
@@ -60,7 +59,7 @@ int main(int argc, const char* argv[]) {
auto depth_1_renderer = Renderer(depth_1_container, [&] {
return vbox({
text(L"Do you like FTXUI?"),
text("Do you like FTXUI?"),
separator(),
hbox(depth_1_container->Render()),
}) |

View File

@@ -1,4 +1,4 @@
#include <string> // for wstring, allocator, basic_string
#include <string> // for string, allocator, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -8,11 +8,11 @@
using namespace ftxui;
int main(int argc, const char* argv[]) {
std::vector<std::wstring> radiobox_list = {
L"Use gcc",
L"Use clang",
L"Use emscripten",
L"Use tcc",
std::vector<std::string> radiobox_list = {
"Use gcc",
"Use clang",
"Use emscripten",
"Use tcc",
};
int selected = 0;

View File

@@ -1,22 +1,21 @@
#include <memory> // for __shared_ptr_access, shared_ptr
#include <string> // for wstring, operator+
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for string, basic_string, operator+, to_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Radiobox, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for Element, operator|, size, border, frame, HEIGHT, LESS_THAN
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/dom/elements.hpp" // for operator|, Element, size, border, frame, HEIGHT, LESS_THAN
using namespace ftxui;
int main(int argc, const char* argv[]) {
std::vector<std::wstring> entries;
std::vector<std::string> entries;
int selected = 0;
for (int i = 0; i < 30; ++i)
entries.push_back(L"RadioBox " + to_wstring(i));
entries.push_back("RadioBox " + std::to_string(i));
auto radiobox = Radiobox(&entries, &selected);
auto renderer = Renderer(radiobox, [&] {
return radiobox->Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;

View File

@@ -4,8 +4,7 @@
#include "ftxui/component/component.hpp" // for Renderer, Button, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for operator|, Element, bold, border, center, color
#include "ftxui/dom/elements.hpp" // for operator|, Element, text, bold, border, center, color
#include "ftxui/screen/color.hpp" // for Color, Color::Red
int main(int argc, const char* argv[]) {
@@ -18,18 +17,18 @@ int main(int argc, const char* argv[]) {
// 1. Example of focusable renderer:
auto renderer_focusable = Renderer([](bool focused) {
if (focused)
return text(L"FOCUSABLE RENDERER()") | center | bold | border;
return text("FOCUSABLE RENDERER()") | center | bold | border;
else
return text(L" Focusable renderer() ") | center | border;
return text(" Focusable renderer() ") | center | border;
});
// 2. Examples of a non focusable renderer.
auto renderer_non_focusable = Renderer([&] {
return text(L"~~~~~ Non Focusable renderer() ~~~~~"); //
return text("~~~~~ Non Focusable renderer() ~~~~~"); //
});
// 3. Renderer can wrap other components to redefine their Render() function.
auto button = Button(L"Wrapped quit button", screen.ExitLoopClosure());
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
auto renderer_wrap = Renderer(button, [&] {
if (button->Focused())
return button->Render() | bold | color(Color::Red);

View File

@@ -4,19 +4,18 @@
#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for Element, operator|, center, border
#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border
using namespace ftxui;
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::Fullscreen();
auto middle = Renderer([] { return text(L"middle") | center; });
auto left = Renderer([] { return text(L"Left") | center; });
auto right = Renderer([] { return text(L"right") | center; });
auto top = Renderer([] { return text(L"top") | center; });
auto bottom = Renderer([] { return text(L"bottom") | center; });
auto middle = Renderer([] { return text("middle") | center; });
auto left = Renderer([] { return text("Left") | center; });
auto right = Renderer([] { return text("right") | center; });
auto top = Renderer([] { return text("top") | center; });
auto bottom = Renderer([] { return text("bottom") | center; });
int left_size = 20;
int right_size = 20;

View File

@@ -7,7 +7,7 @@ using namespace ftxui;
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput();
int value = 50;
auto slider = Slider(L"Value:", &value, 0, 100, 1);
auto slider = Slider("Value:", &value, 0, 100, 1);
screen.Loop(slider);
}

View File

@@ -1,26 +1,25 @@
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for char_traits, operator+, to_wstring
#include <string> // for char_traits, operator+, to_string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
#include "ftxui/dom/elements.hpp" // for separator, operator|, Element, size, text, vbox, xflex, bgcolor, hbox, GREATER_THAN, WIDTH, border, HEIGHT, LESS_THAN
#include "ftxui/screen/color.hpp" // for Color
using namespace ftxui;
Element ColorTile(int red, int green, int blue) {
return text(L"") | size(WIDTH, GREATER_THAN, 14) |
return text("") | size(WIDTH, GREATER_THAN, 14) |
size(HEIGHT, GREATER_THAN, 7) | bgcolor(Color::RGB(red, green, blue));
}
Element ColorString(int red, int green, int blue) {
return text(L"RGB = (" + //
std::to_wstring(red) + L"," + //
std::to_wstring(green) + L"," + //
std::to_wstring(blue) + L")" //
return text("RGB = (" + //
std::to_string(red) + "," + //
std::to_string(green) + "," + //
std::to_string(blue) + ")" //
);
}
@@ -28,9 +27,9 @@ int main(int argc, const char* argv[]) {
int red = 128;
int green = 25;
int blue = 100;
auto slider_red = Slider(L"Red :", &red, 0, 255, 1);
auto slider_green = Slider(L"Green:", &green, 0, 255, 1);
auto slider_blue = Slider(L"Blue :", &blue, 0, 255, 1);
auto slider_red = Slider("Red :", &red, 0, 255, 1);
auto slider_green = Slider("Green:", &green, 0, 255, 1);
auto slider_blue = Slider("Blue :", &blue, 0, 255, 1);
auto container = Container::Vertical({
slider_red,

View File

@@ -1,5 +1,5 @@
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -11,33 +11,33 @@
using namespace ftxui;
int main(int argc, const char* argv[]) {
std::vector<std::wstring> tab_values{
L"tab_1",
L"tab_2",
L"tab_3",
std::vector<std::string> tab_values{
"tab_1",
"tab_2",
"tab_3",
};
int tab_selected = 0;
auto tab_toggle = Toggle(&tab_values, &tab_selected);
std::vector<std::wstring> tab_1_entries{
L"Forest",
L"Water",
L"I don't know",
std::vector<std::string> tab_1_entries{
"Forest",
"Water",
"I don't know",
};
int tab_1_selected = 0;
std::vector<std::wstring> tab_2_entries{
L"Hello",
L"Hi",
L"Hay",
std::vector<std::string> tab_2_entries{
"Hello",
"Hi",
"Hay",
};
int tab_2_selected = 0;
std::vector<std::wstring> tab_3_entries{
L"Table",
L"Nothing",
L"Is",
L"Empty",
std::vector<std::string> tab_3_entries{
"Table",
"Nothing",
"Is",
"Empty",
};
int tab_3_selected = 0;
auto tab_container = Container::Tab(

View File

@@ -1,5 +1,5 @@
#include <memory> // for allocator, __shared_ptr_access, shared_ptr
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -11,33 +11,33 @@
using namespace ftxui;
int main(int argc, const char* argv[]) {
std::vector<std::wstring> tab_values{
L"tab_1",
L"tab_2",
L"tab_3",
std::vector<std::string> tab_values{
"tab_1",
"tab_2",
"tab_3",
};
int tab_selected = 0;
auto tab_menu = Menu(&tab_values, &tab_selected);
std::vector<std::wstring> tab_1_entries{
L"Forest",
L"Water",
L"I don't know",
std::vector<std::string> tab_1_entries{
"Forest",
"Water",
"I don't know",
};
int tab_1_selected = 0;
std::vector<std::wstring> tab_2_entries{
L"Hello",
L"Hi",
L"Hay",
std::vector<std::string> tab_2_entries{
"Hello",
"Hi",
"Hay",
};
int tab_2_selected = 0;
std::vector<std::wstring> tab_3_entries{
L"Table",
L"Nothing",
L"Is",
L"Empty",
std::vector<std::string> tab_3_entries{
"Table",
"Nothing",
"Is",
"Empty",
};
int tab_3_selected = 0;
auto tab_container = Container::Tab(

View File

@@ -1,33 +1,32 @@
#include <memory> // for allocator, __shared_ptr_access
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Toggle, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for hbox, vbox, Element
#include "ftxui/dom/elements.hpp" // for text, hbox, vbox, Element
using namespace ftxui;
int main(int argc, const char* argv[]) {
std::vector<std::wstring> toggle_1_entries = {
L"On",
L"Off",
std::vector<std::string> toggle_1_entries = {
"On",
"Off",
};
std::vector<std::wstring> toggle_2_entries = {
L"Enabled",
L"Disabled",
std::vector<std::string> toggle_2_entries = {
"Enabled",
"Disabled",
};
std::vector<std::wstring> toggle_3_entries = {
L"10€",
L"0€",
std::vector<std::string> toggle_3_entries = {
"10€",
"0€",
};
std::vector<std::wstring> toggle_4_entries = {
L"Nothing",
L"One element",
L"Several elements",
std::vector<std::string> toggle_4_entries = {
"Nothing",
"One element",
"Several elements",
};
int toggle_1_selected = 0;
@@ -48,12 +47,12 @@ int main(int argc, const char* argv[]) {
auto renderer = Renderer(container, [&] {
return vbox({
text(L"Choose your options:"),
text(L""),
hbox(text(L" * Poweroff on startup : "), toggle_1->Render()),
hbox(text(L" * Out of process : "), toggle_2->Render()),
hbox(text(L" * Price of the information : "), toggle_3->Render()),
hbox(text(L" * Number of elements : "), toggle_4->Render()),
text("Choose your options:"),
text(""),
hbox(text(" * Poweroff on startup : "), toggle_1->Render()),
hbox(text(" * Out of process : "), toggle_2->Render()),
hbox(text(" * Price of the information : "), toggle_3->Render()),
hbox(text(" * Number of elements : "), toggle_4->Render()),
});
});