mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
Add Table constructor from Elements. (#310)
This commit is contained in:
parent
feb24b9498
commit
382205c057
@ -20,6 +20,7 @@ unreleased (development)
|
||||
- `paragraphAlignJustify`
|
||||
- Add the helper elements based on `flexbox`: `hflow()`, `vflow()`.
|
||||
- Add: `focusPositionRelative` and `focusPosition`
|
||||
- Add `Table` constructor from 2D vector of Element, instead of string.
|
||||
|
||||
#### Component
|
||||
- Add the `collapsible` component.
|
||||
|
@ -33,7 +33,9 @@ class TableSelection;
|
||||
|
||||
class Table {
|
||||
public:
|
||||
Table();
|
||||
Table(std::vector<std::vector<std::string>>);
|
||||
Table(std::vector<std::vector<Element>>);
|
||||
TableSelection SelectAll();
|
||||
TableSelection SelectCell(int column, int row);
|
||||
TableSelection SelectRow(int row_index);
|
||||
@ -47,6 +49,7 @@ class Table {
|
||||
Element Render();
|
||||
|
||||
private:
|
||||
void Initialize(std::vector<std::vector<Element>>);
|
||||
friend TableSelection;
|
||||
std::vector<std::vector<Element>> elements_;
|
||||
int input_dim_x_;
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user