| 
									
										
										
										
											2023-08-19 13:56:36 +02:00
										 |  |  | // 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.
 | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | #ifndef FTXUI_DOM_TABLE
 | 
					
						
							|  |  |  | #define FTXUI_DOM_TABLE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>  // for string
 | 
					
						
							|  |  |  | #include <vector>  // for vector
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-05 15:03:45 +01:00
										 |  |  | #include "ftxui/dom/elements.hpp"  // for Element, BorderStyle, LIGHT, Decorator
 | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace ftxui { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Table; | 
					
						
							|  |  |  | class TableSelection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 11:35:14 +02:00
										 |  |  | /// @brief Table is a utility to draw tables.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// **example**
 | 
					
						
							|  |  |  | /// ```cpp
 | 
					
						
							|  |  |  | /// 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).Render();
 | 
					
						
							|  |  |  | /// ```
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// @ingroup dom
 | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | class Table { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2022-01-16 16:46:32 +01:00
										 |  |  |   Table(); | 
					
						
							| 
									
										
										
										
											2024-05-01 11:40:49 +02:00
										 |  |  |   explicit Table(std::vector<std::vector<std::string>>); | 
					
						
							|  |  |  |   explicit Table(std::vector<std::vector<Element>>); | 
					
						
							| 
									
										
										
										
											2024-08-13 15:55:09 +02:00
										 |  |  |   Table(std::initializer_list<std::vector<std::string>> init); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  |   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: | 
					
						
							| 
									
										
										
										
											2022-01-16 16:46:32 +01:00
										 |  |  |   void Initialize(std::vector<std::vector<Element>>); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  |   friend TableSelection; | 
					
						
							|  |  |  |   std::vector<std::vector<Element>> elements_; | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |   int input_dim_x_ = 0; | 
					
						
							|  |  |  |   int input_dim_y_ = 0; | 
					
						
							|  |  |  |   int dim_x_ = 0; | 
					
						
							|  |  |  |   int dim_y_ = 0; | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 */
 |