mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +08:00 
			
		
		
		
	Add CheckBox.
This commit is contained in:
		| @@ -4,9 +4,12 @@ function(example name) | ||||
|   target_link_libraries(${name} PUBLIC component) | ||||
| endfunction(example) | ||||
|  | ||||
| example(gallery) | ||||
| example(input) | ||||
| example(menu) | ||||
| example(menu2) | ||||
| example(menu_style) | ||||
| example(toggle) | ||||
| example(tab) | ||||
| example(tab_horizontal) | ||||
| example(tab_vertical) | ||||
| example(checkbox) | ||||
|   | ||||
							
								
								
									
										31
									
								
								examples/component/checkbox.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								examples/component/checkbox.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| #include "ftxui/component/checkbox.hpp" | ||||
| #include "ftxui/component/component.hpp" | ||||
| #include "ftxui/component/container.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   private: | ||||
|     CheckBox box_1_; | ||||
|     CheckBox box_2_; | ||||
|     CheckBox box_3_; | ||||
|     Container container_ = Container::Vertical(); | ||||
|   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"; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char *argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|   return 0; | ||||
| } | ||||
							
								
								
									
										56
									
								
								examples/component/gallery.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								examples/component/gallery.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| #include "ftxui/component/container.hpp" | ||||
| #include "ftxui/component/input.hpp" | ||||
| #include "ftxui/component/menu.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
| #include "ftxui/component/toggle.hpp" | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   Container container = Container::Vertical(); | ||||
|   Menu menu; | ||||
|   Input input; | ||||
|   Toggle toggle; | ||||
|  | ||||
|  public: | ||||
|   MyComponent() { | ||||
|     Add(&container); | ||||
|     menu.entries = { | ||||
|         L"Browse the web", | ||||
|         L"Meditate", | ||||
|         L"Sleep", | ||||
|         L"Eat", | ||||
|     }; | ||||
|     container.Add(&menu); | ||||
|  | ||||
|     toggle.entries = { | ||||
|         L"Browse the web", | ||||
|         L"Meditate", | ||||
|         L"Sleep", | ||||
|         L"Eat", | ||||
|     }; | ||||
|     container.Add(&toggle); | ||||
|  | ||||
|     input.placeholder = L"Input placeholder"; | ||||
|     container.Add(&input); | ||||
|   } | ||||
|  | ||||
|   Element Render() override { | ||||
|     return | ||||
|       vbox( | ||||
|         hbox(text(L"menu") | size(10,1), separator(), menu.Render()), | ||||
|         separator(), | ||||
|         hbox(text(L"toggle") | size(10,1), separator(), toggle.Render()), | ||||
|         separator(), | ||||
|         hbox(text(L"input") | size(10,1), separator(), input.Render()) | ||||
|       ) | frame; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   screen.Loop(&component); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
| @@ -1,44 +0,0 @@ | ||||
| #include <iostream> | ||||
| #include <thread> | ||||
|  | ||||
| #include "ftxui/component/container.hpp" | ||||
| #include "ftxui/component/menu.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
| #include "ftxui/component/toggle.hpp" | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   public: | ||||
|    MyComponent() { | ||||
|      Add(&container); | ||||
|      container.Add(&toggle); | ||||
|      container.Add(&menu); | ||||
|  | ||||
|      toggle.options = {L" left ", L" middle ", L" end "}; | ||||
|      menu.entries = {L" top ", L" middle ", L" bottom "}; | ||||
|    } | ||||
|  | ||||
|    std::function<void()> on_enter = [](){}; | ||||
|   private: | ||||
|    Container container = Container::Vertical(); | ||||
|    Toggle toggle; | ||||
|    Menu menu; | ||||
|  | ||||
|    Element Render() override { | ||||
|      return | ||||
|        vbox( | ||||
|         hbox(frame(toggle.Render()), filler()), | ||||
|         frame(menu.Render())); | ||||
|    } | ||||
| }; | ||||
|  | ||||
|   | ||||
| int main(int argc, const char *argv[]) | ||||
| { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
| } | ||||
							
								
								
									
										66
									
								
								examples/component/tab_horizontal.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								examples/component/tab_horizontal.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| #include <iostream> | ||||
| #include <thread> | ||||
|  | ||||
| #include "ftxui/component/container.hpp" | ||||
| #include "ftxui/component/menu.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
| #include "ftxui/component/toggle.hpp" | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| class MyComponent : public Component { | ||||
|   public: | ||||
|    MyComponent() { | ||||
|      Add(&container_); | ||||
|      container_.Add(&toggle_); | ||||
|  | ||||
|      toggle_.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 = [](){}; | ||||
|   private: | ||||
|    Toggle toggle_; | ||||
|    Container container_ = Container::Vertical(); | ||||
|    Container tab_container_ = Container::Tab(&(toggle_.selected)); | ||||
|    Menu menu_1_; | ||||
|    Menu menu_2_; | ||||
|    Menu menu_3_; | ||||
| }; | ||||
|  | ||||
|   | ||||
| int main(int argc, const char *argv[]) | ||||
| { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
| } | ||||
							
								
								
									
										66
									
								
								examples/component/tab_vertical.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								examples/component/tab_vertical.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| #include <iostream> | ||||
| #include <thread> | ||||
|  | ||||
| #include "ftxui/component/container.hpp" | ||||
| #include "ftxui/component/menu.hpp" | ||||
| #include "ftxui/component/screen_interactive.hpp" | ||||
| #include "ftxui/component/toggle.hpp" | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| 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 = [](){}; | ||||
|   private: | ||||
|    Menu menu_; | ||||
|    Container container_ = Container::Horizontal(); | ||||
|    Container tab_container_ = Container::Tab(&(menu_.selected)); | ||||
|    Menu menu_1_; | ||||
|    Menu menu_2_; | ||||
|    Menu menu_3_; | ||||
| }; | ||||
|  | ||||
|   | ||||
| int main(int argc, const char *argv[]) | ||||
| { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MyComponent component; | ||||
|   component.on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(&component); | ||||
| } | ||||
| @@ -12,36 +12,36 @@ 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); | ||||
|     Add(&container_); | ||||
|     container_.Add(&toggle_1_); | ||||
|     container_.Add(&toggle_2_); | ||||
|     container_.Add(&toggle_3_); | ||||
|     container_.Add(&toggle_4_); | ||||
|  | ||||
|     toggle_1.options = {L"On", L"Off"}; | ||||
|     toggle_2.options = {L"Enabled", L"Disabled"}; | ||||
|     toggle_3.options = {L"10€", L"0€"}; | ||||
|     toggle_4.options = {L"Nothing", L"One element", L"Several elements"}; | ||||
|     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 = []() {}; | ||||
|  | ||||
|  private: | ||||
|   Container container = Container::Vertical(); | ||||
|   Toggle toggle_1; | ||||
|   Toggle toggle_2; | ||||
|   Toggle toggle_3; | ||||
|   Toggle toggle_4; | ||||
|   Container container_ = Container::Vertical(); | ||||
|   Toggle toggle_1_; | ||||
|   Toggle toggle_2_; | ||||
|   Toggle toggle_3_; | ||||
|   Toggle toggle_4_; | ||||
|  | ||||
|   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()) | ||||
|       ); | ||||
|   } | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Arthur Sonzogni
					Arthur Sonzogni