| 
									
										
										
										
											2023-08-19 13:56:36 +02:00
										 |  |  | // Copyright 2023 Arthur Sonzogni. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be found in
 | 
					
						
							|  |  |  | // the LICENSE file.
 | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  | #ifndef FTXUI_DOM_LINEAR_GRADIENT_HPP
 | 
					
						
							|  |  |  | #define FTXUI_DOM_LINEAR_GRADIENT_HPP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <optional>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ftxui/screen/color.hpp"  // for Colors
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace ftxui { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// @brief A class representing the settings for linear-gradient color effect.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// Example:
 | 
					
						
							|  |  |  | /// ```cpp
 | 
					
						
							|  |  |  | /// LinearGradient()
 | 
					
						
							|  |  |  | ///    .Angle(45)
 | 
					
						
							|  |  |  | ///    .Stop(Color::Red, 0.0)
 | 
					
						
							|  |  |  | ///    .Stop(Color::Green, 0.5)
 | 
					
						
							|  |  |  | ///    .Stop(Color::Blue, 1.0);
 | 
					
						
							|  |  |  | /// ```
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// There are also shorthand constructors:
 | 
					
						
							|  |  |  | /// ```cpp
 | 
					
						
							|  |  |  | /// LinearGradient(Color::Red, Color::Blue);
 | 
					
						
							|  |  |  | /// LinearGradient(45, Color::Red, Color::Blue);
 | 
					
						
							|  |  |  | /// ```
 | 
					
						
							| 
									
										
										
										
											2025-06-05 11:35:14 +02:00
										 |  |  | ///
 | 
					
						
							|  |  |  | /// @ingroup dom
 | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  | struct LinearGradient { | 
					
						
							|  |  |  |   float angle = 0.f; | 
					
						
							| 
									
										
										
										
											2025-06-05 11:35:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// A stop is a color at a specific position in the gradient.
 | 
					
						
							|  |  |  |   /// The position is a value between 0.0 and 1.0,
 | 
					
						
							|  |  |  |   /// where 0.0 is the start of the gradient
 | 
					
						
							|  |  |  |   /// and 1.0 is the end of the gradient.
 | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  |   struct Stop { | 
					
						
							|  |  |  |     Color color = Color::Default; | 
					
						
							|  |  |  |     std::optional<float> position; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   std::vector<Stop> stops; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Simple constructor
 | 
					
						
							|  |  |  |   LinearGradient(); | 
					
						
							|  |  |  |   LinearGradient(Color begin, Color end); | 
					
						
							|  |  |  |   LinearGradient(float angle, Color begin, Color end); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Modifier using the builder pattern.
 | 
					
						
							|  |  |  |   LinearGradient& Angle(float angle); | 
					
						
							|  |  |  |   LinearGradient& Stop(Color color, float position); | 
					
						
							|  |  |  |   LinearGradient& Stop(Color color); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace ftxui
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // FTXUI_DOM_LINEAR_GRADIENT_HPP
 |