mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-16 16:08:08 +08:00
@@ -75,6 +75,7 @@ struct Event {
|
||||
|
||||
//--- State section ----------------------------------------------------------
|
||||
ScreenInteractive* screen_ = nullptr;
|
||||
|
||||
private:
|
||||
friend ComponentBase;
|
||||
friend ScreenInteractive;
|
||||
|
@@ -17,7 +17,7 @@ using Elements = std::vector<Element>;
|
||||
using Decorator = std::function<Element(Element)>;
|
||||
using GraphFunction = std::function<std::vector<int>(int, int)>;
|
||||
|
||||
enum BorderStyle { LIGHT, HEAVY, DOUBLE, ROUNDED };
|
||||
enum BorderStyle { LIGHT, HEAVY, DOUBLE, ROUNDED, EMPTY };
|
||||
|
||||
// Pipe elements into decorator togethers.
|
||||
// For instance the next lines are equivalents:
|
||||
@@ -34,20 +34,24 @@ Element separator(void);
|
||||
Element separatorLight();
|
||||
Element separatorHeavy();
|
||||
Element separatorDouble();
|
||||
Element separatorEmpty();
|
||||
Element separatorStyled(BorderStyle);
|
||||
Element separator(Pixel);
|
||||
Element separatorCharacter(std::string);
|
||||
Element gauge(float ratio);
|
||||
Element border(Element);
|
||||
Element borderLight(Element);
|
||||
Element borderHeavy(Element);
|
||||
Element borderDouble(Element);
|
||||
Element borderRounded(Element);
|
||||
Element borderEmpty(Element);
|
||||
Decorator borderStyled(BorderStyle);
|
||||
Decorator borderWith(Pixel);
|
||||
Element window(Element title, Element content);
|
||||
Element spinner(int charset_index, size_t image_index);
|
||||
Elements paragraph(std::string text); // Use inside hflow(). Split by space.
|
||||
Element graph(GraphFunction);
|
||||
Element emptyElement();
|
||||
|
||||
// -- Decorator ---
|
||||
Element bold(Element);
|
||||
|
93
include/ftxui/dom/table.hpp
Normal file
93
include/ftxui/dom/table.hpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef FTXUI_DOM_TABLE
|
||||
#define FTXUI_DOM_TABLE
|
||||
|
||||
#include <memory>
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for BorderStyle, LIGHT, Element, 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(std::vector<std::vector<std::string>>);
|
||||
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:
|
||||
friend TableSelection;
|
||||
std::vector<std::vector<Element>> elements_;
|
||||
int input_dim_x_;
|
||||
int input_dim_y_;
|
||||
int dim_x_;
|
||||
int dim_y_;
|
||||
};
|
||||
|
||||
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 */
|
||||
|
||||
// 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.
|
Reference in New Issue
Block a user