Execute clang tidy and IWYU (#528)

This commit is contained in:
Arthur Sonzogni
2022-12-19 18:51:25 +01:00
committed by ArthurSonzogni
parent 4dc1a9fff9
commit 0542227ba7
55 changed files with 315 additions and 298 deletions

View File

@@ -12,7 +12,7 @@ void ComputeGrow(std::vector<Element>* elements,
int extra_space,
int flex_grow_sum) {
for (Element& element : *elements) {
int added_space =
const int added_space =
extra_space * element.flex_grow / std::max(flex_grow_sum, 1);
extra_space -= added_space;
flex_grow_sum -= element.flex_grow;
@@ -27,8 +27,8 @@ void ComputeShrinkEasy(std::vector<Element>* elements,
int extra_space,
int flex_shrink_sum) {
for (Element& element : *elements) {
int added_space = extra_space * element.min_size * element.flex_shrink /
std::max(flex_shrink_sum, 1);
const int added_space = extra_space * element.min_size *
element.flex_shrink / std::max(flex_shrink_sum, 1);
extra_space -= added_space;
flex_shrink_sum -= element.flex_shrink * element.min_size;
element.size = element.min_size + added_space;
@@ -48,7 +48,7 @@ void ComputeShrinkHard(std::vector<Element>* elements,
continue;
}
int added_space = extra_space * element.min_size / std::max(1, size);
const int added_space = extra_space * element.min_size / std::max(1, size);
extra_space -= added_space;
size -= element.min_size;
@@ -73,7 +73,7 @@ void Compute(std::vector<Element>* elements, int target_size) {
size += element.min_size;
}
int extra_space = target_size - size;
const int extra_space = target_size - size;
if (extra_space >= 0) {
ComputeGrow(elements, extra_space, flex_grow_sum);
} else if (flex_shrink_size + extra_space >= 0) {

View File

@@ -1,6 +1,7 @@
#include "ftxui/dom/canvas.hpp"
#include <algorithm> // for max, min
#include <cmath> // for abs
#include <cstdint> // for uint8_t
#include <cstdlib> // for abs
#include <ftxui/screen/color.hpp> // for Color
@@ -469,7 +470,7 @@ void Canvas::DrawBlockOn(int x, int y) {
cell.type = CellType::kBlock;
}
uint8_t bit = (x % 2) * 2 + y % 2;
const uint8_t bit = (x % 2) * 2 + y % 2;
uint8_t value = g_map_block_inversed.at(cell.content.character);
value |= 1U << bit;
cell.content.character = g_map_block[value];
@@ -489,7 +490,7 @@ void Canvas::DrawBlockOff(int x, int y) {
}
y /= 2;
uint8_t bit = (y % 2) * 2 + x % 2;
const uint8_t bit = (y % 2) * 2 + x % 2;
uint8_t value = g_map_block_inversed.at(cell.content.character);
value &= ~(1U << bit);
cell.content.character = g_map_block[value];
@@ -510,7 +511,7 @@ void Canvas::DrawBlockToggle(int x, int y) {
}
y /= 2;
uint8_t bit = (y % 2) * 2 + x % 2;
const uint8_t bit = (y % 2) * 2 + x % 2;
uint8_t value = g_map_block_inversed.at(cell.content.character);
value ^= 1U << bit;
cell.content.character = g_map_block[value];
@@ -829,8 +830,8 @@ class CanvasNodeBase : public Node {
void Render(Screen& screen) override {
const Canvas& c = canvas();
int y_max = std::min(c.height() / 4, box_.y_max - box_.y_min + 1);
int x_max = std::min(c.width() / 2, box_.x_max - box_.x_min + 1);
const int y_max = std::min(c.height() / 4, box_.y_max - box_.y_min + 1);
const int x_max = std::min(c.width() / 2, box_.x_max - box_.x_min + 1);
for (int y = 0; y < y_max; ++y) {
for (int x = 0; x < x_max; ++x) {
screen.PixelAt(box_.x_min + x, box_.y_min + y) = c.GetPixel(x, y);
@@ -873,8 +874,8 @@ Element canvas(int width, int height, std::function<void(Canvas&)> fn) {
}
void Render(Screen& screen) final {
int width = (box_.x_max - box_.x_min + 1) * 2;
int height = (box_.y_max - box_.y_min + 1) * 4;
const int width = (box_.x_max - box_.x_min + 1) * 2;
const int height = (box_.y_max - box_.y_min + 1) * 4;
canvas_ = Canvas(width, height);
fn_(canvas_);
CanvasNodeBase::Render(screen);

View File

@@ -145,7 +145,7 @@ class Flexbox : public Node {
void SetBox(Box box) override {
Node::SetBox(box);
int asked_previous = asked_;
const int asked_previous = asked_;
asked_ = std::min(asked_, IsColumnOriented() ? box.y_max - box.y_min + 1
: box.x_max - box.x_min + 1);
need_iteration_ = (asked_ != asked_previous);
@@ -166,7 +166,7 @@ class Flexbox : public Node {
children_box.x_max = box.x_min + b.x + b.dim_x - 1;
children_box.y_max = box.y_min + b.y + b.dim_y - 1;
Box intersection = Box::Intersection(children_box, box);
const Box intersection = Box::Intersection(children_box, box);
child->SetBox(intersection);
need_iteration_ |= (intersection != children_box);

View File

@@ -162,9 +162,9 @@ void SetY(Global& g, std::vector<Line> lines) {
case FlexboxConfig::AlignContent::Stretch: {
for (int i = ys.size() - 1; i >= 0; --i) { // NOLINT
int shifted = remaining_space * (i + 0) / (i + 1);
const int shifted = remaining_space * (i + 0) / (i + 1);
ys[i] += shifted;
int consumed = remaining_space - shifted;
const int consumed = remaining_space - shifted;
elements[i].size += consumed;
remaining_space -= consumed;
}
@@ -200,10 +200,10 @@ void SetY(Global& g, std::vector<Line> lines) {
for (size_t i = 0; i < lines.size(); ++i) {
auto& element = elements[i];
for (auto* block : lines[i].blocks) {
bool stretch =
const bool stretch =
block->flex_grow_y != 0 ||
g.config.align_content == FlexboxConfig::AlignContent::Stretch;
int size =
const int size =
stretch ? element.size : std::min(element.size, block->min_size_y);
switch (g.config.align_items) {
case FlexboxConfig::AlignItems::FlexStart: {

View File

@@ -102,9 +102,9 @@ class Frame : public Node {
Box children_box = box;
if (x_frame_) {
int external_dimx = box.x_max - box.x_min;
int internal_dimx = std::max(requirement_.min_x, external_dimx);
int focused_dimx = selected_box.x_max - selected_box.x_min;
const int external_dimx = box.x_max - box.x_min;
const int internal_dimx = std::max(requirement_.min_x, external_dimx);
const int focused_dimx = selected_box.x_max - selected_box.x_min;
int dx = selected_box.x_min - external_dimx / 2 + focused_dimx / 2;
dx = std::max(0, std::min(internal_dimx - external_dimx - 1, dx));
children_box.x_min = box.x_min - dx;
@@ -112,9 +112,9 @@ class Frame : public Node {
}
if (y_frame_) {
int external_dimy = box.y_max - box.y_min;
int internal_dimy = std::max(requirement_.min_y, external_dimy);
int focused_dimy = selected_box.y_max - selected_box.y_min;
const int external_dimy = box.y_max - box.y_min;
const int internal_dimy = std::max(requirement_.min_y, external_dimy);
const int focused_dimy = selected_box.y_max - selected_box.y_min;
int dy = selected_box.y_min - external_dimy / 2 + focused_dimy / 2;
dy = std::max(0, std::min(internal_dimy - external_dimy - 1, dy));
children_box.y_min = box.y_min - dy;
@@ -125,8 +125,8 @@ class Frame : public Node {
}
void Render(Screen& screen) override {
AutoReset<Box> stencil(&screen.stencil,
Box::Intersection(box_, screen.stencil));
const AutoReset<Box> stencil(&screen.stencil,
Box::Intersection(box_, screen.stencil));
children_[0]->Render(screen);
}

View File

@@ -90,17 +90,17 @@ class Gauge : public Node {
}
void RenderHorizontal(Screen& screen, bool invert) {
int y = box_.y_min;
const int y = box_.y_min;
if (y > box_.y_max) {
return;
}
// Draw the progress bar horizontally.
{
float progress = invert ? 1.F - progress_ : progress_;
float limit =
const float progress = invert ? 1.F - progress_ : progress_;
const float limit =
(float)box_.x_min + progress * (float)(box_.x_max - box_.x_min + 1);
int limit_int = (int)limit;
const int limit_int = (int)limit;
int x = box_.x_min;
while (x < limit_int) {
screen.at(x++, y) = charset_horizontal[9]; // NOLINT
@@ -120,17 +120,17 @@ class Gauge : public Node {
}
void RenderVertical(Screen& screen, bool invert) {
int x = box_.x_min;
const int x = box_.x_min;
if (x > box_.x_max) {
return;
}
// Draw the progress bar vertically:
{
float progress = invert ? progress_ : 1.F - progress_;
float limit =
const float progress = invert ? progress_ : 1.F - progress_;
const float limit =
(float)box_.y_min + progress * (float)(box_.y_max - box_.y_min + 1);
int limit_int = (int)limit;
const int limit_int = (int)limit;
int y = box_.y_min;
while (y < limit_int) {
screen.at(x, y++) = charset_vertical[8]; // NOLINT

View File

@@ -37,15 +37,15 @@ class Graph : public Node {
}
void Render(Screen& screen) override {
int width = (box_.x_max - box_.x_min + 1) * 2;
int height = (box_.y_max - box_.y_min + 1) * 2;
const int width = (box_.x_max - box_.x_min + 1) * 2;
const int height = (box_.y_max - box_.y_min + 1) * 2;
auto data = graph_function_(width, height);
int i = 0;
for (int x = box_.x_min; x <= box_.x_max; ++x) {
int height_1 = 2 * box_.y_max - data[i++];
int height_2 = 2 * box_.y_max - data[i++];
const int height_1 = 2 * box_.y_max - data[i++];
const int height_2 = 2 * box_.y_max - data[i++];
for (int y = box_.y_min; y <= box_.y_max; ++y) {
int yy = 2 * y;
const int yy = 2 * y;
int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6; // NOLINT
int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2; // NOLINT
screen.at(x, y) = charset[i_1 + i_2]; // NOLINT

View File

@@ -22,7 +22,7 @@ namespace {
int Integrate(std::vector<int>& elements) {
int accu = 0;
for (auto& i : elements) {
int old_accu = accu;
const int old_accu = accu;
accu += i;
i = old_accu;
}
@@ -113,8 +113,8 @@ class GridBox : public Node {
}
}
int target_size_x = box.x_max - box.x_min + 1;
int target_size_y = box.y_max - box.y_min + 1;
const int target_size_x = box.x_max - box.x_min + 1;
const int target_size_y = box.y_max - box.y_min + 1;
box_helper::Compute(&elements_x, target_size_x);
box_helper::Compute(&elements_y, target_size_y);
@@ -165,15 +165,15 @@ class GridBox : public Node {
/// ```
/// Output:
/// ```
///╭──────────╮╭──────╮╭──────────╮
///│north-west││north ││north-east│
///╰──────────╯╰──────╯╰──────────╯
///╭──────────╮╭──────╮╭──────────╮
///│west ││center││east │
///╰──────────╯╰──────╯╰──────────╯
///╭──────────╮╭──────╮╭──────────╮
///│south-west││south ││south-east│
///╰──────────╯╰──────╯╰──────────╯
/// ╭──────────╮╭──────╮╭──────────╮
/// │north-west││north ││north-east│
/// ╰──────────╯╰──────╯╰──────────╯
/// ╭──────────╮╭──────╮╭──────────╮
/// │west ││center││east │
/// ╰──────────╯╰──────╯╰──────────╯
/// ╭──────────╮╭──────╮╭──────────╮
/// │south-west││south ││south-east│
/// ╰──────────╯╰──────╯╰──────────╯
/// ```
Element gridbox(std::vector<Elements> lines) {
return std::make_shared<GridBox>(std::move(lines));

View File

@@ -49,7 +49,7 @@ class HBox : public Node {
element.flex_grow = requirement.flex_grow_x;
element.flex_shrink = requirement.flex_shrink_x;
}
int target_size = box.x_max - box.x_min + 1;
const int target_size = box.x_max - box.x_min + 1;
box_helper::Compute(&elements, target_size);
int x = box.x_min;

View File

@@ -39,11 +39,11 @@ Element vscroll_indicator(Element child) {
const Box& stencil = screen.stencil;
int size_inner = box_.y_max - box_.y_min;
const int size_inner = box_.y_max - box_.y_min;
if (size_inner <= 0) {
return;
}
int size_outter = stencil.y_max - stencil.y_min + 1;
const int size_outter = stencil.y_max - stencil.y_min + 1;
if (size_outter >= size_inner) {
return;
}
@@ -51,15 +51,16 @@ Element vscroll_indicator(Element child) {
int size = 2 * size_outter * size_outter / size_inner;
size = std::max(size, 1);
int start_y = 2 * stencil.y_min + //
2 * (stencil.y_min - box_.y_min) * size_outter / size_inner;
const int start_y =
2 * stencil.y_min + //
2 * (stencil.y_min - box_.y_min) * size_outter / size_inner;
const int x = stencil.x_max;
for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
int y_up = 2 * y + 0;
int y_down = 2 * y + 1;
bool up = (start_y <= y_up) && (y_up <= start_y + size);
bool down = (start_y <= y_down) && (y_down <= start_y + size);
const int y_up = 2 * y + 0;
const int y_down = 2 * y + 1;
const bool up = (start_y <= y_up) && (y_up <= start_y + size);
const bool down = (start_y <= y_down) && (y_down <= start_y + size);
const char* c = up ? (down ? "" : "") : (down ? "" : " "); // NOLINT
screen.PixelAt(x, y) = Pixel();

View File

@@ -58,8 +58,8 @@ class SeparatorAuto : public Node {
}
void Render(Screen& screen) override {
bool is_column = (box_.x_max == box_.x_min);
bool is_line = (box_.y_min == box_.y_max);
const bool is_column = (box_.x_max == box_.x_min);
const bool is_line = (box_.y_min == box_.y_max);
const std::string c = charsets[style_][int(is_line && !is_column)];
@@ -414,14 +414,14 @@ Element separatorHSelector(float left,
int demi_cell_left = int(left_ * 2.F - 1.F); // NOLINT
int demi_cell_right = int(right_ * 2.F + 2.F); // NOLINT
int y = box_.y_min;
const int y = box_.y_min;
for (int x = box_.x_min; x <= box_.x_max; ++x) {
Pixel& pixel = screen.PixelAt(x, y);
int a = (x - box_.x_min) * 2;
int b = a + 1;
bool a_empty = demi_cell_left == a || demi_cell_right == a;
bool b_empty = demi_cell_left == b || demi_cell_right == b;
const int a = (x - box_.x_min) * 2;
const int b = a + 1;
const bool a_empty = demi_cell_left == a || demi_cell_right == a;
const bool b_empty = demi_cell_left == b || demi_cell_right == b;
if (!a_empty && !b_empty) {
pixel.character = "";
@@ -481,17 +481,17 @@ Element separatorVSelector(float up,
}
// This are the two location with an empty demi-cell.
int demi_cell_up = int(up_ * 2 - 1);
int demi_cell_down = int(down_ * 2 + 2);
const int demi_cell_up = int(up_ * 2 - 1);
const int demi_cell_down = int(down_ * 2 + 2);
int x = box_.x_min;
const int x = box_.x_min;
for (int y = box_.y_min; y <= box_.y_max; ++y) {
Pixel& pixel = screen.PixelAt(x, y);
int a = (y - box_.y_min) * 2;
int b = a + 1;
bool a_empty = demi_cell_up == a || demi_cell_down == a;
bool b_empty = demi_cell_up == b || demi_cell_down == b;
const int a = (y - box_.y_min) * 2;
const int b = a + 1;
const bool a_empty = demi_cell_up == a || demi_cell_down == a;
const bool b_empty = demi_cell_up == b || demi_cell_down == b;
if (!a_empty && !b_empty) {
pixel.character = "";

View File

@@ -720,14 +720,14 @@ TEST(TableTest, Merge) {
Screen screen(7, 7);
Render(screen, table.Render());
EXPECT_EQ(
"┌─┲━┱─┐\r\n"
"│a┃b┃c│\r\n"
"┢━╋━╋━┪\r\n"
"┃d┃e┃f┃\r\n"
"┡━╋━╋━┩\r\n"
"│g┃h┃i│\r\n"
"└─┺━┹─┘",
screen.ToString());
"┌─┲━┱─┐\r\n"
"│a┃b┃c│\r\n"
"┢━╋━╋━┪\r\n"
"┃d┃e┃f┃\r\n"
"┡━╋━╋━┩\r\n"
"│g┃h┃i│\r\n"
"└─┺━┹─┘",
screen.ToString());
}
} // namespace ftxui

View File

@@ -27,7 +27,7 @@ class Text : public Node {
void Render(Screen& screen) override {
int x = box_.x_min;
int y = box_.y_min;
const int y = box_.y_min;
if (y > box_.y_max) {
return;
}
@@ -55,7 +55,7 @@ class VText : public Node {
}
void Render(Screen& screen) override {
int x = box_.x_min;
const int x = box_.x_min;
int y = box_.y_min;
if (x + width_ - 1 > box_.x_max) {
return;

View File

@@ -1,8 +1,9 @@
#include <algorithm> // for min
#include <functional> // for function
#include <memory> // for __shared_ptr_access, make_unique
#include <utility> // for move
#include <vector> // for vector
#include <algorithm> // for min
#include <functional> // for function
#include <memory> // for __shared_ptr_access, make_unique
#include <type_traits> // for remove_reference, remove_reference<>::type
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/elements.hpp" // for Element, Decorator, Elements, operator|, Fit, emptyElement, nothing, operator|=
#include "ftxui/dom/node.hpp" // for Node, Node::Status
@@ -88,7 +89,7 @@ Element& operator|=(Element& e, Decorator d) {
/// @see Fixed
/// @see Full
Dimensions Dimension::Fit(Element& e) {
Dimensions fullsize = Dimension::Full();
const Dimensions fullsize = Dimension::Full();
Box box;
box.x_min = 0;
box.y_min = 0;

View File

@@ -49,7 +49,7 @@ class VBox : public Node {
element.flex_grow = requirement.flex_grow_y;
element.flex_shrink = requirement.flex_shrink_y;
}
int target_size = box.y_max - box.y_min + 1;
const int target_size = box.y_max - box.y_min + 1;
box_helper::Compute(&elements, target_size);
int y = box.y_min;