Add more example for colors.

This commit is contained in:
ArthurSonzogni
2020-09-06 13:43:24 +02:00
committed by Arthur Sonzogni
parent dc8c090753
commit d09996a6c7
8 changed files with 454 additions and 265 deletions

View File

@@ -10,8 +10,22 @@ namespace ftxui {
/// @ingroup screen
class Color {
public:
enum Palette16 : uint8_t;
enum Palette256: uint8_t;
Color(); // Transparent.
Color(Palette16 index); // Implicit conversion from index to Color.
Color(Palette256 index); // Implicit conversion from index to Color.
Color(uint8_t red, uint8_t green, uint8_t blue);
static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
//---------------------------
// List of colors:
//---------------------------
// clang-format off
enum Palette16 {
enum Palette16 : uint8_t {
Black = 30,
Blue = 34,
BlueLight = 94,
@@ -31,7 +45,7 @@ class Color {
YellowLight = 93,
};
enum Palette256 {
enum Palette256 : uint8_t {
Aquamarine1 = 122,
Aquamarine1Bis = 86,
Aquamarine3 = 79,
@@ -275,14 +289,6 @@ class Color {
};
// clang-format on
public:
Color(); // Transparent.
Color(Palette256 index); // Implicit conversion from index to Color.
Color(Palette16 index); // Implicit conversion from index to Color.
Color(uint8_t red, uint8_t green, uint8_t blue);
static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
// --- Operators ------
bool operator==(const Color& rhs) const;
bool operator!=(const Color& rhs) const;

View File

@@ -0,0 +1,23 @@
#ifndef FTXUI_SCREEN_COLOR_INFO_HPP
#define FTXUI_SCREEN_COLOR_INFO_HPP
#include <ftxui/screen/color.hpp>
namespace ftxui {
struct ColorInfo {
const char* name;
uint8_t index;
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t hue;
uint8_t saturation;
uint8_t value;
};
ColorInfo GetColorInfo(Color::Palette256 index);
} // namespace ftxui
#endif /* end of include guard: FTXUI_SCREEN_COLOR_INFO_HPP */