mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 16:38:09 +08:00
Add Table constructor from Elements. (#310)
This commit is contained in:
@@ -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;
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user