mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 02:28:11 +08:00 
			
		
		
		
	Add support for full RGB colors.
FTXUI supported only the 16 colors palette. This patch adds support for the 256 palette and the TrueColor(8×8×8) mode. This was made by kerdelos@ and fixes issue: https://github.com/ArthurSonzogni/FTXUI/issues/45 Co-authored-by: Damien D <kerdelos@gmail.com> Co-authored-by: Arthur Sonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
		 Damien D
					Damien D
				
			
				
					committed by
					
						 Arthur Sonzogni
						Arthur Sonzogni
					
				
			
			
				
	
			
			
			 Arthur Sonzogni
						Arthur Sonzogni
					
				
			
						parent
						
							49941b6403
						
					
				
				
					commit
					dc8c090753
				
			| @@ -4,23 +4,26 @@ function(example name) | ||||
|   set_property(TARGET ${name} PROPERTY CXX_STANDARD 17) | ||||
| endfunction(example) | ||||
|  | ||||
| example(dbox) | ||||
| example(border) | ||||
| example(color_gallery) | ||||
| example(dbox) | ||||
| example(gauge) | ||||
| example(package_manager) | ||||
| example(separator) | ||||
| example(graph) | ||||
| example(hflow) | ||||
| example(html_like) | ||||
| example(package_manager) | ||||
| example(paragraph) | ||||
| example(separator) | ||||
| example(size) | ||||
| example(spinner) | ||||
| example(style_blink) | ||||
| example(style_bold) | ||||
| example(style_color) | ||||
| example(color_truecolor_RGB) | ||||
| example(color_truecolor_HSV) | ||||
| example(style_dim) | ||||
| example(style_gallery) | ||||
| example(style_inverted) | ||||
| example(style_underlined) | ||||
| example(size) | ||||
| example(vbox_hbox) | ||||
| example(hflow) | ||||
| example(paragraph) | ||||
| example(html_like) | ||||
| example(window) | ||||
|   | ||||
							
								
								
									
										109
									
								
								examples/dom/color_gallery.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								examples/dom/color_gallery.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,109 @@ | ||||
| // 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 <ftxui/dom/elements.hpp> | ||||
| #include <ftxui/screen/screen.hpp> | ||||
| #include <ftxui/screen/terminal.hpp> | ||||
| #include <iostream> | ||||
|  | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|   // clang-format off | ||||
|   auto terminal_info = | ||||
|     vbox( | ||||
|       text(L"Basic Color support : unknown"), | ||||
|       text(L"256 Color support : unknown"), | ||||
|       (Terminal::CanSupportTrueColors() ? | ||||
|         text(L"TrueColor support : Yes"): | ||||
|         text(L"TrueColor support : No")) | ||||
|     ); | ||||
|  | ||||
|   auto basic_color_display = | ||||
|     vbox( | ||||
|       text(L"Basic Color Set:"), | ||||
|       hbox( | ||||
|         vbox( | ||||
|           color(Color::Default, text(L"Default")), | ||||
|           color(Color::Black, text(L"Black")), | ||||
|           color(Color::GrayDark, text(L"GrayDark")), | ||||
|           color(Color::GrayLight, text(L"GrayLight")), | ||||
|           color(Color::White, text(L"White")), | ||||
|           color(Color::Blue, text(L"Blue")), | ||||
|           color(Color::BlueLight, text(L"BlueLight")), | ||||
|           color(Color::Cyan, text(L"Cyan")), | ||||
|           color(Color::CyanLight, text(L"CyanLight")), | ||||
|           color(Color::Green, text(L"Green")), | ||||
|           color(Color::GreenLight, text(L"GreenLight")), | ||||
|           color(Color::Magenta, text(L"Magenta")), | ||||
|           color(Color::MagentaLight, text(L"MagentaLight")), | ||||
|           color(Color::Red, text(L"Red")), | ||||
|           color(Color::RedLight, text(L"RedLight")), | ||||
|           color(Color::Yellow, text(L"Yellow")), | ||||
|           color(Color::YellowLight, text(L"YellowLight")) | ||||
|         ), | ||||
|         vbox( | ||||
|           bgcolor(Color::Default, text(L"Default")), | ||||
|           bgcolor(Color::Black, text(L"Black")), | ||||
|           bgcolor(Color::GrayDark, text(L"GrayDark")), | ||||
|           bgcolor(Color::GrayLight, text(L"GrayLight")), | ||||
|           bgcolor(Color::White, text(L"White")), | ||||
|           bgcolor(Color::Blue, text(L"Blue")), | ||||
|           bgcolor(Color::BlueLight, text(L"BlueLight")), | ||||
|           bgcolor(Color::Cyan, text(L"Cyan")), | ||||
|           bgcolor(Color::CyanLight, text(L"CyanLight")), | ||||
|           bgcolor(Color::Green, text(L"Green")), | ||||
|           bgcolor(Color::GreenLight, text(L"GreenLight")), | ||||
|           bgcolor(Color::Magenta, text(L"Magenta")), | ||||
|           bgcolor(Color::MagentaLight, text(L"MagentaLight")), | ||||
|           bgcolor(Color::Red, text(L"Red")), | ||||
|           bgcolor(Color::RedLight, text(L"RedLight")), | ||||
|           bgcolor(Color::Yellow, text(L"Yellow")), | ||||
|           bgcolor(Color::YellowLight, text(L"YellowLight")) | ||||
|         ) | ||||
|       ) | ||||
|     ); | ||||
|  | ||||
|   // clang-format on | ||||
|   auto palette_256_color_display = vbox(text(L"256 color palette:")); | ||||
|  | ||||
|   int y = -1; | ||||
|   for (int i = 0; i < 256; ++i) { | ||||
|     if (i % 16 == 0) { | ||||
|       palette_256_color_display->children.push_back(hbox()); | ||||
|       ++y; | ||||
|     } | ||||
|     std::string number = std::to_string(i); | ||||
|     while (number.length() < 4) { | ||||
|       number.push_back(' '); | ||||
|     } | ||||
|     palette_256_color_display->children.back()->children.push_back( | ||||
|         bgcolor(Color::Palette256(i), text(to_wstring(number)))); | ||||
|   } | ||||
|  | ||||
|   auto true_color_display = vbox(text(L"a true color grandient:")); | ||||
|  | ||||
|   for (int i = 0; i < 17; ++i) { | ||||
|     true_color_display->children.push_back(hbox()); | ||||
|  | ||||
|     for (int j = 0; j < 30; ++j) { | ||||
|       true_color_display->children.back()->children.push_back( | ||||
|           bgcolor(Color(50 + i * 5, 100 + j, 150), text(L" "))); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   auto document = | ||||
|       vbox(terminal_info, text(L""), | ||||
|            hbox(basic_color_display, text(L"  "), palette_256_color_display, | ||||
|                 text(L" "), true_color_display)); | ||||
|   // clang-format on | ||||
|  | ||||
|   auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); | ||||
|   Render(screen, document); | ||||
|  | ||||
|   std::cout << screen.ToString(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
							
								
								
									
										32
									
								
								examples/dom/color_truecolor_HSV.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								examples/dom/color_truecolor_HSV.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| // 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 <ftxui/dom/elements.hpp> | ||||
| #include <ftxui/screen/screen.hpp> | ||||
| #include <ftxui/screen/terminal.hpp> | ||||
| #include <iostream> | ||||
|  | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|  | ||||
|   int saturation = 255; | ||||
|   Elements array; | ||||
|   for (int value = 0; value < 255; value += 10) { | ||||
|     Elements line; | ||||
|     for (int hue = 0; hue < 255; hue += 2) | ||||
|       line.push_back(text(L" ") | bgcolor(Color::HSV(hue, saturation, value))); | ||||
|     array.push_back(hbox(std::move(line))); | ||||
|   } | ||||
|  | ||||
|   auto document = vbox(std::move(array)); | ||||
|  | ||||
|   auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); | ||||
|   Render(screen, document); | ||||
|  | ||||
|   std::cout << screen.ToString(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
							
								
								
									
										55
									
								
								examples/dom/color_truecolor_RGB.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								examples/dom/color_truecolor_RGB.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| // 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 <cmath> | ||||
| #include <ftxui/dom/elements.hpp> | ||||
| #include <ftxui/screen/screen.hpp> | ||||
| #include <ftxui/screen/terminal.hpp> | ||||
| #include <iostream> | ||||
|  | ||||
| #include "ftxui/screen/string.hpp" | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|  | ||||
|   int saturation = 255; | ||||
|   Elements red_line; | ||||
|   Elements green_line; | ||||
|   Elements blue_line; | ||||
|   Elements cyan_line; | ||||
|   Elements magenta_line; | ||||
|   Elements yellow_line; | ||||
|  | ||||
|   for (int value = 0; value < 255; value += 3) { | ||||
|     int v = value * value / 255; | ||||
|     red_line.push_back(text(L" ") | bgcolor(Color::RGB(v, 0, 0))); | ||||
|     green_line.push_back(text(L" ") | bgcolor(Color::RGB(0, v, 0))); | ||||
|     blue_line.push_back(text(L" ") | bgcolor(Color::RGB(0, 0, v))); | ||||
|     cyan_line.push_back(text(L" ") | bgcolor(Color::RGB(0, v, v))); | ||||
|     magenta_line.push_back(text(L" ") | bgcolor(Color::RGB(v, 0, v))); | ||||
|     yellow_line.push_back(text(L" ") | bgcolor(Color::RGB(v, v, 0))); | ||||
|   } | ||||
|  | ||||
|   auto document = vbox({ | ||||
|       window(text(L"Primary colors"), | ||||
|              vbox({ | ||||
|                  hbox({text(L"Red line    :"), hbox(std::move(red_line))}), | ||||
|                  hbox({text(L"Green line  :"), hbox(std::move(green_line))}), | ||||
|                  hbox({text(L"Blue line   :"), hbox(std::move(blue_line))}), | ||||
|              })), | ||||
|       window(text(L"Secondary colors"), | ||||
|              vbox({ | ||||
|                  hbox({text(L"cyan line   :"), hbox(std::move(cyan_line))}), | ||||
|                  hbox({text(L"magenta line:"), hbox(std::move(magenta_line))}), | ||||
|                  hbox({text(L"Yellow line :"), hbox(std::move(yellow_line))}), | ||||
|              })), | ||||
|   }); | ||||
|  | ||||
|   auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); | ||||
|   Render(screen, document); | ||||
|  | ||||
|   std::cout << screen.ToString(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user