mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +08:00 
			
		
		
		
	Merge dom and component focus (#978)
Instead of two levels of focus with `focus` and `selected`, use a recursive level. The components set the one "active" and hbox/vbox/dbox Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
		| @@ -18,6 +18,7 @@ example(focus_cursor) | ||||
| example(gallery) | ||||
| example(homescreen) | ||||
| example(input) | ||||
| example(input_in_frame) | ||||
| example(input_style) | ||||
| example(linear_gradient_gallery) | ||||
| example(maybe) | ||||
| @@ -38,8 +39,8 @@ example(radiobox) | ||||
| example(radiobox_in_frame) | ||||
| example(renderer) | ||||
| example(resizable_split) | ||||
| example(selection) | ||||
| example(scrollbar) | ||||
| example(selection) | ||||
| example(slider) | ||||
| example(slider_direction) | ||||
| example(slider_rgb) | ||||
|   | ||||
| @@ -1,30 +1,38 @@ | ||||
| // Copyright 2021 Arthur Sonzogni. All rights reserved. | ||||
| // Use of this source code is governed by the MIT license that can be found in | ||||
| // the LICENSE file. | ||||
| #include <memory>  // for allocator, __shared_ptr_access | ||||
| #include <string>  // for string, basic_string, operator+, to_string | ||||
| #include <vector>  // for vector | ||||
| #include <array>  // for array | ||||
| #include <iostream> | ||||
| #include <memory>  // for shared_ptr, __shared_ptr_access | ||||
| #include <string>  // for operator+, to_string | ||||
|  | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Input, Renderer, Vertical | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/component/component.hpp"  // for Checkbox, Renderer, Vertical | ||||
| #include "ftxui/component/component_base.hpp"      // for ComponentBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| int main() { | ||||
|   using namespace ftxui; | ||||
|   bool download = false; | ||||
|   bool upload = false; | ||||
|   bool ping = false; | ||||
|  | ||||
|   Component input_list = Container::Vertical({}); | ||||
|   std::vector<std::string> items(100, ""); | ||||
|   for (size_t i = 0; i < items.size(); ++i) { | ||||
|     input_list->Add(Input(&(items[i]), "placeholder " + std::to_string(i))); | ||||
|   } | ||||
|  | ||||
|   auto renderer = Renderer(input_list, [&] { | ||||
|     return input_list->Render() | vscroll_indicator | frame | border | | ||||
|            size(HEIGHT, LESS_THAN, 10); | ||||
|   auto container = Container::Vertical({ | ||||
|       Checkbox("Download", &download), | ||||
|       Checkbox("Upload", &upload), | ||||
|       Checkbox("Ping", &ping), | ||||
|   }); | ||||
|  | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   screen.Loop(renderer); | ||||
|   auto screen = ScreenInteractive::FitComponent(); | ||||
|   screen.Loop(container); | ||||
|  | ||||
|   std::cout << "---" << std::endl; | ||||
|   std::cout << "Download: " << download << std::endl; | ||||
|   std::cout << "Upload: " << upload << std::endl; | ||||
|   std::cout << "Ping: " << ping << std::endl; | ||||
|   std::cout << "---" << std::endl; | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
							
								
								
									
										30
									
								
								examples/component/input_in_frame.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								examples/component/input_in_frame.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| // Copyright 2021 Arthur Sonzogni. All rights reserved. | ||||
| // Use of this source code is governed by the MIT license that can be found in | ||||
| // the LICENSE file. | ||||
| #include <memory>  // for allocator, __shared_ptr_access | ||||
| #include <string>  // for string, basic_string, operator+, to_string | ||||
| #include <vector>  // for vector | ||||
|  | ||||
| #include "ftxui/component/captured_mouse.hpp"  // for ftxui | ||||
| #include "ftxui/component/component.hpp"       // for Input, Renderer, Vertical | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for operator|, Element, size, border, frame, vscroll_indicator, HEIGHT, LESS_THAN | ||||
|  | ||||
| int main() { | ||||
|   using namespace ftxui; | ||||
|  | ||||
|   Component input_list = Container::Vertical({}); | ||||
|   std::vector<std::string> items(100, ""); | ||||
|   for (size_t i = 0; i < items.size(); ++i) { | ||||
|     input_list->Add(Input(&(items[i]), "placeholder " + std::to_string(i))); | ||||
|   } | ||||
|  | ||||
|   auto renderer = Renderer(input_list, [&] { | ||||
|     return input_list->Render() | vscroll_indicator | frame | border | | ||||
|            size(HEIGHT, LESS_THAN, 10); | ||||
|   }); | ||||
|  | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   screen.Loop(renderer); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Ayaan
					Ayaan