FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
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#include "ftxui/util/export.hpp" // for FTXUI_EXPORT
12
13namespace ftxui {
14
15/// @brief A class representing the settings for linear-gradient color effect.
16///
17/// Example:
18/// ```cpp
19/// LinearGradient()
20/// .Angle(45)
21/// .Stop(Color::Red, 0.0)
22/// .Stop(Color::Green, 0.5)
23/// .Stop(Color::Blue, 1.0);
24/// ```
25///
26/// There are also shorthand constructors:
27/// ```cpp
28/// LinearGradient(Color::Red, Color::Blue);
29/// LinearGradient(45, Color::Red, Color::Blue);
30/// ```
31///
32/// @ingroup dom
33struct FTXUI_EXPORT(DOM) LinearGradient {
34 float angle = 0.f;
35
36 /// A stop is a color at a specific position in the gradient.
37 /// The position is a value between 0.0 and 1.0,
38 /// where 0.0 is the start of the gradient
39 /// and 1.0 is the end of the gradient.
40 struct Stop {
41 Color color = Color::Default;
42 std::optional<float> position;
43 };
44 std::vector<Stop> stops;
45
46 // Simple constructor
47 LinearGradient();
48 LinearGradient(Color begin, Color end);
49 LinearGradient(float angle, Color begin, Color end);
50
51 // Modifier using the builder pattern.
52 LinearGradient& Angle(float angle);
53 LinearGradient& Stop(Color color, float position);
54 LinearGradient& Stop(Color color);
55};
56
57} // namespace ftxui
58
59#endif // FTXUI_DOM_LINEAR_GRADIENT_HPP
The FTXUI ftxui:: namespace.
Definition animation.hpp:11