mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 02:28:11 +08:00 
			
		
		
		
	Feature: Selection
Add support for selection content in the dom.
This commit is contained in:
		| @@ -38,6 +38,7 @@ example(radiobox) | ||||
| example(radiobox_in_frame) | ||||
| example(renderer) | ||||
| example(resizable_split) | ||||
| example(selection) | ||||
| example(scrollbar) | ||||
| example(slider) | ||||
| example(slider_direction) | ||||
|   | ||||
| @@ -97,7 +97,25 @@ int main() { | ||||
|   }); | ||||
|   sliders = Wrap("Slider", sliders); | ||||
|  | ||||
|   // -- Layout ----------------------------------------------------------------- | ||||
|   // A large text: | ||||
|   auto lorel_ipsum = Renderer([] { | ||||
|     return vbox({ | ||||
|         text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "), | ||||
|         text("Sed do eiusmod tempor incididunt ut labore et dolore magna " | ||||
|              "aliqua. "), | ||||
|         text("Ut enim ad minim veniam, quis nostrud exercitation ullamco " | ||||
|              "laboris nisi ut aliquip ex ea commodo consequat. "), | ||||
|         text("Duis aute irure dolor in reprehenderit in voluptate velit esse " | ||||
|              "cillum dolore eu fugiat nulla pariatur. "), | ||||
|         text("Excepteur sint occaecat cupidatat non proident, sunt in culpa " | ||||
|              "qui officia deserunt mollit anim id est laborum. "), | ||||
|  | ||||
|     }); | ||||
|   }); | ||||
|   lorel_ipsum = Wrap("Lorel Ipsum", lorel_ipsum); | ||||
|  | ||||
|   // -- Layout | ||||
|   // ----------------------------------------------------------------- | ||||
|   auto layout = Container::Vertical({ | ||||
|       menu, | ||||
|       toggle, | ||||
| @@ -106,6 +124,7 @@ int main() { | ||||
|       input, | ||||
|       sliders, | ||||
|       button, | ||||
|       lorel_ipsum, | ||||
|   }); | ||||
|  | ||||
|   auto component = Renderer(layout, [&] { | ||||
| @@ -123,6 +142,8 @@ int main() { | ||||
|                sliders->Render(), | ||||
|                separator(), | ||||
|                button->Render(), | ||||
|                separator(), | ||||
|                lorel_ipsum->Render(), | ||||
|            }) | | ||||
|            xflex | size(WIDTH, GREATER_THAN, 40) | border; | ||||
|   }); | ||||
|   | ||||
| @@ -424,7 +424,7 @@ int main() { | ||||
|   auto paragraph_renderer_left = Renderer([&] { | ||||
|     std::string str = | ||||
|         "Lorem Ipsum is simply dummy text of the printing and typesetting " | ||||
|         "industry. Lorem Ipsum has been the industry's standard dummy text " | ||||
|         "industry.\nLorem Ipsum has been the industry's standard dummy text " | ||||
|         "ever since the 1500s, when an unknown printer took a galley of type " | ||||
|         "and scrambled it to make a type specimen book."; | ||||
|     return vbox({ | ||||
|   | ||||
							
								
								
									
										87
									
								
								examples/component/selection.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								examples/component/selection.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| // Copyright 2020 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 <string>  // for char_traits, operator+, string, basic_string | ||||
|  | ||||
| #include "ftxui/component/component.hpp"       // for Input, Renderer, Vertical | ||||
| #include "ftxui/component/component_base.hpp"  // for ComponentBase | ||||
| #include "ftxui/component/component_options.hpp"  // for InputOption | ||||
| #include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive | ||||
| #include "ftxui/dom/elements.hpp"  // for text, hbox, separator, Element, operator|, vbox, border | ||||
| #include "ftxui/util/ref.hpp"  // for Ref | ||||
|  | ||||
| using namespace ftxui; | ||||
|  | ||||
| Element LoremIpsum() { | ||||
|   return vbox({ | ||||
|       text("FTXUI: A powerful library for building user interfaces."), | ||||
|       text("Enjoy a rich set of components and a declarative style."), | ||||
|       text("Create beautiful and responsive UIs with minimal effort."), | ||||
|       text("Join the community and experience the power of FTXUI."), | ||||
|   }); | ||||
| } | ||||
|  | ||||
| int main() { | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|  | ||||
|   auto quit = | ||||
|       Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated()); | ||||
|  | ||||
|   int selection_change_counter = 0; | ||||
|   std::string selection_content = ""; | ||||
|   screen.SelectionChange([&] { | ||||
|     selection_change_counter++; | ||||
|     selection_content = screen.GetSelection(); | ||||
|   }); | ||||
|  | ||||
|   // The components: | ||||
|   auto renderer = Renderer(quit, [&] { | ||||
|     return vbox({ | ||||
|         text("Select changed: " + std::to_string(selection_change_counter) + | ||||
|              " times"), | ||||
|         text("Currently selected: "), | ||||
|         paragraph(selection_content) | vscroll_indicator | frame | border | | ||||
|             size(HEIGHT, EQUAL, 10), | ||||
|         window(text("Horizontal split"), hbox({ | ||||
|                                              LoremIpsum(), | ||||
|                                              separator(), | ||||
|                                              LoremIpsum(), | ||||
|                                              separator(), | ||||
|                                              LoremIpsum(), | ||||
|                                          })), | ||||
|         window(text("Vertical split"), vbox({ | ||||
|                                            LoremIpsum(), | ||||
|                                            separator(), | ||||
|                                            LoremIpsum(), | ||||
|                                            separator(), | ||||
|                                            LoremIpsum(), | ||||
|                                        })), | ||||
|         window(text("Grid split with different style"), | ||||
|                vbox({ | ||||
|                    hbox({ | ||||
|                        LoremIpsum(), | ||||
|                        separator(), | ||||
|                        LoremIpsum()                                   // | ||||
|                            | selectionBackgroundColor(Color::Yellow)  // | ||||
|                            | selectionColor(Color::Black)             // | ||||
|                            | selectionStyleReset, | ||||
|                        separator(), | ||||
|                        LoremIpsum() | selectionColor(Color::Blue), | ||||
|                    }), | ||||
|                    separator(), | ||||
|                    hbox({ | ||||
|                        LoremIpsum() | selectionColor(Color::Red), | ||||
|                        separator(), | ||||
|                        LoremIpsum() | selectionStyle([](Pixel& pixel) { | ||||
|                          pixel.underlined_double = true; | ||||
|                        }), | ||||
|                        separator(), | ||||
|                        LoremIpsum(), | ||||
|                    }), | ||||
|                })), | ||||
|         quit->Render(), | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   screen.Loop(renderer); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Clément Roblot
					Clément Roblot