mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-23 03:10:01 +08:00
Add an UDL for combined hex RGB colors (#203)
In order to allow using the literal on its own it has been put into the inline namespace `literals`.
This commit is contained in:
parent
b5c3b17b3f
commit
7d4452f45c
@ -28,7 +28,8 @@ int main(int argc, const char* argv[]) {
|
|||||||
color(Color::Red, text("Red")),
|
color(Color::Red, text("Red")),
|
||||||
color(Color::RedLight, text("RedLight")),
|
color(Color::RedLight, text("RedLight")),
|
||||||
color(Color::Yellow, text("Yellow")),
|
color(Color::Yellow, text("Yellow")),
|
||||||
color(Color::YellowLight, text("YellowLight"))
|
color(Color::YellowLight, text("YellowLight")),
|
||||||
|
color(0x66ff66_rgb, text("Phosphor"))
|
||||||
),
|
),
|
||||||
vbox(
|
vbox(
|
||||||
bgcolor(Color::Default, text("Default")),
|
bgcolor(Color::Default, text("Default")),
|
||||||
@ -47,7 +48,8 @@ int main(int argc, const char* argv[]) {
|
|||||||
bgcolor(Color::Red, text("Red")),
|
bgcolor(Color::Red, text("Red")),
|
||||||
bgcolor(Color::RedLight, text("RedLight")),
|
bgcolor(Color::RedLight, text("RedLight")),
|
||||||
bgcolor(Color::Yellow, text("Yellow")),
|
bgcolor(Color::Yellow, text("Yellow")),
|
||||||
bgcolor(Color::YellowLight, text("YellowLight"))
|
bgcolor(Color::YellowLight, text("YellowLight")),
|
||||||
|
bgcolor(0x66ff66_rgb, text("Phosphor"))
|
||||||
),
|
),
|
||||||
filler()
|
filler()
|
||||||
);
|
);
|
||||||
|
@ -322,6 +322,14 @@ class Color {
|
|||||||
uint8_t blue_ = 0;
|
uint8_t blue_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline namespace literals {
|
||||||
|
|
||||||
|
/// @brief Creates a color from a combined hex RGB representation,
|
||||||
|
/// e.g. 0x808000_rgb
|
||||||
|
Color operator""_rgb(unsigned long long int combined);
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
|
||||||
#endif /* end of include guard: FTXUI_COLOR_H_ */
|
#endif /* end of include guard: FTXUI_COLOR_H_ */
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "ftxui/screen/color.hpp"
|
#include "ftxui/screen/color.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
||||||
#include "ftxui/screen/terminal.hpp" // for Terminal, Terminal::Color, Terminal::Palette256, Terminal::TrueColor
|
#include "ftxui/screen/terminal.hpp" // for Terminal, Terminal::Color, Terminal::Palette256, Terminal::TrueColor
|
||||||
|
|
||||||
@ -143,6 +145,18 @@ Color Color::HSV(uint8_t h, uint8_t s, uint8_t v) {
|
|||||||
return Color(0, 0, 0);
|
return Color(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline namespace literals {
|
||||||
|
|
||||||
|
Color operator""_rgb(unsigned long long int combined) {
|
||||||
|
assert(combined <= 0xffffffU);
|
||||||
|
auto const red = static_cast<uint8_t>(combined >> 16);
|
||||||
|
auto const green = static_cast<uint8_t>(combined >> 8);
|
||||||
|
auto const blue = static_cast<uint8_t>(combined);
|
||||||
|
return Color(red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
|
||||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
|
Loading…
Reference in New Issue
Block a user