mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 01:38:08 +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:
@@ -1,5 +1,7 @@
|
||||
#include "ftxui/screen/color.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo
|
||||
#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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
|
Reference in New Issue
Block a user