Add Table constructor from Elements. (#310)

This commit is contained in:
Arthur Sonzogni
2022-01-16 16:46:32 +01:00
committed by GitHub
parent feb24b9498
commit 382205c057
4 changed files with 26 additions and 2 deletions

View File

@@ -35,7 +35,27 @@ void Order(int& a, int& b) {
} // namespace
Table::Table() {
Initialize({});
}
Table::Table(std::vector<std::vector<std::string>> input) {
std::vector<std::vector<Element>> output;
for(auto& row : input) {
output.push_back({});
auto& output_row = output.back();
for(auto& cell : row) {
output_row.push_back(text(cell));
}
}
Initialize(std::move(output));
}
Table::Table(std::vector<std::vector<Element>> input) {
Initialize(std::move(input));
}
void Table::Initialize(std::vector<std::vector<Element>> input) {
input_dim_y_ = input.size();
input_dim_x_ = 0;
for (auto& row : input)
@@ -55,7 +75,7 @@ Table::Table(std::vector<std::vector<std::string>> input) {
for (auto& row : input) {
int x = 1;
for (auto& cell : row) {
elements_[y][x] = text(cell);
elements_[y][x] = std::move(cell);
x += 2;
}
y += 2;

View File

@@ -12,7 +12,7 @@
using namespace ftxui;
TEST(TableTest, Empty) {
auto table = Table({});
auto table = Table();
Screen screen(5, 5);
Render(screen, table.Render());
EXPECT_EQ(