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(to_string(std::wstring(ref))) {}
ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {}
ConstStringRef& operator=(const ConstStringRef&) = default;
};
/// @brief An adapter. Reference a list of strings.
@ -98,6 +96,8 @@ class ConstStringListRef {
ConstStringListRef() = default;
ConstStringListRef(const std::vector<std::string>* ref) : ref_(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 {
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 option;
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);
return option;
}

View File

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

View File

@ -17,7 +17,7 @@ namespace ftxui {
namespace {
struct LinearGradientNormalized {
float angle = 0.f;
float angle = 0.F;
std::vector<Color> colors;
std::vector<float> positions; // Sorted.
};
@ -27,15 +27,18 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
// Handle gradient of size 0.
if (gradient.stops.empty()) {
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.
if (!gradient.stops.front().position) {
gradient.stops.front().position = 0.f;
gradient.stops.front().position = 0.F;
}
if (!gradient.stops.back().position) {
gradient.stops.back().position = 1.f;
gradient.stops.back().position = 1.F;
}
// 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 (gradient.stops.front().position != 0) {
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 (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.
LinearGradientNormalized normalized;
// NOLINTNEXTLINE
normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f);
for (const auto& stop : gradient.stops) {
const float modulo = 360.F;
normalized.angle =
std::fmod(std::fmod(gradient.angle, modulo) + modulo, modulo);
for (auto& stop : gradient.stops) {
normalized.colors.push_back(stop.color);
normalized.positions.push_back(stop.position.value()); // NOLINT
// NOLINTNEXTLINE
normalized.positions.push_back(stop.position.value());
}
return normalized;
}
@ -90,8 +95,8 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) {
size_t i = 1;
while (true) {
if (i > gradient.positions.size()) {
// NOLINTNEXTLINE
return Color::Interpolate(0.5f, gradient.colors.back(),
const float half = 0.5F;
return Color::Interpolate(half, gradient.colors.back(),
gradient.colors.back());
}
if (t <= gradient.positions[i]) {
@ -122,7 +127,7 @@ class LinearGradientColor : public NodeDecorator {
private:
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 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:
// https://en.wikipedia.org/wiki/Gamma_correction
constexpr float gamma = 2.2f;
return Color::RGB(
uint8_t(pow(pow(a_r, gamma) * (1 - t) + pow(b_r, gamma) * t, 1 / gamma)),
uint8_t(pow(pow(a_g, gamma) * (1 - t) + pow(b_g, gamma) * t, 1 / gamma)),
uint8_t(pow(pow(a_b, gamma) * (1 - t) + pow(b_b, gamma) * t, 1 / gamma)));
auto interp = [](uint8_t a, uint8_t b, float t) {
constexpr float gamma = 2.2F;
const float a_f = powf(a, gamma);
const float b_f = powf(b, 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 {

File diff suppressed because it is too large Load Diff