Multiple fixes: signed/unsigned, etc... (#600)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Marc
2023-03-26 20:20:02 +02:00
committed by GitHub
parent e177409bd3
commit eed7e2ea70
48 changed files with 215 additions and 144 deletions

View File

@@ -4,6 +4,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
static void BencharkBasic(benchmark::State& state) {
@@ -12,11 +13,11 @@ static void BencharkBasic(benchmark::State& state) {
text("Test"),
separator(),
hbox({
gauge(0.9),
gauge(0.9f),
separator() | blink,
gauge(0.5),
gauge(0.5f),
separator() | inverted,
gauge(0.1),
gauge(0.1f),
separator(),
}),
text("Test"),
@@ -30,6 +31,7 @@ static void BencharkBasic(benchmark::State& state) {
BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16);
} // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(BlinkTest, Basic) {
@@ -15,6 +16,7 @@ TEST(BlinkTest, Basic) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(BoldTest, Basic) {
@@ -15,6 +16,7 @@ TEST(BoldTest, Basic) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(BorderTest, Default) {
@@ -100,6 +101,7 @@ TEST(BorderTest, Window) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stdint.h> // for uint32_t
#include <string> // for allocator, string
#include <cstdint> // for uint32_t
#include <string> // for allocator, string
#include "ftxui/dom/canvas.hpp" // for Canvas
#include "ftxui/dom/elements.hpp" // for canvas
@@ -9,6 +9,7 @@
#include "ftxui/screen/screen.hpp" // for Screen
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
// NOLINTBEGIN
namespace ftxui {
namespace {
@@ -101,6 +102,7 @@ TEST(CanvasTest, GoldText) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -6,6 +6,7 @@
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(ColorTest, Foreground) {
@@ -25,6 +26,7 @@ TEST(ColorTest, Background) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(DBoxTest, Basic) {
@@ -29,6 +30,7 @@ TEST(DBoxTest, Basic) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(DimTest, Basic) {
@@ -15,6 +16,7 @@ TEST(DimTest, Basic) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -4,6 +4,7 @@
#include "ftxui/dom/flexbox_helper.hpp"
// NOLINTBEGIN
namespace ftxui {
TEST(FlexboxHelperTest, BasicRow) {
@@ -227,6 +228,7 @@ TEST(FlexboxHelperTest, BasicColumnInversed) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -6,6 +6,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(FlexboxTest, BasicRow) {
@@ -454,6 +455,7 @@ TEST(FlexboxTest, Focus) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(GaugeTest, ZeroHorizontal) {
@@ -96,6 +97,7 @@ TEST(GaugeTest, OneVertical) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove
#include <cstddef> // for size_t
#include <memory> // for shared_ptr
#include <string> // for allocator, basic_string, string
#include <vector> // for vector
@@ -9,6 +9,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
namespace {
@@ -615,6 +616,7 @@ TEST(GridboxTest, Focus) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -1,15 +1,14 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <string> // for string, allocator
#include <vector> // for vector
#include <gtest/gtest.h> // for Test, TestInfo (ptr only), EXPECT_EQ, Message, TEST, TestPartResult
#include <cstddef> // for size_t
#include <string> // for allocator, basic_string, string
#include <vector> // for vector
#include "ftxui/dom/elements.hpp" // for text, operator|, hbox, Element, flex_grow, flex_shrink
#include "ftxui/dom/elements.hpp" // for text, operator|, Element, flex_grow, flex_shrink, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
#include "ftxui/screen/screen.hpp" // for Screen
using namespace ftxui;
using namespace ftxui;
// NOLINTBEGIN
namespace ftxui {
TEST(HBoxTest, NoFlex_NoFlex_NoFlex) {
auto root = hbox({
@@ -356,6 +355,9 @@ TEST(HBoxTest, FlexGrow_NoFlex_FlewShrink) {
}
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@@ -1,6 +1,6 @@
#include <stddef.h> // for size_t
#include <algorithm> // for max, min, sort, copy
#include <cmath> // for fmod, cos, sin
#include <cstddef> // for size_t
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <memory> // for allocator_traits<>::value_type, make_shared
#include <optional> // for optional, operator!=, operator<
@@ -25,7 +25,7 @@ struct LinearGradientNormalized {
// Convert a LinearGradient to a normalized version.
LinearGradientNormalized Normalize(LinearGradient gradient) {
// Handle gradient of size 0.
if (gradient.stops.size() == 0) {
if (gradient.stops.empty()) {
return LinearGradientNormalized{
0.f, {Color::Default, Color::Default}, {0.f, 1.f}};
}
@@ -46,11 +46,13 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
}
if (i - last_checkpoint >= 2) {
const float min = gradient.stops[i].position.value();
const float max = gradient.stops[last_checkpoint].position.value();
const float min = gradient.stops[i].position.value(); // NOLINT
const float max =
gradient.stops[last_checkpoint].position.value(); // NOLINT
for (size_t j = last_checkpoint + 1; j < i; ++j) {
gradient.stops[j].position =
min + (max - min) * (j - last_checkpoint) / (i - last_checkpoint);
gradient.stops[j].position = min + (max - min) *
float(j - last_checkpoint) /
float(i - last_checkpoint);
}
}
@@ -74,10 +76,11 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
// Normalize the angle.
LinearGradientNormalized normalized;
// NOLINTNEXTLINE
normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f);
for (auto& stop : gradient.stops) {
normalized.colors.push_back(stop.color);
normalized.positions.push_back(stop.position.value());
normalized.positions.push_back(stop.position.value()); // NOLINT
}
return normalized;
}
@@ -87,6 +90,7 @@ 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(),
gradient.colors.back());
}
@@ -123,10 +127,10 @@ class LinearGradientColor : public NodeDecorator {
const float dy = std::sin(gradient_.angle * degtorad);
// Project every corner to get the extent of the gradient.
const float p1 = box_.x_min * dx + box_.y_min * dy;
const float p2 = box_.x_min * dx + box_.y_max * dy;
const float p3 = box_.x_max * dx + box_.y_min * dy;
const float p4 = box_.x_max * dx + box_.y_max * dy;
const float p1 = float(box_.x_min) * dx + float(box_.y_min) * dy;
const float p2 = float(box_.x_min) * dx + float(box_.y_max) * dy;
const float p3 = float(box_.x_max) * dx + float(box_.y_min) * dy;
const float p4 = float(box_.x_max) * dx + float(box_.y_max) * dy;
const float min = std::min({p1, p2, p3, p4});
const float max = std::max({p1, p2, p3, p4});
@@ -140,14 +144,14 @@ class LinearGradientColor : public NodeDecorator {
if (background_color_) {
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
const float t = x * dX + y * dY + dZ;
const float t = float(x) * dX + float(y) * dY + dZ;
screen.PixelAt(x, y).background_color = Interpolate(gradient_, t);
}
}
} else {
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
const float t = x * dX + y * dY + dZ;
const float t = float(x) * dX + float(y) * dY + dZ;
screen.PixelAt(x, y).foreground_color = Interpolate(gradient_, t);
}
}
@@ -180,18 +184,15 @@ LinearGradient::LinearGradient() = default;
/// @param begin The color at the beginning of the gradient.
/// @param end The color at the end of the gradient.
/// @ingroup dom
LinearGradient::LinearGradient(Color begin, Color end) {
stops.push_back({begin, {}});
stops.push_back({end, {}});
}
LinearGradient::LinearGradient(Color begin, Color end)
: LinearGradient(0, begin, end) {}
/// @brief Build a gradient with two colors and an angle.
/// @param a The angle of the gradient.
/// @param begin The color at the beginning of the gradient.
/// @param end The color at the end of the gradient.
/// @ingroup dom
LinearGradient::LinearGradient(float a, Color begin, Color end) {
angle = a;
LinearGradient::LinearGradient(float a, Color begin, Color end) : angle(a) {
stops.push_back({begin, {}});
stops.push_back({end, {}});
}

View File

@@ -1,12 +1,13 @@
#include <gtest/gtest.h> // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <string> // for allocator
#include <memory> // for allocator_traits<>::value_type
#include "ftxui/dom/elements.hpp" // for operator|, text, bgcolor, color, Element
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight
#include "ftxui/screen/color.hpp" // for Color, Color::RedLight, Color::Red
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(ColorTest, API_default) {
@@ -84,6 +85,7 @@ TEST(ColorTest, GradientBackground) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2023 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -7,6 +7,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
namespace {
@@ -197,6 +198,7 @@ TEST(ScrollIndicator, HorizontalFlexbox) {
} // namespace
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(SeparatorTest, Default) {
@@ -122,6 +123,7 @@ TEST(SeparatorTest, WithPixel) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -278,7 +278,7 @@ const std::vector<std::vector<std::vector<std::string>>> elements = {
/// every "step".
/// @ingroup dom
Element spinner(int charset_index, size_t image_index) {
if (charset_index == 0) {
if (charset_index <= 0) {
const int progress_size = 40;
image_index %= progress_size;
if (image_index > progress_size / 2) {

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(SpinnerTest, Spinner1) {
@@ -36,6 +37,7 @@ TEST(SpinnerTest, Spinner4) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -6,6 +6,7 @@
#include "ftxui/dom/table.hpp"
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(TableTest, Empty) {
@@ -731,6 +732,7 @@ TEST(TableTest, Merge) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
TEST(TextTest, ScreenHeightSmaller) {
@@ -118,6 +119,7 @@ TEST(TextTest, CombiningCharactersWithSpace) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui {
TEST(UnderlinedTest, Basic) {
@@ -15,6 +16,7 @@ TEST(UnderlinedTest, Basic) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove
#include <cstddef> // for size_t
#include <string> // for string, allocator, basic_string
#include <vector> // for vector
@@ -8,6 +8,7 @@
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
namespace {
@@ -365,6 +366,7 @@ TEST(VBoxText, FlexGrow_NoFlex_FlewShrink) {
}
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in