mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +08:00 
			
		
		
		
	Make component more functionnal
This commit is contained in:
		| @@ -17,6 +17,7 @@ example(modal_dialog) | ||||
| example(radiobox) | ||||
| example(radiobox_in_frame) | ||||
| example(slider) | ||||
| example(slider_rgb) | ||||
| example(tab_horizontal) | ||||
| example(tab_vertical) | ||||
| example(toggle) | ||||
|   | ||||
| @@ -1,51 +1,43 @@ | ||||
| #include <functional>  // for function | ||||
| #include <memory>      // for unique_ptr, make_u... | ||||
| #include <string>      // for wstring | ||||
| #include <utility>     // for move | ||||
| #include <vector>      // for vector | ||||
| #include <string>  // for operator+, to_wstring, allocator, wstring | ||||
|  | ||||
| #include "ftxui/component/button.hpp"              // for Button | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/captured_mouse.hpp"      // for ftxui | ||||
| #include "ftxui/component/component.hpp"           // for Button, Make | ||||
| #include "ftxui/component/component_base.hpp"      // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/dom/elements.hpp"  // for separator, Element, gauge, text, operator|, vbox, border | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   std::vector<std::unique_ptr<Button>> buttons_; | ||||
|   Container container_ = Container::Horizontal(); | ||||
|   std::wstring label_add = L"Increase"; | ||||
|   std::wstring label_rm = L"Decrease"; | ||||
|   int value_ = 50; | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     Add(Container::Horizontal({ | ||||
|         Button(&label_rm, [&] { value_--; }), | ||||
|         Button(&label_add, [&] { value_++; }), | ||||
|     })); | ||||
|   } | ||||
|  | ||||
|     auto button_add = std::make_unique<Button>(); | ||||
|     auto button_remove = std::make_unique<Button>(); | ||||
|     container_.Add(button_add.get()); | ||||
|     container_.Add(button_remove.get()); | ||||
|     button_add->label = L"Add one button"; | ||||
|     button_remove->label = L"Remove last button"; | ||||
|  | ||||
|     button_add->on_click = [&] { | ||||
|       auto extra_button = std::make_unique<Button>(); | ||||
|       extra_button->label = L"extra button"; | ||||
|       container_.Add(extra_button.get()); | ||||
|       buttons_.push_back(std::move(extra_button)); | ||||
|     }; | ||||
|  | ||||
|     button_remove->on_click = [&] { buttons_.resize(buttons_.size() - 1); }; | ||||
|  | ||||
|     buttons_.push_back(std::move(button_add)); | ||||
|     buttons_.push_back(std::move(button_remove)); | ||||
|   Element Render() override { | ||||
|     return vbox({ | ||||
|                text(L"Value = " + std::to_wstring(value_)), | ||||
|                separator(), | ||||
|                gauge(value_ * 0.01f), | ||||
|                separator(), | ||||
|                ComponentBase::Render(), | ||||
|            }) | | ||||
|            border; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|   auto screen = ScreenInteractive::FitComponent(); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,34 +1,34 @@ | ||||
| #include "ftxui/component/checkbox.hpp" | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Checkbox, Make | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive, Component | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   CheckBox box_1_; | ||||
|   CheckBox box_2_; | ||||
|   CheckBox box_3_; | ||||
|   Container container_ = Container::Vertical(); | ||||
|   std::wstring build_examples_label = L"Build examples"; | ||||
|   std::wstring build_tests_label = L"Build tests"; | ||||
|   std::wstring use_webassembly_label = L"Use WebAssembly"; | ||||
|  | ||||
|   bool build_examples_state = false; | ||||
|   bool build_tests_state = false; | ||||
|   bool use_webassembly_state = true; | ||||
|  | ||||
|   Component container = Container::Vertical({ | ||||
|       Checkbox(&build_examples_label, &build_examples_state), | ||||
|       Checkbox(&build_tests_label, &build_tests_state), | ||||
|       Checkbox(&use_webassembly_label, &use_webassembly_state), | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&box_1_); | ||||
|     container_.Add(&box_2_); | ||||
|     container_.Add(&box_3_); | ||||
|     box_1_.label = L"Build examples"; | ||||
|     box_2_.label = L"Build tests"; | ||||
|     box_3_.label = L"Use WebAssembly"; | ||||
|     box_3_.state = true; | ||||
|   } | ||||
|   MyComponent() { Add(container); } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,50 +1,61 @@ | ||||
| #include <memory>   // for allocator_traits<>... | ||||
| #include <string>   // for operator+, wstring | ||||
| #include <utility>  // for move | ||||
| #include <vector>   // for vector | ||||
| #include <ext/alloc_traits.h>  // for __alloc_traits<>::value_type | ||||
| #include <memory>  // for unique_ptr, make_unique, __shared_ptr_access | ||||
| #include <string>  // for operator+, wstring | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/checkbox.hpp"            // for CheckBox | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"                  // for Element, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/screen/string.hpp"                 // for to_wstring | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Checkbox, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for Element, operator|, size, vbox, border, frame, Elements, HEIGHT, LESS_THAN | ||||
| #include "ftxui/screen/string.hpp"  // for to_wstring | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| struct CheckboxAndState { | ||||
|   std::wstring label; | ||||
|   bool state; | ||||
|   Component component; | ||||
| }; | ||||
|  | ||||
| std::unique_ptr<CheckboxAndState> MakeCheckbox(std::wstring label) { | ||||
|   auto out = std::make_unique<CheckboxAndState>(); | ||||
|   out->label = label; | ||||
|   out->state = false; | ||||
|   out->component = Checkbox(&out->label, &out->state); | ||||
|   return out; | ||||
| } | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|     Add(container); | ||||
|     checkbox.resize(30); | ||||
|     for (int i = 0; i < checkbox.size(); ++i) { | ||||
|       checkbox[i].label = (L"CheckBox " + to_wstring(i)); | ||||
|       container.Add(&checkbox[i]); | ||||
|       checkbox[i] = MakeCheckbox(L"CheckBox " + to_wstring(i)); | ||||
|       container->Add(checkbox[i]->component); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // clang-format off | ||||
|   Element Render() override { | ||||
|     Elements content; | ||||
|     for (auto& it : checkbox) { | ||||
|       content.push_back(it.Render()); | ||||
|     } | ||||
|     return vbox(std::move(content)) | ||||
|     return vbox(container->Render()) | ||||
|       | frame | ||||
|       | size(HEIGHT, LESS_THAN, 10) | ||||
|       | border; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   std::vector<CheckBox> checkbox; | ||||
|   Container container = Container::Vertical(); | ||||
|   std::vector<std::unique_ptr<CheckboxAndState>> checkbox; | ||||
|   Component container = Container::Vertical(); | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::FitComponent(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|   auto my_component = Make<MyComponent>(); | ||||
|   screen.Loop(my_component); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,82 +1,81 @@ | ||||
| #include <functional>  // for function | ||||
| #include <memory>      // for allocator, unique_ptr | ||||
| #include <string>      // for wstring | ||||
| #include <memory>      // for allocator, __shared_ptr_access | ||||
| #include <string>      // for wstring, basic_string | ||||
| #include <vector>      // for vector | ||||
|  | ||||
| #include "ftxui/component/button.hpp"              // for Button | ||||
| #include "ftxui/component/checkbox.hpp"            // for CheckBox | ||||
| #include "ftxui/component/component.hpp"           // for Component, Compone... | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/input.hpp"               // for Input | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/radiobox.hpp"            // for RadioBox | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/component/slider.hpp"              // for Slider | ||||
| #include "ftxui/component/toggle.hpp"              // for Toggle | ||||
| #include "ftxui/dom/elements.hpp"                  // for separator, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"  // for Slider, Checkbox, Button, Input, Make, Menu, Radiobox, Toggle | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for separator, operator|, Element, size, xflex, text, WIDTH, hbox, vbox, EQUAL, LESS_THAN, border, GREATER_THAN | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   Container container = Container::Vertical(); | ||||
|   Menu menu; | ||||
|   Toggle toggle; | ||||
|   Container checkbox_container = Container::Vertical(); | ||||
|   CheckBox checkbox1; | ||||
|   CheckBox checkbox2; | ||||
|   RadioBox radiobox; | ||||
|   Input input; | ||||
|   Button button; | ||||
| class MyComponent : public ComponentBase { | ||||
|   const std::vector<std::wstring> menu_entries_ = { | ||||
|       L"Menu 1", | ||||
|       L"Menu 2", | ||||
|       L"Menu 3", | ||||
|       L"Menu 4", | ||||
|   }; | ||||
|   int menu_selected_ = 0; | ||||
|   Component menu_ = Menu(&menu_entries_, &menu_selected_); | ||||
|  | ||||
|   int toggle_selected_ = 0; | ||||
|   std::vector<std::wstring> toggle_entries_ = { | ||||
|       L"Toggle_1", | ||||
|       L"Toggle_2", | ||||
|   }; | ||||
|   Component toggle_ = Toggle(&toggle_entries_, &toggle_selected_); | ||||
|  | ||||
|   std::wstring checkbox_1_label_ = L"checkbox1"; | ||||
|   std::wstring checkbox_2_label_ = L"checkbox2"; | ||||
|   bool checkbox_1_selected_ = false; | ||||
|   bool checkbox_2_selected_ = false; | ||||
|  | ||||
|   Component checkbox_container_ = Container::Vertical({ | ||||
|       Checkbox(&checkbox_1_label_, &checkbox_1_selected_), | ||||
|       Checkbox(&checkbox_2_label_, &checkbox_2_selected_), | ||||
|   }); | ||||
|  | ||||
|   int radiobox_selected_ = 0; | ||||
|   std::vector<std::wstring> radiobox_entries_ = { | ||||
|       L"Radiobox 1", | ||||
|       L"Radiobox 2", | ||||
|       L"Radiobox 3", | ||||
|       L"Radiobox 4", | ||||
|   }; | ||||
|   Component radiobox_ = Radiobox(&radiobox_entries_, &radiobox_selected_); | ||||
|  | ||||
|   std::wstring input_label_; | ||||
|   std::wstring input_placeholder_ = L"input"; | ||||
|   Component input_ = Input(&input_label_, &input_placeholder_); | ||||
|  | ||||
|   std::wstring button_label_ = L"Quit"; | ||||
|   std::function<void()> on_button_clicked_; | ||||
|   Component button_ = Button(&button_label_, [this] { on_button_clicked_(); }); | ||||
|  | ||||
|   int slider_value_1_ = 12; | ||||
|   int slider_value_2_ = 56; | ||||
|   int slider_value_3_ = 128; | ||||
|   ComponentPtr slider_1_ = Slider(L"R:", &slider_value_1_, 0, 256, 1); | ||||
|   ComponentPtr slider_2_ = Slider(L"G:", &slider_value_2_, 0, 256, 1); | ||||
|   ComponentPtr slider_3_ = Slider(L"B:", &slider_value_3_, 0, 256, 1); | ||||
|   Component slider_container_ = 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), | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|     menu.entries = { | ||||
|         L"Menu 1", | ||||
|         L"Menu 2", | ||||
|         L"Menu 3", | ||||
|         L"Menu 4", | ||||
|     }; | ||||
|     container.Add(&menu); | ||||
|  | ||||
|     toggle.entries = { | ||||
|         L"Toggle_1", | ||||
|         L"Toggle_2", | ||||
|     }; | ||||
|     container.Add(&toggle); | ||||
|  | ||||
|     container.Add(&checkbox_container); | ||||
|     checkbox1.label = L"checkbox1"; | ||||
|     checkbox_container.Add(&checkbox1); | ||||
|     checkbox2.label = L"checkbox2"; | ||||
|     checkbox_container.Add(&checkbox2); | ||||
|  | ||||
|     radiobox.entries = { | ||||
|         L"Radiobox 1", | ||||
|         L"Radiobox 2", | ||||
|         L"Radiobox 3", | ||||
|         L"Radiobox 4", | ||||
|     }; | ||||
|     container.Add(&radiobox); | ||||
|  | ||||
|     input.placeholder = L"Input placeholder"; | ||||
|     container.Add(&input); | ||||
|  | ||||
|     container.Add(slider_1_.get()); | ||||
|     container.Add(slider_2_.get()); | ||||
|     container.Add(slider_3_.get()); | ||||
|  | ||||
|     button.label = L"Quit"; | ||||
|     button.on_click = [&] { on_quit(); }; | ||||
|     container.Add(&button); | ||||
|   MyComponent(std::function<void(void)> on_quit) : on_quit_(on_quit) { | ||||
|     Add(Container::Vertical({ | ||||
|         menu_, | ||||
|         toggle_, | ||||
|         checkbox_container_, | ||||
|         radiobox_, | ||||
|         input_, | ||||
|         slider_container_, | ||||
|         button_, | ||||
|     })); | ||||
|   } | ||||
|  | ||||
|   Element Render(std::wstring name, Element element) { | ||||
| @@ -89,42 +88,36 @@ class MyComponent : public Component { | ||||
|   } | ||||
|  | ||||
|   Element Render(std::wstring name, Component& component) { | ||||
|     return Render(name, component.Render()); | ||||
|     return Render(name, component->Render()); | ||||
|   } | ||||
|  | ||||
|   Element Render() override { | ||||
|     return  // | ||||
|         vbox({ | ||||
|             Render(L"menu", menu), | ||||
|             Render(L"menu", menu_), | ||||
|             separator(), | ||||
|             Render(L"toggle", toggle), | ||||
|             Render(L"toggle", toggle_), | ||||
|             separator(), | ||||
|             Render(L"checkbox", checkbox_container), | ||||
|             Render(L"checkbox", checkbox_container_), | ||||
|             separator(), | ||||
|             Render(L"radiobox", radiobox), | ||||
|             Render(L"radiobox", radiobox_), | ||||
|             separator(), | ||||
|             Render(L"input", input) | size(WIDTH, LESS_THAN, 50), | ||||
|             Render(L"input", input_) | size(WIDTH, LESS_THAN, 50), | ||||
|             separator(), | ||||
|             Render(L"slider",  // | ||||
|                    vbox({ | ||||
|                        slider_1_->Render(), | ||||
|                        slider_2_->Render(), | ||||
|                        slider_3_->Render(), | ||||
|                    })), | ||||
|             Render(L"slider", slider_container_), | ||||
|             separator(), | ||||
|             Render(L"button", button), | ||||
|             Render(L"button", button_), | ||||
|         }) | | ||||
|         xflex | size(WIDTH, GREATER_THAN, 40) | border; | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_quit = [] {}; | ||||
|   std::function<void()> on_quit_; | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::FitComponent(); | ||||
|   MyComponent component; | ||||
|   component.on_quit = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   auto component = Make<MyComponent>(screen.ExitLoopClosure()); | ||||
|   screen.Loop(component); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,23 +1,22 @@ | ||||
| #include <chrono>      // for operator""s, chron... | ||||
| #include <array>       // for array | ||||
| #include <chrono>      // for operator""s, chrono_literals | ||||
| #include <cmath>       // for sin | ||||
| #include <functional>  // for ref, reference_wra... | ||||
| #include <string>      // for allocator, wstring | ||||
| #include <thread>      // for sleep_for, thread | ||||
| #include <utility>     // for move | ||||
| #include <vector>      // for vector | ||||
| #include <functional>  // for ref, reference_wrapper, function | ||||
| #include <memory>      // for make_shared, __shared_ptr_access | ||||
| #include <string>  // for allocator, wstring, basic_string, operator+, to_wstring | ||||
| #include <thread>   // for sleep_for, thread | ||||
| #include <utility>  // for move | ||||
| #include <vector>   // for vector | ||||
|  | ||||
| #include "ftxui/component/checkbox.hpp"            // for CheckBox | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/event.hpp"               // for Event, Event::Custom | ||||
| #include "ftxui/component/input.hpp"               // for Input | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/radiobox.hpp"            // for RadioBox | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/component/toggle.hpp"              // for Toggle | ||||
| #include "ftxui/dom/elements.hpp"                  // for text, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/screen/color.hpp"                  // for Color, Color::Blue... | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"  // for Checkbox, Input, Menu, Radiobox, Toggle | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/event.hpp"           // for Event, Event::Custom | ||||
| #include "ftxui/component/input.hpp"           // for InputBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for text, operator|, color, bgcolor, Element, filler, size, vbox, flex, hbox, graph, separator, EQUAL, WIDTH, hcenter, bold, border, window, Elements, HEIGHT, 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 | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| @@ -39,7 +38,7 @@ class Graph { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class HTopComponent : public Component { | ||||
| class HTopComponent : public ComponentBase { | ||||
|   Graph my_graph; | ||||
|  | ||||
|  public: | ||||
| @@ -102,110 +101,121 @@ class HTopComponent : public Component { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class CompilerComponent : public Component { | ||||
|   Container container = Container::Horizontal(); | ||||
|   RadioBox compiler; | ||||
|   Container flag = Container::Vertical(); | ||||
|   CheckBox flag_checkbox[4]; | ||||
|   Container subcontainer = Container::Vertical(); | ||||
|   Container input_container = Container::Horizontal(); | ||||
|   Input input_add; | ||||
|   Menu input; | ||||
|   Input executable; | ||||
| 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", | ||||
| }; | ||||
|  | ||||
| class CompilerComponent : public ComponentBase { | ||||
|   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<bool, 4> options_state = { | ||||
|       false, | ||||
|       false, | ||||
|       false, | ||||
|       false, | ||||
|   }; | ||||
|   std::wstring input_add_content = L""; | ||||
|   std::wstring input_add_placeholder = L"input_files"; | ||||
|   Component input_add = Input(&input_add_content, &input_add_placeholder); | ||||
|  | ||||
|   std::vector<std::wstring> input_entries; | ||||
|   int input_selected = 0; | ||||
|   Component input = Menu(&input_entries, &input_selected); | ||||
|  | ||||
|   std::wstring executable_content_ = L""; | ||||
|   std::wstring executable_placeholder_ = L"executable"; | ||||
|   Component executable_ = Input(&executable_content_, &executable_placeholder_); | ||||
|  | ||||
|   Component flags = Container::Vertical({ | ||||
|       Checkbox(&options_label[0], &options_state[0]), | ||||
|       Checkbox(&options_label[1], &options_state[1]), | ||||
|       Checkbox(&options_label[2], &options_state[2]), | ||||
|       Checkbox(&options_label[3], &options_state[3]), | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   ~CompilerComponent() override {} | ||||
|   CompilerComponent() { | ||||
|     Add(&container); | ||||
|     Add(Container::Horizontal({ | ||||
|         compiler, | ||||
|         flags, | ||||
|         Container::Vertical({ | ||||
|             executable_, | ||||
|             Container::Horizontal({ | ||||
|                 input_add, | ||||
|                 input, | ||||
|             }), | ||||
|         }), | ||||
|     })); | ||||
|  | ||||
|     // Compiler ---------------------------------------------------------------- | ||||
|     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", | ||||
|     InputBase::From(input_add)->on_enter = [this] { | ||||
|       input_entries.push_back(input_add_content); | ||||
|       input_add_content = L""; | ||||
|     }; | ||||
|     container.Add(&compiler); | ||||
|  | ||||
|     // Flags    ---------------------------------------------------------------- | ||||
|     container.Add(&flag); | ||||
|     flag_checkbox[0].label = L"-Wall"; | ||||
|     flag_checkbox[1].label = L"-Werror"; | ||||
|     flag_checkbox[2].label = L"-lpthread"; | ||||
|     flag_checkbox[3].label = L"-O3"; | ||||
|     for (auto& c : flag_checkbox) | ||||
|       flag.Add(&c); | ||||
|  | ||||
|     container.Add(&subcontainer); | ||||
|     // Executable | ||||
|     // ---------------------------------------------------------------- | ||||
|     executable.placeholder = L"executable"; | ||||
|     subcontainer.Add(&executable); | ||||
|  | ||||
|     // Input    ---------------------------------------------------------------- | ||||
|     subcontainer.Add(&input_container); | ||||
|  | ||||
|     input_add.placeholder = L"input files"; | ||||
|     input_add.on_enter = [this] { | ||||
|       input.entries.push_back(input_add.content); | ||||
|       input_add.content = L""; | ||||
|     }; | ||||
|     input_container.Add(&input_add); | ||||
|     input_container.Add(&input); | ||||
|   } | ||||
|  | ||||
|   Element Render() override { | ||||
|     auto compiler_win = window(text(L"Compiler"), compiler.Render() | frame); | ||||
|     auto flags_win = window(text(L"Flags"), flag.Render()); | ||||
|     auto executable_win = window(text(L"Executable:"), executable.Render()); | ||||
|     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 input_win = | ||||
|         window(text(L"Input"), | ||||
|                hbox({ | ||||
|                    vbox({ | ||||
|                        hbox({ | ||||
|                            text(L"Add: "), | ||||
|                            input_add.Render(), | ||||
|                            input_add->Render(), | ||||
|                        }) | size(WIDTH, EQUAL, 20) | | ||||
|                            size(HEIGHT, EQUAL, 1), | ||||
|                        filler(), | ||||
|                    }), | ||||
|                    separator(), | ||||
|                    input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex, | ||||
|                    input->Render() | frame | size(HEIGHT, EQUAL, 3) | flex, | ||||
|                })); | ||||
|     return vbox({ | ||||
|                hbox({ | ||||
| @@ -225,28 +235,29 @@ class CompilerComponent : public Component { | ||||
|   Elements RenderCommandLine() { | ||||
|     Elements line; | ||||
|     // Compiler | ||||
|     line.push_back(text(compiler.entries[compiler.selected]) | bold); | ||||
|     line.push_back(text(compiler_entries[compiler_selected]) | bold); | ||||
|     // flags | ||||
|     for (auto& it : flag_checkbox) { | ||||
|       if (it.state) { | ||||
|     for (int i = 0; i < 4; ++i) { | ||||
|       if (options_state[i]) { | ||||
|         line.push_back(text(L" ")); | ||||
|         line.push_back(text(it.label) | dim); | ||||
|         line.push_back(text(options_label[i]) | dim); | ||||
|       } | ||||
|     } | ||||
|     // Executable | ||||
|     if (!executable.content.empty()) { | ||||
|     if (!executable_content_.empty()) { | ||||
|       line.push_back(text(L" -O ") | bold); | ||||
|       line.push_back(text(executable.content) | color(Color::BlueLight) | bold); | ||||
|       line.push_back(text(executable_content_) | color(Color::BlueLight) | | ||||
|                      bold); | ||||
|     } | ||||
|     // Input | ||||
|     for (auto& it : input.entries) { | ||||
|     for (auto& it : input_entries) { | ||||
|       line.push_back(text(L" " + it) | color(Color::RedLight)); | ||||
|     } | ||||
|     return line; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class SpinnerComponent : public Component { | ||||
| class SpinnerComponent : public ComponentBase { | ||||
|   Element Render() override { | ||||
|     Elements entries; | ||||
|     for (int i = 0; i < 22; ++i) { | ||||
| @@ -258,7 +269,7 @@ class SpinnerComponent : public Component { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class ColorComponent : public Component { | ||||
| class ColorComponent : public ComponentBase { | ||||
|   Element Render() override { | ||||
|     return hbox({ | ||||
|                vbox({ | ||||
| @@ -304,7 +315,7 @@ class ColorComponent : public Component { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class GaugeComponent : public Component { | ||||
| class GaugeComponent : public ComponentBase { | ||||
|   Element RenderGauge(int delta) { | ||||
|     float progress = (shift + delta) % 1000 / 1000.f; | ||||
|     return hbox({ | ||||
| @@ -337,38 +348,35 @@ class GaugeComponent : public Component { | ||||
|   }; | ||||
| }; | ||||
|  | ||||
| class Tab : public Component { | ||||
| class Tab : public ComponentBase { | ||||
|  public: | ||||
|   Container main_container = Container::Vertical(); | ||||
|   int tab_index = 0; | ||||
|   std::vector<std::wstring> tab_entries = { | ||||
|       L"htop", L"color", L"spinner", L"gauge", L"compiler", | ||||
|   }; | ||||
|   Component tab_selection = Toggle(&tab_entries, &tab_index); | ||||
|   Component container = | ||||
|       Container::Tab(&tab_index, | ||||
|                      { | ||||
|                          std::make_shared<HTopComponent>(), | ||||
|                          std::make_shared<ColorComponent>(), | ||||
|                          std::make_shared<SpinnerComponent>(), | ||||
|                          std::make_shared<GaugeComponent>(), | ||||
|                          std::make_shared<CompilerComponent>(), | ||||
|                      }); | ||||
|  | ||||
|   Toggle tab_selection; | ||||
|   Container container = Container::Tab(&tab_selection.selected); | ||||
|   Component main_container = Container::Vertical({ | ||||
|       tab_selection, | ||||
|       container, | ||||
|   }); | ||||
|  | ||||
|   HTopComponent htop_component; | ||||
|   ColorComponent color_component; | ||||
|   SpinnerComponent spinner_component; | ||||
|   GaugeComponent gauge_component; | ||||
|   CompilerComponent compiler_component; | ||||
|  | ||||
|   Tab() { | ||||
|     Add(&main_container); | ||||
|     main_container.Add(&tab_selection); | ||||
|     tab_selection.entries = { | ||||
|         L"htop", L"color", L"spinner", L"gauge", L"compiler", | ||||
|     }; | ||||
|     main_container.Add(&container); | ||||
|     container.Add(&htop_component); | ||||
|     container.Add(&color_component); | ||||
|     container.Add(&spinner_component); | ||||
|     container.Add(&gauge_component); | ||||
|     container.Add(&compiler_component); | ||||
|   } | ||||
|   Tab() { Add(main_container); } | ||||
|  | ||||
|   Element Render() override { | ||||
|     return vbox({ | ||||
|         text(L"FTXUI Demo") | bold | hcenter, | ||||
|         tab_selection.Render() | hcenter, | ||||
|         container.Render() | flex, | ||||
|         tab_selection->Render() | hcenter, | ||||
|         container->Render() | flex, | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
| @@ -385,8 +393,8 @@ int main(int argc, const char* argv[]) { | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   Tab tab; | ||||
|   screen.Loop(&tab); | ||||
|   Component tab = std::make_shared<Tab>(); | ||||
|   screen.Loop(tab); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,44 +1,45 @@ | ||||
| #include "ftxui/component/input.hpp" | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include <memory>  // for allocator, __shared_ptr_access | ||||
| #include <string>  // for operator+, wstring, char_traits | ||||
|  | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Input, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for text, hbox, separator, border, vbox, Element | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|     container.Add(&input_1); | ||||
|     container.Add(&input_2); | ||||
|     container.Add(&input_3); | ||||
|  | ||||
|     input_1.placeholder = L"input1"; | ||||
|     input_2.placeholder = L"input2"; | ||||
|     input_3.placeholder = L"input3"; | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   Container container = Container::Vertical(); | ||||
|   Input input_1; | ||||
|   Input input_2; | ||||
|   Input input_3; | ||||
|   std::wstring first_name_; | ||||
|   std::wstring last_name_; | ||||
|   std::wstring first_name_placeholder_ = L"first_name"; | ||||
|   std::wstring last_name_placeholder_ = L"last_name"; | ||||
|   Component input_first_name_ = Input(&first_name_, &first_name_placeholder_); | ||||
|   Component input_last_name_ = Input(&last_name_, &last_name_placeholder_); | ||||
|  | ||||
|   Element Render() override { | ||||
|     return border(vbox({ | ||||
|         hbox({text(L" input_1 : "), input_1.Render()}), | ||||
|         hbox({text(L" input_2 : "), input_2.Render()}), | ||||
|         hbox({text(L" input_3 : "), input_3.Render()}), | ||||
|         text(L"Hello " + first_name_ + L" " + last_name_), | ||||
|         separator(), | ||||
|         hbox({text(L" First name  : "), input_first_name_->Render()}), | ||||
|         hbox({text(L" Last name   : "), input_last_name_->Render()}), | ||||
|     })); | ||||
|   } | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(Container::Vertical({ | ||||
|         input_first_name_, | ||||
|         input_last_name_, | ||||
|     })); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,24 +1,30 @@ | ||||
| #include <functional>  // for function | ||||
| #include <iostream>    // for basic_ostream::ope... | ||||
| #include <string>      // for wstring, allocator | ||||
| #include <vector>      // for vector | ||||
| #include <iostream>  // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream | ||||
| #include <string>    // for wstring, allocator, basic_string | ||||
| #include <vector>    // for vector | ||||
|  | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/captured_mouse.hpp"      // for ftxui | ||||
| #include "ftxui/component/component.hpp"           // for Menu | ||||
| #include "ftxui/component/menu.hpp"                // for MenuBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|  | ||||
|   Menu menu; | ||||
|   menu.entries = {L"entry 1", L"entry 2", L"entry 3"}; | ||||
|   menu.selected = 0; | ||||
|   menu.on_enter = screen.ExitLoopClosure(); | ||||
|   std::vector<std::wstring> entries = { | ||||
|       L"entry 1", | ||||
|       L"entry 2", | ||||
|       L"entry 3", | ||||
|   }; | ||||
|   int selected = 0; | ||||
|  | ||||
|   screen.Loop(&menu); | ||||
|   auto menu = Menu(&entries, &selected); | ||||
|   MenuBase::From(menu)->on_enter = screen.ExitLoopClosure(); | ||||
|  | ||||
|   std::cout << "Selected element = " << menu.selected << std::endl; | ||||
|   screen.Loop(menu); | ||||
|  | ||||
|   std::cout << "Selected element = " << selected << std::endl; | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,84 +1,88 @@ | ||||
| #include <functional>  // for function | ||||
| #include <string>      // for wstring, allocator | ||||
| #include <vector>      // for vector | ||||
| #include <memory>      // for __shared_ptr_access, shared_ptr | ||||
| #include <string>  // for wstring, allocator, operator+, to_string, basic_string | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"                  // for text, separator, bold | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/screen/string.hpp"                 // for to_wstring | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Menu, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/menu.hpp"            // for MenuBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for text, separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border | ||||
| #include "ftxui/screen/string.hpp"  // for to_wstring | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|     container.Add(&left_menu); | ||||
|     container.Add(&right_menu); | ||||
|  | ||||
|     left_menu.entries = { | ||||
|         L"0%",  L"10%", L"20%", L"30%", L"40%", | ||||
|         L"50%", L"60%", L"70%", L"80%", L"90%", | ||||
|     }; | ||||
|     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%", | ||||
|     }; | ||||
|  | ||||
|     left_menu.on_enter = [this]() { on_enter(); }; | ||||
|     right_menu.on_enter = [this]() { on_enter(); }; | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   Container container = Container::Horizontal(); | ||||
|   Menu left_menu; | ||||
|   Menu right_menu; | ||||
|   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::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%", | ||||
|   }; | ||||
|   int left_menu_selected = 0; | ||||
|   int right_menu_selected = 0; | ||||
|   Component left_menu_ = Menu(&left_menu_entries, &left_menu_selected); | ||||
|   Component right_menu_ = Menu(&right_menu_entries, &right_menu_selected); | ||||
|   Component container = Container::Horizontal({ | ||||
|       left_menu_, | ||||
|       right_menu_, | ||||
|   }); | ||||
|  | ||||
|   Element Render() override { | ||||
|     int sum = left_menu.selected * 10 + right_menu.selected; | ||||
|     return border(vbox({ | ||||
|         // -------- Top panel -------------- | ||||
|         hbox({ | ||||
|             // -------- Left Menu -------------- | ||||
|             vbox({ | ||||
|                 hcenter(bold(text(L"Percentage by 10%"))), | ||||
|                 separator(), | ||||
|                 left_menu.Render(), | ||||
|             }) | flex, | ||||
|             // -------- Right Menu -------------- | ||||
|             vbox({ | ||||
|                 hcenter(bold(text(L"Percentage by 1%"))), | ||||
|                 separator(), | ||||
|                 right_menu.Render(), | ||||
|             }) | flex, | ||||
|             filler(), | ||||
|         }), | ||||
|         separator(), | ||||
|         // -------- Bottom panel -------------- | ||||
|         vbox({ | ||||
|             hbox({ | ||||
|                 text(L" gauge : "), | ||||
|                 gauge(sum / 100.0), | ||||
|             }), | ||||
|             hbox({ | ||||
|                 text(L"  text : "), | ||||
|                 text(to_wstring(std::to_string(sum) + " %")), | ||||
|             }), | ||||
|         }) | flex, | ||||
|     })); | ||||
|     int sum = left_menu_selected * 10 + right_menu_selected; | ||||
|     return vbox({ | ||||
|                // -------- Top panel -------------- | ||||
|                hbox({ | ||||
|                    // -------- Left Menu -------------- | ||||
|                    vbox({ | ||||
|                        hcenter(bold(text(L"Percentage by 10%"))), | ||||
|                        separator(), | ||||
|                        left_menu_->Render(), | ||||
|                    }), | ||||
|                    separator(), | ||||
|                    // -------- Right Menu -------------- | ||||
|                    vbox({ | ||||
|                        hcenter(bold(text(L"Percentage by 1%"))), | ||||
|                        separator(), | ||||
|                        right_menu_->Render(), | ||||
|                    }), | ||||
|                    separator(), | ||||
|                }), | ||||
|                separator(), | ||||
|                // -------- Bottom panel -------------- | ||||
|                vbox({ | ||||
|                    hbox({ | ||||
|                        text(L" gauge : "), | ||||
|                        gauge(sum / 100.0), | ||||
|                    }), | ||||
|                    hbox({ | ||||
|                        text(L"  text : "), | ||||
|                        text(to_wstring(std::to_string(sum) + " %")), | ||||
|                    }), | ||||
|                }), | ||||
|            }) | | ||||
|            border; | ||||
|   } | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(container); | ||||
|     MenuBase::From(left_menu_)->on_enter = [this]() { on_enter(); }; | ||||
|     MenuBase::From(right_menu_)->on_enter = [this]() { on_enter(); }; | ||||
|   } | ||||
|   std::function<void()> on_enter = []() {}; | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   auto component = Make<MyComponent>(); | ||||
|   component->on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(component); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,92 +1,100 @@ | ||||
| #include <functional>        // for function | ||||
| #include <initializer_list>  // for initializer_list | ||||
| #include <string>            // for wstring, allocator | ||||
| #include <memory>            // for __shared_ptr_access | ||||
| #include <string>            // for wstring, allocator, basic_string | ||||
| #include <vector>            // for vector | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"                  // for operator|, Element | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/screen/color.hpp"                  // for Color, Color::Blue | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Menu, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/menu.hpp"            // for MenuBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for operator|, Element, separator, bgcolor, color, flex, Decorator, bold, hbox, border, dim | ||||
| #include "ftxui/screen/color.hpp"  // for Color, Color::Blue, Color::BlueLight, Color::Red, Color::Yellow | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| std::vector<std::wstring> entries = { | ||||
|     L"Monkey", L"Dog", L"Cat", L"Bird", L"Elephant", | ||||
| }; | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|   MyComponent(std::function<void(void)> exit) { | ||||
|     on_enter_ = exit; | ||||
|  | ||||
|     for (Menu* menu : { | ||||
|              &menu_1, | ||||
|              &menu_2, | ||||
|              &menu_3, | ||||
|              &menu_4, | ||||
|              &menu_5, | ||||
|              &menu_6, | ||||
|          }) { | ||||
|       container.Add(menu); | ||||
|       menu->entries = { | ||||
|           L"Monkey", L"Dog", L"Cat", L"Bird", L"Elephant", | ||||
|       }; | ||||
|       menu->on_enter = [this]() { on_enter(); }; | ||||
|     } | ||||
|     Add(container); | ||||
|  | ||||
|     menu_2.focused_style = bold | color(Color::Blue); | ||||
|     menu_2.selected_style = color(Color::Blue); | ||||
|     menu_2.selected_focused_style = bold | color(Color::Blue); | ||||
|     for (Component menu : | ||||
|          {menu_1_, menu_2_, menu_3_, menu_4_, menu_5_, menu_6_}) | ||||
|       MenuBase::From(menu)->on_enter = [this] { on_enter_(); }; | ||||
|  | ||||
|     menu_3.selected_style = color(Color::Blue); | ||||
|     menu_3.focused_style = bgcolor(Color::Blue); | ||||
|     menu_3.selected_focused_style = bgcolor(Color::Blue); | ||||
|     MenuBase::From(menu_2_)->focused_style = bold | color(Color::Blue); | ||||
|     MenuBase::From(menu_2_)->selected_style = color(Color::Blue); | ||||
|     MenuBase::From(menu_2_)->selected_focused_style = bold | color(Color::Blue); | ||||
|  | ||||
|     menu_4.selected_style = bgcolor(Color::Blue); | ||||
|     menu_4.focused_style = bgcolor(Color::BlueLight); | ||||
|     menu_4.selected_focused_style = bgcolor(Color::BlueLight); | ||||
|     MenuBase::From(menu_3_)->selected_style = color(Color::Blue); | ||||
|     MenuBase::From(menu_3_)->focused_style = bgcolor(Color::Blue); | ||||
|     MenuBase::From(menu_3_)->selected_focused_style = bgcolor(Color::Blue); | ||||
|  | ||||
|     menu_5.normal_style = bgcolor(Color::Blue); | ||||
|     menu_5.selected_style = bgcolor(Color::Yellow); | ||||
|     menu_5.focused_style = bgcolor(Color::Red); | ||||
|     menu_5.selected_focused_style = bgcolor(Color::Red); | ||||
|     MenuBase::From(menu_4_)->selected_style = bgcolor(Color::Blue); | ||||
|     MenuBase::From(menu_4_)->focused_style = bgcolor(Color::BlueLight); | ||||
|     MenuBase::From(menu_4_)->selected_focused_style = bgcolor(Color::BlueLight); | ||||
|  | ||||
|     menu_6.normal_style = dim | color(Color::Blue); | ||||
|     menu_6.selected_style = color(Color::Blue); | ||||
|     menu_6.focused_style = bold | color(Color::Blue); | ||||
|     menu_6.selected_focused_style = bold | color(Color::Blue); | ||||
|     MenuBase::From(menu_5_)->normal_style = bgcolor(Color::Blue); | ||||
|     MenuBase::From(menu_5_)->selected_style = bgcolor(Color::Yellow); | ||||
|     MenuBase::From(menu_5_)->focused_style = bgcolor(Color::Red); | ||||
|     MenuBase::From(menu_5_)->selected_focused_style = bgcolor(Color::Red); | ||||
|  | ||||
|     MenuBase::From(menu_6_)->normal_style = dim | color(Color::Blue); | ||||
|     MenuBase::From(menu_6_)->selected_style = color(Color::Blue); | ||||
|     MenuBase::From(menu_6_)->focused_style = bold | color(Color::Blue); | ||||
|     MenuBase::From(menu_6_)->selected_focused_style = bold | color(Color::Blue); | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|   std::function<void()> on_enter_; | ||||
|  | ||||
|  private: | ||||
|   Container container = Container::Horizontal(); | ||||
|   Menu menu_1; | ||||
|   Menu menu_2; | ||||
|   Menu menu_3; | ||||
|   Menu menu_4; | ||||
|   Menu menu_5; | ||||
|   Menu menu_6; | ||||
|   int menu_1_selected_ = 0; | ||||
|   int menu_2_selected_ = 0; | ||||
|   int menu_3_selected_ = 0; | ||||
|   int menu_4_selected_ = 0; | ||||
|   int menu_5_selected_ = 0; | ||||
|   int menu_6_selected_ = 0; | ||||
|   Component menu_1_ = Menu(&entries, &menu_1_selected_); | ||||
|   Component menu_2_ = Menu(&entries, &menu_2_selected_); | ||||
|   Component menu_3_ = Menu(&entries, &menu_3_selected_); | ||||
|   Component menu_4_ = Menu(&entries, &menu_4_selected_); | ||||
|   Component menu_5_ = Menu(&entries, &menu_5_selected_); | ||||
|   Component menu_6_ = Menu(&entries, &menu_6_selected_); | ||||
|   Component container = Container::Horizontal({ | ||||
|       menu_1_, | ||||
|       menu_2_, | ||||
|       menu_3_, | ||||
|       menu_4_, | ||||
|       menu_5_, | ||||
|       menu_6_, | ||||
|   }); | ||||
|  | ||||
|   // clang-format off | ||||
|    Element Render() override { | ||||
|      return | ||||
|         hbox({ | ||||
|           menu_1.Render() | flex, separator(), | ||||
|           menu_2.Render() | flex, separator(), | ||||
|           menu_3.Render() | flex, separator(), | ||||
|           menu_4.Render() | flex, separator(), | ||||
|           menu_5.Render() | flex, separator(), | ||||
|           menu_6.Render() | flex, | ||||
|         }) | border; | ||||
|    } | ||||
|   Element Render() override { | ||||
|    return | ||||
|       hbox({ | ||||
|         menu_1_->Render() | flex, separator(), | ||||
|         menu_2_->Render() | flex, separator(), | ||||
|         menu_3_->Render() | flex, separator(), | ||||
|         menu_4_->Render() | flex, separator(), | ||||
|         menu_5_->Render() | flex, separator(), | ||||
|         menu_6_->Render() | flex, | ||||
|       }) | border; | ||||
|   } | ||||
|   // clang-format on | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>(screen.ExitLoopClosure())); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,132 +1,130 @@ | ||||
| #include <functional>  // for function | ||||
| #include <memory>      // for allocator_traits<>... | ||||
| #include <string>      // for operator+, wstring | ||||
| #include <vector>      // for vector | ||||
| #include <memory>  // for allocator, __shared_ptr_access, shared_ptr, make_shared | ||||
| #include <string>  // for wstring, operator+, basic_string, char_traits | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/button.hpp"              // for Button | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"                  // for Element, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Button, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for Element, operator|, filler, text, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| // The main screen, at depth 0. It display the main content. | ||||
| class Content : public Component { | ||||
| class Content : public ComponentBase { | ||||
|  private: | ||||
|   std::wstring label_rate_ftxui_ = L"Rate FTXUI"; | ||||
|   std::wstring label_quit_ = L"Quit"; | ||||
|   bool modal_open_ = false; | ||||
|  | ||||
|   Component button_rate_ftxui_ = | ||||
|       Button(&label_rate_ftxui_, [this] { on_rate_ftxui(); }); | ||||
|   Component button_quit_ = Button(&label_quit_, [this] { on_quit(); }); | ||||
|   Component container_ = Container::Horizontal({ | ||||
|       button_rate_ftxui_, | ||||
|       button_quit_, | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   std::function<void()> on_rate_ftxui = [] {}; | ||||
|   std::function<void()> on_quit = [] {}; | ||||
|   std::wstring rating_ = L"3/5 stars"; | ||||
|   Content() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&button_rate_ftxui); | ||||
|     container_.Add(&button_quit_); | ||||
|     button_rate_ftxui.on_click = [&] { on_rate_ftxui(); }; | ||||
|     button_quit_.on_click = [&] { on_quit(); }; | ||||
|   } | ||||
|   std::wstring rating = L"3/5 stars"; | ||||
|   std::function<void()> on_rate_ftxui; | ||||
|   std::function<void()> on_quit; | ||||
|  | ||||
|   Content() { Add(container_); } | ||||
|  | ||||
|   Element Render() final { | ||||
|     auto button_elements = hbox({ | ||||
|         button_rate_ftxui.Render(), | ||||
|         filler(), | ||||
|         button_quit_.Render(), | ||||
|     }); | ||||
|  | ||||
|     auto document =  // | ||||
|         vbox({ | ||||
|             text(L"Modal dialog example"), | ||||
|             separator(), | ||||
|             text(L"☆☆☆ FTXUI:" + rating_ + L" ☆☆☆") | bold, | ||||
|             text(L"☆☆☆ FTXUI:" + rating + L" ☆☆☆") | bold, | ||||
|             filler(), | ||||
|             button_elements, | ||||
|             hbox({ | ||||
|                 button_rate_ftxui_->Render(), | ||||
|                 filler(), | ||||
|                 button_quit_->Render(), | ||||
|             }), | ||||
|         }) | | ||||
|         border; | ||||
|  | ||||
|     return document | size(HEIGHT, GREATER_THAN, 18) | center; | ||||
|   } | ||||
| }; | ||||
|  | ||||
|  private: | ||||
|   Container container_ = Container::Horizontal(); | ||||
|   Button button_rate_ftxui = Button(L"Rate FTXUI"); | ||||
|   Button button_quit_ = Button(L"Quit"); | ||||
| 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", | ||||
| }; | ||||
|  | ||||
| // The "modal" screen, at depth 1. It display the modal dialog. | ||||
| class Modal : public Component { | ||||
| class Modal : public ComponentBase { | ||||
|  private: | ||||
|   Component container_ = Container::Horizontal({ | ||||
|       Button(&rating_labels[0], [this] { on_click(rating_labels[0]); }), | ||||
|       Button(&rating_labels[1], [this] { on_click(rating_labels[1]); }), | ||||
|       Button(&rating_labels[2], [this] { on_click(rating_labels[2]); }), | ||||
|       Button(&rating_labels[3], [this] { on_click(rating_labels[3]); }), | ||||
|       Button(&rating_labels[4], [this] { on_click(rating_labels[4]); }), | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   std::function<void(std::wstring)> on_click; | ||||
|  | ||||
|   Modal() { | ||||
|     Add(&container_); | ||||
|     buttons_.resize(5); | ||||
|     for (int i = 0; i < 5; ++i) { | ||||
|       std::wstring stars = std::to_wstring(i + 1) + L"/5 stars"; | ||||
|       buttons_[i] = Button(stars); | ||||
|       buttons_[i].on_click = [&, stars] { on_click(stars); }; | ||||
|       container_.Add(&buttons_[i]); | ||||
|     } | ||||
|   } | ||||
|   Modal() { Add(container_); } | ||||
|  | ||||
|   Element Render() final { | ||||
|     return vbox({ | ||||
|                text(L"Do you like FTXUI?"), | ||||
|                separator(), | ||||
|                hbox({ | ||||
|                    buttons_[0].Render(), | ||||
|                    buttons_[1].Render(), | ||||
|                    buttons_[2].Render(), | ||||
|                    buttons_[3].Render(), | ||||
|                    buttons_[4].Render(), | ||||
|                }), | ||||
|                hbox(container_->Render()), | ||||
|            }) | | ||||
|            border; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Container container_ = Container::Horizontal(); | ||||
|   std::vector<Button> buttons_; | ||||
| }; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   std::shared_ptr<Content> content_ = std::make_shared<Content>(); | ||||
|   std::shared_ptr<Modal> modal_ = std::make_shared<Modal>(); | ||||
|  | ||||
|   int depth = 0; | ||||
|   Component container_ = Container::Tab(&depth, | ||||
|                                         { | ||||
|                                             content_, | ||||
|                                             modal_, | ||||
|                                         }); | ||||
|  | ||||
|   std::function<void()> on_quit_; | ||||
|  | ||||
|  public: | ||||
|   std::function<void()> on_quit = [] {}; | ||||
|   MyComponent(std::function<void()> on_quit) : on_quit_(on_quit) { | ||||
|     Add(container_); | ||||
|  | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&content_); | ||||
|     container_.Add(&modal_); | ||||
|  | ||||
|     content_.on_quit = [&] { on_quit(); }; | ||||
|     content_.on_rate_ftxui = [&] { modal_.TakeFocus(); }; | ||||
|     modal_.on_click = [&](std::wstring rating) { | ||||
|       content_.rating_ = rating; | ||||
|       content_.TakeFocus(); | ||||
|     content_->on_quit = [&] { on_quit(); }; | ||||
|     content_->on_rate_ftxui = [this] { depth = 1; }; | ||||
|     modal_->on_click = [&](std::wstring rating) { | ||||
|       content_->rating = rating; | ||||
|       depth = 0; | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   Element Render() final { | ||||
|     Element document = content_.Render(); | ||||
|     if (modal_.Focused()) { | ||||
|     Element document = content_->Render(); | ||||
|  | ||||
|     if (depth == 1) { | ||||
|       document = dbox({ | ||||
|           document, | ||||
|           modal_.Render() | clear_under | center, | ||||
|           modal_->Render() | clear_under | center, | ||||
|       }); | ||||
|     } | ||||
|     return document; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Container container_ = Container::Tab(nullptr); | ||||
|   Content content_; | ||||
|   Modal modal_; | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent my_component; | ||||
|   my_component.on_quit = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&my_component); | ||||
|   screen.Loop(Make<MyComponent>(screen.ExitLoopClosure())); | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,18 +1,23 @@ | ||||
| #include "ftxui/component/radiobox.hpp" | ||||
| #include <string>  // for wstring, allocator, basic_string | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/captured_mouse.hpp"      // for ftxui | ||||
| #include "ftxui/component/component.hpp"           // for Radiobox | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   RadioBox radiobox; | ||||
|   radiobox.entries = { | ||||
|   std::vector<std::wstring> radiobox_list = { | ||||
|       L"Use gcc", | ||||
|       L"Use clang", | ||||
|       L"Use emscripten", | ||||
|       L"Use tcc", | ||||
|   }; | ||||
|   screen.Loop(&radiobox); | ||||
|   int selected = 0; | ||||
|  | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   screen.Loop(Radiobox(&radiobox_list, &selected)); | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,35 +1,36 @@ | ||||
| #include <string>  // for wstring, operator+ | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/radiobox.hpp"            // for RadioBox | ||||
| #include "ftxui/component/captured_mouse.hpp"      // for ftxui | ||||
| #include "ftxui/component/component.hpp"           // for Make, Radiobox | ||||
| #include "ftxui/component/component_base.hpp"      // for ComponentBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"                  // for Element, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/screen/string.hpp"                 // for to_wstring | ||||
| #include "ftxui/dom/elements.hpp"  // for Element, operator|, size, border, frame, HEIGHT, LESS_THAN | ||||
| #include "ftxui/screen/string.hpp"  // for to_wstring | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   RadioBox radiobox; | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   std::vector<std::wstring> entries_; | ||||
|   int selected_ = 0; | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     for (int i = 0; i < 30; ++i) { | ||||
|       radiobox.entries.push_back(L"RadioBox " + to_wstring(i)); | ||||
|     } | ||||
|     Add(&radiobox); | ||||
|     for (int i = 0; i < 30; ++i) | ||||
|       entries_.push_back(L"RadioBox " + to_wstring(i)); | ||||
|     Add(Radiobox(&entries_, &selected_)); | ||||
|   } | ||||
|  | ||||
|   Element Render() override { | ||||
|     return radiobox.Render() | frame | size(HEIGHT, LESS_THAN, 10) | border; | ||||
|     return ComponentBase::Render() | frame | size(HEIGHT, LESS_THAN, 10) | | ||||
|            border; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::FitComponent(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,82 +1,16 @@ | ||||
| #include <functional>  // for function | ||||
| #include <memory>      // for allocator, unique_ptr | ||||
| #include <string>      // for operator+, to_wstring | ||||
| #include <memory>  // for allocator | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component, Compone... | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/event.hpp"               // for Event, Event::Escape | ||||
| #include "ftxui/component/captured_mouse.hpp"      // for ftxui | ||||
| #include "ftxui/component/component.hpp"           // for Slider | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/component/slider.hpp"              // for Slider | ||||
| #include "ftxui/dom/elements.hpp"                  // for separator, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #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) | | ||||
|          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")"     // | ||||
|   ); | ||||
| } | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|  public: | ||||
|   MyComponent(int* red, int* green, int* blue, std::function<void(void)> quit) | ||||
|       : red_(red), green_(green), blue_(blue), quit_(quit) { | ||||
|     Add(&container_); | ||||
|     container_.Add(slider_red_.get()); | ||||
|     container_.Add(slider_green_.get()); | ||||
|     container_.Add(slider_blue_.get()); | ||||
|   } | ||||
|  | ||||
|   Element Render() { | ||||
|     return hbox({ | ||||
|                ColorTile(*red_, *green_, *blue_), | ||||
|                separator(), | ||||
|                vbox({ | ||||
|                    slider_red_->Render(), | ||||
|                    separator(), | ||||
|                    slider_green_->Render(), | ||||
|                    separator(), | ||||
|                    slider_blue_->Render(), | ||||
|                    separator(), | ||||
|                    ColorString(*red_, *green_, *blue_), | ||||
|                }) | xflex, | ||||
|            }) | | ||||
|            border | size(WIDTH, LESS_THAN, 80); | ||||
|   } | ||||
|  | ||||
|   bool OnEvent(Event event) { | ||||
|     if (event == Event::Return || event == Event::Escape) | ||||
|       quit_(); | ||||
|     return Component::OnEvent(event); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   int* red_; | ||||
|   int* green_; | ||||
|   int* blue_; | ||||
|   Container container_ = Container::Vertical(); | ||||
|   ComponentPtr slider_red_ = Slider(L"Red  :", red_, 0, 255, 1); | ||||
|   ComponentPtr slider_green_ = Slider(L"Green:", green_, 0, 255, 1); | ||||
|   ComponentPtr slider_blue_ = Slider(L"Blue :", blue_, 0, 255, 1); | ||||
|   std::function<void(void)> quit_; | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   int red = 128; | ||||
|   int green = 25; | ||||
|   int blue = 100; | ||||
|   auto component = MyComponent(&red, &green, &blue, screen.ExitLoopClosure()); | ||||
|   screen.Loop(&component); | ||||
|   int value = 50; | ||||
|   auto slider = Slider(L"Value:", &value, 0, 100, 1); | ||||
|   screen.Loop(slider); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,71 +1,77 @@ | ||||
| #include <functional>  // for function | ||||
| #include <string>      // for wstring, allocator | ||||
| #include <vector>      // for vector | ||||
| #include <memory>  // for __shared_ptr_access | ||||
| #include <string>  // for wstring, allocator, basic_string | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/radiobox.hpp"            // for RadioBox | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/component/toggle.hpp"              // for Toggle | ||||
| #include "ftxui/dom/elements.hpp"                  // for Element, operator| | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Radiobox, Make, Toggle | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for Element, separator, operator|, vbox, border | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   std::vector<std::wstring> tab_values_ = { | ||||
|       L"tab_1", | ||||
|       L"tab_2", | ||||
|       L"tab_3", | ||||
|   }; | ||||
|   int tab_selected_ = 0; | ||||
|   Component tab_toggle_ = Toggle(&tab_values_, &tab_selected_); | ||||
|  | ||||
|   std::vector<std::wstring> tab_1_entries_ = { | ||||
|       L"Forest", | ||||
|       L"Water", | ||||
|       L"I don't know", | ||||
|   }; | ||||
|   int tab_1_selected_ = 0; | ||||
|  | ||||
|   std::vector<std::wstring> tab_2_entries_ = { | ||||
|       L"Hello", | ||||
|       L"Hi", | ||||
|       L"Hay", | ||||
|   }; | ||||
|   int tab_2_selected_ = 0; | ||||
|  | ||||
|   std::vector<std::wstring> tab_3_entries_ = { | ||||
|       L"Table", | ||||
|       L"Nothing", | ||||
|       L"Is", | ||||
|       L"Empty", | ||||
|   }; | ||||
|   int tab_3_selected_ = 0; | ||||
|  | ||||
|   Component tab_container_ = | ||||
|       Container::Tab(&tab_selected_, | ||||
|                      { | ||||
|                          Radiobox(&tab_1_entries_, &tab_1_selected_), | ||||
|                          Radiobox(&tab_2_entries_, &tab_2_selected_), | ||||
|                          Radiobox(&tab_3_entries_, &tab_3_selected_), | ||||
|                      }); | ||||
|  | ||||
|   Component container_ = Container::Vertical({ | ||||
|       tab_toggle_, | ||||
|       tab_container_, | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&toggle_); | ||||
|  | ||||
|     toggle_.entries = { | ||||
|         L"tab_1", | ||||
|         L"tab_2", | ||||
|         L"tab_3", | ||||
|     }; | ||||
|  | ||||
|     container_.Add(&tab_container_); | ||||
|  | ||||
|     radiobox_1_.entries = {L"Forest", L"Water", L"I don't know"}; | ||||
|     tab_container_.Add(&radiobox_1_); | ||||
|  | ||||
|     radiobox_2_.entries = { | ||||
|         L"Hello", | ||||
|         L"Hi", | ||||
|         L"Hay", | ||||
|     }; | ||||
|     tab_container_.Add(&radiobox_2_); | ||||
|  | ||||
|     radiobox_3_.entries = { | ||||
|         L"Table", | ||||
|         L"Nothing", | ||||
|         L"Is", | ||||
|         L"Empty", | ||||
|     }; | ||||
|     tab_container_.Add(&radiobox_3_); | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|   MyComponent() { Add(container_); } | ||||
|  | ||||
|   Element Render() { | ||||
|     return vbox(toggle_.Render(), separator(), tab_container_.Render()) | | ||||
|     return vbox({ | ||||
|                tab_toggle_->Render(), | ||||
|                separator(), | ||||
|                tab_container_->Render(), | ||||
|            }) | | ||||
|            border; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   Toggle toggle_; | ||||
|   Container container_ = Container::Vertical(); | ||||
|   Container tab_container_ = Container::Tab(&(toggle_.selected)); | ||||
|   RadioBox radiobox_1_; | ||||
|   RadioBox radiobox_2_; | ||||
|   RadioBox radiobox_3_; | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,64 +1,77 @@ | ||||
| #include <functional>  // for function | ||||
| #include <string>      // for wstring, allocator | ||||
| #include <vector>      // for vector | ||||
| #include <memory>  // for __shared_ptr_access | ||||
| #include <string>  // for wstring, allocator, basic_string | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/component.hpp"           // for Component | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/menu.hpp"                // for Menu | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/screen/box.hpp"                    // for ftxui | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Radiobox, Make, Menu | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for Element, separator, hbox, operator|, border | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&menu_); | ||||
|  | ||||
|     menu_.entries = { | ||||
|         L"menu_1", | ||||
|         L"menu_2", | ||||
|         L"menu_3", | ||||
|     }; | ||||
|  | ||||
|     container_.Add(&tab_container_); | ||||
|  | ||||
|     menu_1_.entries = {L"Forest", L"Water", L"I don't know"}; | ||||
|     tab_container_.Add(&menu_1_); | ||||
|  | ||||
|     menu_2_.entries = { | ||||
|         L"Hello", | ||||
|         L"Hi", | ||||
|         L"Hay", | ||||
|     }; | ||||
|     tab_container_.Add(&menu_2_); | ||||
|  | ||||
|     menu_3_.entries = { | ||||
|         L"Table", | ||||
|         L"Nothing", | ||||
|         L"Is", | ||||
|         L"Empty", | ||||
|     }; | ||||
|     tab_container_.Add(&menu_3_); | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   Menu menu_; | ||||
|   Container container_ = Container::Horizontal(); | ||||
|   Container tab_container_ = Container::Tab(&(menu_.selected)); | ||||
|   Menu menu_1_; | ||||
|   Menu menu_2_; | ||||
|   Menu menu_3_; | ||||
|   std::vector<std::wstring> tab_values_ = { | ||||
|       L"tab_1", | ||||
|       L"tab_2", | ||||
|       L"tab_3", | ||||
|   }; | ||||
|   int tab_selected_ = 0; | ||||
|   Component tab_toggle_ = Menu(&tab_values_, &tab_selected_); | ||||
|  | ||||
|   std::vector<std::wstring> tab_1_entries_ = { | ||||
|       L"Forest", | ||||
|       L"Water", | ||||
|       L"I don't know", | ||||
|   }; | ||||
|   int tab_1_selected_ = 0; | ||||
|  | ||||
|   std::vector<std::wstring> tab_2_entries_ = { | ||||
|       L"Hello", | ||||
|       L"Hi", | ||||
|       L"Hay", | ||||
|   }; | ||||
|   int tab_2_selected_ = 0; | ||||
|  | ||||
|   std::vector<std::wstring> tab_3_entries_ = { | ||||
|       L"Table", | ||||
|       L"Nothing", | ||||
|       L"Is", | ||||
|       L"Empty", | ||||
|   }; | ||||
|   int tab_3_selected_ = 0; | ||||
|  | ||||
|   Component tab_container_ = | ||||
|       Container::Tab(&tab_selected_, | ||||
|                      { | ||||
|                          Radiobox(&tab_1_entries_, &tab_1_selected_), | ||||
|                          Radiobox(&tab_2_entries_, &tab_2_selected_), | ||||
|                          Radiobox(&tab_3_entries_, &tab_3_selected_), | ||||
|                      }); | ||||
|  | ||||
|   Component container_ = Container::Horizontal({ | ||||
|       tab_toggle_, | ||||
|       tab_container_, | ||||
|   }); | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { Add(container_); } | ||||
|  | ||||
|   Element Render() { | ||||
|     return hbox({ | ||||
|                tab_toggle_->Render(), | ||||
|                separator(), | ||||
|                tab_container_->Render(), | ||||
|            }) | | ||||
|            border; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>()); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -1,59 +1,82 @@ | ||||
| #include "ftxui/component/toggle.hpp" | ||||
| #include "ftxui/component/container.hpp"           // for Container | ||||
| #include "ftxui/component/event.hpp"               // for Event, Event::Return | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include <functional>  // for function | ||||
| #include <memory>      // for allocator, __shared_ptr_access | ||||
| #include <string>      // for wstring, basic_string | ||||
| #include <vector>      // for vector | ||||
|  | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Toggle, Make | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/container.hpp"       // for Container | ||||
| #include "ftxui/component/event.hpp"           // for Event, Event::Return | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for text, hbox, vbox, Element | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container_); | ||||
|     container_.Add(&toggle_1_); | ||||
|     container_.Add(&toggle_2_); | ||||
|     container_.Add(&toggle_3_); | ||||
|     container_.Add(&toggle_4_); | ||||
|  | ||||
|     toggle_1_.entries = {L"On", L"Off"}; | ||||
|     toggle_2_.entries = {L"Enabled", L"Disabled"}; | ||||
|     toggle_3_.entries = {L"10€", L"0€"}; | ||||
|     toggle_4_.entries = {L"Nothing", L"One element", L"Several elements"}; | ||||
|   } | ||||
|  | ||||
|   std::function<void()> on_enter = []() {}; | ||||
|  | ||||
| class MyComponent : public ComponentBase { | ||||
|  private: | ||||
|   Container container_ = Container::Vertical(); | ||||
|   Toggle toggle_1_; | ||||
|   Toggle toggle_2_; | ||||
|   Toggle toggle_3_; | ||||
|   Toggle toggle_4_; | ||||
|   std::vector<std::wstring> toggle_1_entries_ = { | ||||
|       L"On", | ||||
|       L"Off", | ||||
|   }; | ||||
|   std::vector<std::wstring> toggle_2_entries_ = { | ||||
|       L"Enabled", | ||||
|       L"Disabled", | ||||
|   }; | ||||
|   std::vector<std::wstring> toggle_3_entries_ = { | ||||
|       L"10€", | ||||
|       L"0€", | ||||
|   }; | ||||
|   std::vector<std::wstring> toggle_4_entries_ = { | ||||
|       L"Nothing", | ||||
|       L"One element", | ||||
|       L"Several elements", | ||||
|   }; | ||||
|  | ||||
|   int toggle_1_selected_ = 0; | ||||
|   int toggle_2_selected_ = 0; | ||||
|   int toggle_3_selected_ = 0; | ||||
|   int toggle_4_selected_ = 0; | ||||
|   Component toggle_1_ = Toggle(&toggle_1_entries_, &toggle_1_selected_); | ||||
|   Component toggle_2_ = Toggle(&toggle_2_entries_, &toggle_2_selected_); | ||||
|   Component toggle_3_ = Toggle(&toggle_3_entries_, &toggle_3_selected_); | ||||
|   Component toggle_4_ = Toggle(&toggle_4_entries_, &toggle_4_selected_); | ||||
|  | ||||
|   std::function<void()> exit_; | ||||
|  | ||||
|   Element Render() override { | ||||
|     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()), | ||||
|         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()), | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   bool OnEvent(Event event) override { | ||||
|     if (event == Event::Return) { | ||||
|       on_enter(); | ||||
|       exit_(); | ||||
|       return true; | ||||
|     } | ||||
|     return Component::OnEvent(event); | ||||
|     return ComponentBase::OnEvent(event); | ||||
|   } | ||||
|  | ||||
|  public: | ||||
|   MyComponent(std::function<void()> exit) : exit_(exit) { | ||||
|     Add(Container::Vertical({ | ||||
|         toggle_1_, | ||||
|         toggle_2_, | ||||
|         toggle_3_, | ||||
|         toggle_4_, | ||||
|     })); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
|   screen.Loop(Make<MyComponent>(screen.ExitLoopClosure())); | ||||
| } | ||||
|  | ||||
| // Copyright 2020 Arthur Sonzogni. All rights reserved. | ||||
|   | ||||
| @@ -33,15 +33,18 @@ | ||||
|       "./component/menu.js", | ||||
|       "./component/menu2.js", | ||||
|       "./component/menu_style.js", | ||||
|       "./component/modal_dialog.js", | ||||
|       "./component/radiobox.js", | ||||
|       "./component/radiobox_in_frame.js", | ||||
|       "./component/slider.js", | ||||
|       "./component/tab_horizontal.js", | ||||
|       "./component/tab_vertical.js", | ||||
|       "./component/toggle.js", | ||||
|       "./component/modal_dialog.js", | ||||
|  | ||||
|       "./dom/border.js", | ||||
|       "./dom/color_gallery.js", | ||||
|       "./dom/color_info_palette256.js", | ||||
|       "./dom/color_truecolor_HSV.js", | ||||
|       "./dom/color_truecolor_RGB.js", | ||||
|       "./dom/dbox.js", | ||||
|       "./dom/gauge.js", | ||||
|       "./dom/graph.js", | ||||
| @@ -55,16 +58,12 @@ | ||||
|       "./dom/style_blink.js", | ||||
|       "./dom/style_bold.js", | ||||
|       "./dom/style_color.js", | ||||
|       "./dom/color_truecolor_RGB.js", | ||||
|       "./dom/color_truecolor_HSV.js", | ||||
|       "./dom/color_info_palette256.js", | ||||
|       "./dom/style_dim.js", | ||||
|       "./dom/style_gallery.js", | ||||
|       "./dom/style_inverted.js", | ||||
|       "./dom/style_underlined.js", | ||||
|       "./dom/vbox_hbox.js", | ||||
|       "./dom/window.js", | ||||
|  | ||||
|       "./util/print_key_press.js", | ||||
|     ]; | ||||
|  | ||||
|   | ||||
| @@ -4,16 +4,17 @@ | ||||
|  | ||||
| #include <stddef.h>                                // for size_t | ||||
| #include <algorithm>                               // for max | ||||
| #include <ftxui/component/component.hpp>           // for Component | ||||
| #include <ftxui/component/component.hpp>           // for Make | ||||
| #include <ftxui/component/screen_interactive.hpp>  // for ScreenInteractive | ||||
| #include <string>                                  // for allocator, operator+ | ||||
| #include <utility>                                 // for move | ||||
| #include <vector>                                  // for vector | ||||
| #include <string>  // for allocator, operator+, wstring, char_traits, to_wstring, string | ||||
| #include <utility>  // for move | ||||
| #include <vector>   // for vector | ||||
|  | ||||
| #include "ftxui/component/event.hpp"  // for Event | ||||
| #include "ftxui/component/mouse.hpp"  // for Mouse, Mouse::Left | ||||
| #include "ftxui/dom/elements.hpp"     // for text, vbox, window | ||||
| #include "ftxui/screen/box.hpp"       // for ftxui | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/event.hpp"           // for Event | ||||
| #include "ftxui/component/mouse.hpp"  // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp | ||||
| #include "ftxui/dom/elements.hpp"  // for text, vbox, window, Elements, Element | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| @@ -71,7 +72,7 @@ std::wstring Stringify(Event event) { | ||||
|   return out; | ||||
| } | ||||
|  | ||||
| class DrawKey : public Component { | ||||
| class DrawKey : public ComponentBase { | ||||
|  public: | ||||
|   ~DrawKey() override = default; | ||||
|  | ||||
| @@ -94,6 +95,5 @@ class DrawKey : public Component { | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   DrawKey draw_key; | ||||
|   screen.Loop(&draw_key); | ||||
|   screen.Loop(Make<DrawKey>()); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ArthurSonzogni
					ArthurSonzogni