Loading...
Searching...
No Matches
table.hpp
Go to the documentation of this file.
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_DOM_TABLE
#define FTXUI_DOM_TABLE
#include <string> // for string
#include <vector> // for vector
#include "ftxui/dom/elements.hpp" // for Element, BorderStyle, LIGHT, Decorator
namespace ftxui {
// Usage:
//
// Initialization:
// ---------------
//
// auto table = Table({
// {"X", "Y"},
// {"-1", "1"},
// {"+0", "0"},
// {"+1", "1"},
// });
//
// table.SelectAll().Border(LIGHT);
//
// table.SelectRow(1).Border(DOUBLE);
// table.SelectRow(1).SeparatorInternal(Light);
//
// std::move(table).Element();
class Table;
class TableSelection;
class Table {
public:
Table();
explicit Table(std::vector<std::vector<std::string>>);
explicit Table(std::vector<std::vector<Element>>);
Table(std::initializer_list<std::vector<std::string>> init);
TableSelection SelectAll();
TableSelection SelectCell(int column, int row);
TableSelection SelectRow(int row_index);
TableSelection SelectRows(int row_min, int row_max);
TableSelection SelectColumn(int column_index);
TableSelection SelectColumns(int column_min, int column_max);
TableSelection SelectRectangle(int column_min,
int column_max,
int row_min,
int row_max);
Element Render();
private:
void Initialize(std::vector<std::vector<Element>>);
friend TableSelection;
std::vector<std::vector<Element>> elements_;
int input_dim_x_ = 0;
int input_dim_y_ = 0;
int dim_x_ = 0;
int dim_y_ = 0;
};
class TableSelection {
public:
void Decorate(Decorator);
void DecorateAlternateRow(Decorator, int modulo = 2, int shift = 0);
void DecorateAlternateColumn(Decorator, int modulo = 2, int shift = 0);
void DecorateCells(Decorator);
void DecorateCellsAlternateColumn(Decorator, int modulo = 2, int shift = 0);
void DecorateCellsAlternateRow(Decorator, int modulo = 2, int shift = 0);
void Border(BorderStyle border = LIGHT);
void BorderLeft(BorderStyle border = LIGHT);
void BorderRight(BorderStyle border = LIGHT);
void BorderTop(BorderStyle border = LIGHT);
void BorderBottom(BorderStyle border = LIGHT);
void Separator(BorderStyle border = LIGHT);
void SeparatorVertical(BorderStyle border = LIGHT);
void SeparatorHorizontal(BorderStyle border = LIGHT);
private:
friend Table;
Table* table_;
int x_min_;
int x_max_;
int y_min_;
int y_max_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_TABLE */
ftxui::TableSelection
Definition table.hpp:64
ftxui::TableSelection::DecorateAlternateColumn
void DecorateAlternateColumn(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the lines modulo modulo with a shift of shif...
Definition table.cpp:287
ftxui::TableSelection::SeparatorVertical
void SeparatorVertical(BorderStyle border=LIGHT)
Draw some vertical separator lines in the selection.
Definition table.cpp:398
ftxui::TableSelection::DecorateCells
void DecorateCells(Decorator)
Apply the decorator to the selection.
Definition table.cpp:269
ftxui::TableSelection::BorderLeft
void BorderLeft(BorderStyle border=LIGHT)
Draw some separator lines to the left side of the selection.
Definition table.cpp:426
ftxui::TableSelection::DecorateCellsAlternateColumn
void DecorateCellsAlternateColumn(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the corners modulo modulo with a shift of sh...
Definition table.cpp:327
ftxui::TableSelection::Decorate
void Decorate(Decorator)
Apply the decorator to the selection. This decorate both the cells, the lines and the corners.
Definition table.cpp:255
ftxui::TableSelection::DecorateAlternateRow
void DecorateAlternateRow(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the lines modulo modulo with a shift of shif...
Definition table.cpp:307
ftxui::TableSelection::BorderTop
void BorderTop(BorderStyle border=LIGHT)
Draw some separator lines to the top side of the selection.
Definition table.cpp:446
ftxui::TableSelection::Separator
void Separator(BorderStyle border=LIGHT)
Draw some separator lines in the selection.
Definition table.cpp:382
ftxui::TableSelection::BorderBottom
void BorderBottom(BorderStyle border=LIGHT)
Draw some separator lines to the bottom side of the selection.
Definition table.cpp:456
ftxui::TableSelection::DecorateCellsAlternateRow
void DecorateCellsAlternateRow(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the corners modulo modulo with a shift of sh...
Definition table.cpp:347
ftxui::TableSelection::BorderRight
void BorderRight(BorderStyle border=LIGHT)
Draw some separator lines to the right side of the selection.
Definition table.cpp:436
ftxui::TableSelection::Border
void Border(BorderStyle border=LIGHT)
Apply a border around the selection.
Definition table.cpp:363
ftxui::TableSelection::SeparatorHorizontal
void SeparatorHorizontal(BorderStyle border=LIGHT)
Draw some horizontal separator lines in the selection.
Definition table.cpp:412
ftxui::Table
Definition table.hpp:36
ftxui::Table::Render
Element Render()
Render the table.
Definition table.cpp:224
ftxui::Table::Table
Table()
Create an empty table.
Definition table.cpp:48
ftxui::Table::SelectCell
TableSelection SelectCell(int column, int row)
Select a cell of the table.
Definition table.cpp:178
ftxui::Table::SelectColumn
TableSelection SelectColumn(int column_index)
Select a column of the table.
Definition table.cpp:160
ftxui::Table::SelectRow
TableSelection SelectRow(int row_index)
Select a row of the table.
Definition table.cpp:143
ftxui::Table::SelectColumns
TableSelection SelectColumns(int column_min, int column_max)
Select a range of columns of the table.
Definition table.cpp:169
ftxui::Table::SelectRows
TableSelection SelectRows(int row_min, int row_max)
Select a range of rows of the table.
Definition table.cpp:152
ftxui::Table::SelectAll
TableSelection SelectAll()
Select all the table.
Definition table.cpp:211
ftxui::Table::SelectRectangle
TableSelection SelectRectangle(int column_min, int column_max, int row_min, int row_max)
Select a rectangle of the table.
Definition table.cpp:189
elements.hpp
ftxui
Definition animation.hpp:10
ftxui::Decorator
std::function< Element(Element)> Decorator
Definition elements.hpp:24
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
ftxui::border
Element border(Element)
Draw a border around the element.
Definition border.cpp:227
ftxui::BorderStyle
BorderStyle
Definition elements.hpp:27
ftxui::LIGHT
@ LIGHT
Definition elements.hpp:28