FTXUI  5.0.0
C++ functional terminal UI.
linear_gradient.hpp
Go to the documentation of this file.
1 // Copyright 2023 Arthur Sonzogni. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be found in
3 // the LICENSE file.
4 #ifndef FTXUI_DOM_LINEAR_GRADIENT_HPP
5 #define FTXUI_DOM_LINEAR_GRADIENT_HPP
6 
7 #include <optional>
8 #include <vector>
9 
10 #include "ftxui/screen/color.hpp" // for Colors
11 
12 namespace ftxui {
13 
14 /// @brief A class representing the settings for linear-gradient color effect.
15 ///
16 /// Example:
17 /// ```cpp
18 /// LinearGradient()
19 /// .Angle(45)
20 /// .Stop(Color::Red, 0.0)
21 /// .Stop(Color::Green, 0.5)
22 /// .Stop(Color::Blue, 1.0);
23 /// ```
24 ///
25 /// There are also shorthand constructors:
26 /// ```cpp
27 /// LinearGradient(Color::Red, Color::Blue);
28 /// LinearGradient(45, Color::Red, Color::Blue);
29 /// ```
31  float angle = 0.f;
32  struct Stop {
34  std::optional<float> position;
35  };
36  std::vector<Stop> stops;
37 
38  // Simple constructor
40  LinearGradient(Color begin, Color end);
41  LinearGradient(float angle, Color begin, Color end);
42 
43  // Modifier using the builder pattern.
44  LinearGradient& Angle(float angle);
45  LinearGradient& Stop(Color color, float position);
47 };
48 
49 } // namespace ftxui
50 
51 #endif // FTXUI_DOM_LINEAR_GRADIENT_HPP
A class representing terminal colors.
Definition: color.hpp:20
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:110
A class representing the settings for linear-gradient color effect.
LinearGradient & Stop(Color color, float position)
Add a color stop to the gradient.
LinearGradient & Angle(float angle)
Set the angle of the gradient.
std::optional< float > position
LinearGradient()
Build the "empty" gradient. This is often followed by calls to LinearGradient::Angle() and LinearGrad...
std::vector< Stop > stops