Cleanup. (IWYU, clang-tidy, etc...)

This commit is contained in:
ArthurSonzogni 2023-08-13 07:49:37 +02:00
parent 06ba1c10b9
commit 8058e1af6c
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
6 changed files with 1029 additions and 1018 deletions

View File

@ -88,8 +88,6 @@ class ConstStringRef : public ConstRef<std::string> {
ConstStringRef(const wchar_t* ref) ConstStringRef(const wchar_t* ref)
: ConstStringRef(to_string(std::wstring(ref))) {} : ConstStringRef(to_string(std::wstring(ref))) {}
ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {} ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {}
ConstStringRef& operator=(const ConstStringRef&) = default;
}; };
/// @brief An adapter. Reference a list of strings. /// @brief An adapter. Reference a list of strings.
@ -98,6 +96,8 @@ class ConstStringListRef {
ConstStringListRef() = default; ConstStringListRef() = default;
ConstStringListRef(const std::vector<std::string>* ref) : ref_(ref) {} ConstStringListRef(const std::vector<std::string>* ref) : ref_(ref) {}
ConstStringListRef(const std::vector<std::wstring>* ref) : ref_wide_(ref) {} ConstStringListRef(const std::vector<std::wstring>* ref) : ref_wide_(ref) {}
ConstStringListRef(const ConstStringListRef& other) = default;
ConstStringListRef& operator=(const ConstStringListRef& other) = default;
size_t size() const { size_t size() const {
if (ref_) { if (ref_) {

View File

@ -95,7 +95,7 @@ MenuEntryOption GeneratorMenuEntryOption(const char* data, size_t size) {
MenuOption GeneratorMenuOption(const char* data, size_t size) { MenuOption GeneratorMenuOption(const char* data, size_t size) {
MenuOption option; MenuOption option;
option.underline = GeneratorUnderlineOption(data, size); option.underline = GeneratorUnderlineOption(data, size);
option.entries = GeneratorMenuEntryOption(data, size); option.entries_option = GeneratorMenuEntryOption(data, size);
option.direction = static_cast<Direction>(GeneratorInt(data, size) % 4); option.direction = static_cast<Direction>(GeneratorInt(data, size) % 4);
return option; return option;
} }

View File

@ -205,7 +205,8 @@ class SliderBase : public ComponentBase {
class SliderWithLabel : public ComponentBase { class SliderWithLabel : public ComponentBase {
public: public:
SliderWithLabel(ConstStringRef label, Component inner) : label_(label) { SliderWithLabel(ConstStringRef label, Component inner)
: label_(std::move(label)) {
Add(std::move(inner)); Add(std::move(inner));
SetActiveChild(ChildAt(0)); SetActiveChild(ChildAt(0));
} }

View File

@ -17,7 +17,7 @@ namespace ftxui {
namespace { namespace {
struct LinearGradientNormalized { struct LinearGradientNormalized {
float angle = 0.f; float angle = 0.F;
std::vector<Color> colors; std::vector<Color> colors;
std::vector<float> positions; // Sorted. std::vector<float> positions; // Sorted.
}; };
@ -27,15 +27,18 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
// Handle gradient of size 0. // Handle gradient of size 0.
if (gradient.stops.empty()) { if (gradient.stops.empty()) {
return LinearGradientNormalized{ return LinearGradientNormalized{
0.f, {Color::Default, Color::Default}, {0.f, 1.f}}; 0.F,
{Color::Default, Color::Default},
{0.F, 1.F},
};
} }
// Fill in the two extent, if not provided. // Fill in the two extent, if not provided.
if (!gradient.stops.front().position) { if (!gradient.stops.front().position) {
gradient.stops.front().position = 0.f; gradient.stops.front().position = 0.F;
} }
if (!gradient.stops.back().position) { if (!gradient.stops.back().position) {
gradient.stops.back().position = 1.f; gradient.stops.back().position = 1.F;
} }
// Fill in the blank, by interpolating positions. // Fill in the blank, by interpolating positions.
@ -67,20 +70,22 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
// If we don't being with zero, add a stop at zero. // If we don't being with zero, add a stop at zero.
if (gradient.stops.front().position != 0) { if (gradient.stops.front().position != 0) {
gradient.stops.insert(gradient.stops.begin(), gradient.stops.insert(gradient.stops.begin(),
{gradient.stops.front().color, 0.f}); {gradient.stops.front().color, 0.F});
} }
// If we don't end with one, add a stop at one. // If we don't end with one, add a stop at one.
if (gradient.stops.back().position != 1) { if (gradient.stops.back().position != 1) {
gradient.stops.push_back({gradient.stops.back().color, 1.f}); gradient.stops.push_back({gradient.stops.back().color, 1.F});
} }
// Normalize the angle. // Normalize the angle.
LinearGradientNormalized normalized; LinearGradientNormalized normalized;
// NOLINTNEXTLINE const float modulo = 360.F;
normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f); normalized.angle =
for (const auto& stop : gradient.stops) { std::fmod(std::fmod(gradient.angle, modulo) + modulo, modulo);
for (auto& stop : gradient.stops) {
normalized.colors.push_back(stop.color); normalized.colors.push_back(stop.color);
normalized.positions.push_back(stop.position.value()); // NOLINT // NOLINTNEXTLINE
normalized.positions.push_back(stop.position.value());
} }
return normalized; return normalized;
} }
@ -90,8 +95,8 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) {
size_t i = 1; size_t i = 1;
while (true) { while (true) {
if (i > gradient.positions.size()) { if (i > gradient.positions.size()) {
// NOLINTNEXTLINE const float half = 0.5F;
return Color::Interpolate(0.5f, gradient.colors.back(), return Color::Interpolate(half, gradient.colors.back(),
gradient.colors.back()); gradient.colors.back());
} }
if (t <= gradient.positions[i]) { if (t <= gradient.positions[i]) {
@ -122,7 +127,7 @@ class LinearGradientColor : public NodeDecorator {
private: private:
void Render(Screen& screen) override { void Render(Screen& screen) override {
const float degtorad = 0.01745329251f; const float degtorad = 0.01745329251F;
const float dx = std::cos(gradient_.angle * degtorad); const float dx = std::cos(gradient_.angle * degtorad);
const float dy = std::sin(gradient_.angle * degtorad); const float dy = std::sin(gradient_.angle * degtorad);

View File

@ -224,11 +224,17 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) {
// Gamma correction: // Gamma correction:
// https://en.wikipedia.org/wiki/Gamma_correction // https://en.wikipedia.org/wiki/Gamma_correction
constexpr float gamma = 2.2f; auto interp = [](uint8_t a, uint8_t b, float t) {
return Color::RGB( constexpr float gamma = 2.2F;
uint8_t(pow(pow(a_r, gamma) * (1 - t) + pow(b_r, gamma) * t, 1 / gamma)), const float a_f = powf(a, gamma);
uint8_t(pow(pow(a_g, gamma) * (1 - t) + pow(b_g, gamma) * t, 1 / gamma)), const float b_f = powf(b, gamma);
uint8_t(pow(pow(a_b, gamma) * (1 - t) + pow(b_b, gamma) * t, 1 / gamma))); const float c_f = a_f * (1.0F - t) + //
b_f * t;
return static_cast<uint8_t>(powf(c_f, 1.F / gamma));
};
return Color::RGB(interp(a_r, b_r, t), //
interp(a_g, b_g, t), //
interp(a_b, b_b, t)); //
} }
inline namespace literals { inline namespace literals {

View File

@ -75,8 +75,7 @@ struct WordBreakPropertyInterval {
// Properties from: // Properties from:
// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt // https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt
constexpr std::array<WordBreakPropertyInterval, 993> constexpr std::array<WordBreakPropertyInterval, 993> g_word_break_intervals = {{
g_word_break_intervals = {{
{0x0000A, 0x0000A, WBP::LF}, {0x0000A, 0x0000A, WBP::LF},
{0x0000B, 0x0000C, WBP::Newline}, {0x0000B, 0x0000C, WBP::Newline},
{0x0000D, 0x0000D, WBP::CR}, {0x0000D, 0x0000D, WBP::CR},
@ -1070,7 +1069,7 @@ constexpr std::array<WordBreakPropertyInterval, 993>
{0xE0001, 0xE0001, WBP::Format}, {0xE0001, 0xE0001, WBP::Format},
{0xE0020, 0xE007F, WBP::Extend}, {0xE0020, 0xE007F, WBP::Extend},
{0xE0100, 0xE01EF, WBP::Extend}, {0xE0100, 0xE01EF, WBP::Extend},
}}; }};
// Construct table of just WBP::Extend character intervals // Construct table of just WBP::Extend character intervals
constexpr auto g_extend_characters{[]() constexpr { constexpr auto g_extend_characters{[]() constexpr {