mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +08:00 
			
		
		
		
	Introduce Options and use them for Menu.
Introduce Options for components. This allows me to add new features, without updating functions signatures.
This commit is contained in:
		 ArthurSonzogni
					ArthurSonzogni
				
			
				
					committed by
					
						 Arthur Sonzogni
						Arthur Sonzogni
					
				
			
			
				
	
			
			
			 Arthur Sonzogni
						Arthur Sonzogni
					
				
			
						parent
						
							82adc3b410
						
					
				
				
					commit
					cd84b187b3
				
			| @@ -19,8 +19,9 @@ int main(int argc, const char* argv[]) { | ||||
|   }; | ||||
|   int selected = 0; | ||||
|  | ||||
|   auto menu = Menu(&entries, &selected); | ||||
|   MenuBase::From(menu)->on_enter = screen.ExitLoopClosure(); | ||||
|   MenuOption option; | ||||
|   option.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu = Menu(&entries, &selected, &option); | ||||
|  | ||||
|   screen.Loop(menu); | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|  | ||||
|   std::vector<std::wstring> left_menu_entries = { | ||||
|       L"0%",  L"10%", L"20%", L"30%", L"40%", | ||||
| @@ -22,10 +23,16 @@ int main(int argc, const char* argv[]) { | ||||
|       L"0%", L"1%", L"2%", L"3%", L"4%",  L"5%", | ||||
|       L"6%", L"7%", L"8%", L"9%", L"10%", | ||||
|   }; | ||||
|  | ||||
|   auto menu_option = MenuOption(); | ||||
|   menu_option.on_enter = screen.ExitLoopClosure(); | ||||
|  | ||||
|   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 left_menu_ = | ||||
|       Menu(&left_menu_entries, &left_menu_selected, &menu_option); | ||||
|   Component right_menu_ = | ||||
|       Menu(&right_menu_entries, &right_menu_selected, &menu_option); | ||||
|  | ||||
|   Component container = Container::Horizontal({ | ||||
|       left_menu_, | ||||
| @@ -68,9 +75,6 @@ int main(int argc, const char* argv[]) { | ||||
|            border; | ||||
|   }); | ||||
|  | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   MenuBase::From(left_menu_)->on_enter = screen.ExitLoopClosure(); | ||||
|   MenuBase::From(right_menu_)->on_enter = screen.ExitLoopClosure(); | ||||
|   screen.Loop(renderer); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -14,6 +14,8 @@ | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|  | ||||
|   std::vector<std::wstring> entries = { | ||||
|       L"Monkey", L"Dog", L"Cat", L"Bird", L"Elephant", | ||||
|   }; | ||||
| @@ -23,12 +25,51 @@ int main(int argc, const char* argv[]) { | ||||
|   int menu_4_selected_ = 0; | ||||
|   int menu_5_selected_ = 0; | ||||
|   int menu_6_selected_ = 0; | ||||
|   auto menu_1_ = Menu(&entries, &menu_1_selected_); | ||||
|   auto menu_2_ = Menu(&entries, &menu_2_selected_); | ||||
|   auto menu_3_ = Menu(&entries, &menu_3_selected_); | ||||
|   auto menu_4_ = Menu(&entries, &menu_4_selected_); | ||||
|   auto menu_5_ = Menu(&entries, &menu_5_selected_); | ||||
|   auto menu_6_ = Menu(&entries, &menu_6_selected_); | ||||
|  | ||||
|   MenuOption option_1; | ||||
|   option_1.focused_style = bold | color(Color::Blue); | ||||
|   option_1.selected_style = color(Color::Blue); | ||||
|   option_1.selected_focused_style = bold | color(Color::Blue); | ||||
|   option_1.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_1_ = Menu(&entries, &menu_1_selected_, &option_1); | ||||
|  | ||||
|   MenuOption option_2; | ||||
|   option_2.focused_style = bold | color(Color::Blue); | ||||
|   option_2.selected_style = color(Color::Blue); | ||||
|   option_2.selected_focused_style = bold | color(Color::Blue); | ||||
|   option_2.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_2_ = Menu(&entries, &menu_2_selected_, &option_2); | ||||
|  | ||||
|   MenuOption option_3; | ||||
|   option_3.selected_style = color(Color::Blue); | ||||
|   option_3.focused_style = bgcolor(Color::Blue); | ||||
|   option_3.selected_focused_style = bgcolor(Color::Blue); | ||||
|   option_3.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_3_ = Menu(&entries, &menu_3_selected_, &option_3); | ||||
|  | ||||
|   MenuOption option_4; | ||||
|   option_4.selected_style = bgcolor(Color::Blue); | ||||
|   option_4.focused_style = bgcolor(Color::BlueLight); | ||||
|   option_4.selected_focused_style = bgcolor(Color::BlueLight); | ||||
|   option_4.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_4_ = Menu(&entries, &menu_4_selected_, &option_4); | ||||
|  | ||||
|   MenuOption option_5; | ||||
|   option_5.normal_style = bgcolor(Color::Blue); | ||||
|   option_5.selected_style = bgcolor(Color::Yellow); | ||||
|   option_5.focused_style = bgcolor(Color::Red); | ||||
|   option_5.selected_focused_style = bgcolor(Color::Red); | ||||
|   option_5.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_5_ = Menu(&entries, &menu_5_selected_, &option_5); | ||||
|  | ||||
|   MenuOption option_6; | ||||
|   option_6.normal_style = dim | color(Color::Blue); | ||||
|   option_6.selected_style = color(Color::Blue); | ||||
|   option_6.focused_style = bold | color(Color::Blue); | ||||
|   option_6.selected_focused_style = bold | color(Color::Blue); | ||||
|   option_6.on_enter = screen.ExitLoopClosure(); | ||||
|   auto menu_6_ = Menu(&entries, &menu_6_selected_, &option_6); | ||||
|  | ||||
|   auto container = Container::Horizontal({ | ||||
|       menu_1_, | ||||
|       menu_2_, | ||||
| @@ -51,31 +92,6 @@ int main(int argc, const char* argv[]) { | ||||
|       }) | border; | ||||
|   }); | ||||
|   // clang-format on | ||||
|   auto screen = ScreenInteractive::TerminalOutput(); | ||||
|   for (Component menu : {menu_1_, menu_2_, menu_3_, menu_4_, menu_5_, menu_6_}) | ||||
|     MenuBase::From(menu)->on_enter = screen.ExitLoopClosure(); | ||||
|  | ||||
|   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); | ||||
|  | ||||
|   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); | ||||
|  | ||||
|   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); | ||||
|  | ||||
|   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); | ||||
|  | ||||
|   screen.Loop(renderer); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user