Skip to main content

Overview

The Row class represents a single row in a table. It manages a collection of columns and provides configuration options for row-specific styling and borders.

Class Definition

namespace tabular {
  class Row;
}

Constructors

Default Constructor

Row()
Creates an empty row. Example:
tabular::Row row;

Column Vector Constructor

explicit Row(std::vector<Column> columns)
Creates a row from a vector of Column objects.
columns
std::vector<Column>
Vector of Column objects to initialize the row
Example:
using namespace tabular;

Column col1("Name");
Column col2("Age");
Row row({col1, col2});

String Vector Constructor

explicit Row(std::vector<std::string> columns)
Creates a row from a vector of strings. Each string becomes a column.
columns
std::vector<std::string>
Vector of strings to create columns
Example:
tabular::Row row({"Alice", "30", "New York"});

Methods

columns()

Gets or sets all columns in the row.
std::vector<Column>& columns()
const std::vector<Column>& columns() const
void columns(std::vector<Column> columns)
Returns: Reference to the vector of columns Example:
Row row;
row.columns({
  Column("Data1"),
  Column("Data2"),
  Column("Data3")
});

// Access all columns
for (auto& col : row.columns()) {
  col.config().align(Align::Center);
}

column()

Accesses a specific column by index.
Column& column(int index)
const Column& column(int index) const
Column& operator[](int index)
const Column& operator[](int index) const
index
int
Zero-based index of the column to access
Returns: Reference to the column at the specified index Throws: std::out_of_range if index is invalid Example:
Row row({"Name", "Age", "City"});

// Access column by index
row.column(0).style().fg(Color::Green);

// Or using operator[]
row[1].config().align(Align::Center);

config()

Accesses the row’s configuration settings.
Config& config()
const Config& config() const
Returns: Reference to the Config object Example:
Row row({"Header1", "Header2"});
row.config().hasBottom(true);

str()

Generates the string representation of the row.
const std::string& str() const
Returns: Const reference to the rendered row string Note: This method uses caching and is automatically called by Table when rendering.

clr()

Clears all columns and resets the row configuration.
void clr()
Example:
Row row({"Data1", "Data2"});
row.clr(); // Row is now empty

Nested Classes

Row::Config

Configuration class for row-level settings.

Methods

hasBottom()
void hasBottom(bool hasBottom)
bool hasBottom() const
Controls whether the row has a bottom border separator.
hasBottom
bool
If true, a horizontal separator is drawn below the row (default: true)
Example:
// Header row with bottom border
row.config().hasBottom(true);

// Regular row without bottom border
row.config().hasBottom(false);
vertical()
void vertical(Border::Part part)
const Border::Part& vertical() const
Sets the vertical border character for this row.
part
Border::Part
Border part to use for vertical separators
Example:
Border::Part customVertical(U'|');
customVertical.fg(Color::Blue);
row.config().vertical(customVertical);
reset()
void reset()
Resets configuration to default values.

Examples

Creating a Header Row

#include <tabular/table.h>
using namespace tabular;

Table table;

// Add header row with styling
Row header({"Name", "Age", "City"});
header.config().hasBottom(true);

// Style each header column
for (auto& col : header.columns()) {
  col.style().fg(Color::BrightCyan).attrs(Attr::Bold);
  col.config().align(Align::Center);
}

table.addRow(header);

Creating a Data Row

using namespace tabular;

Row dataRow({"Alice", "30", "New York"});
dataRow.config().hasBottom(false);

// Align specific columns
dataRow[0].config().align(Align::Left);
dataRow[1].config().align(Align::Center);
dataRow[2].config().align(Align::Left);

Accessing and Modifying Columns

Row row({"Value1", "Value2", "Value3"});

// Modify specific columns
row.column(0).content("Updated");
row.column(1).style().fg(Color::Green);
row.column(2).config().width(20);

// Iterate through all columns
for (size_t i = 0; i < row.columns().size(); i++) {
  row[i].config().align(Align::Center);
}

Custom Row Separators

using namespace tabular;

Table table;
table.border(Border::modern());

// Header with separator
Row header({"Product", "Price", "Stock"});
header.config().hasBottom(true);
table.addRow(header);

// Data rows without separators
for (int i = 0; i < 3; i++) {
  Row dataRow({"Item" + std::to_string(i), "$10", "100"});
  dataRow.config().hasBottom(false);
  table.addRow(dataRow);
}

// Last row with separator
table.row(table.rows().size() - 1).config().hasBottom(false);

See Also

  • Table - Table class reference
  • Column - Column configuration
  • Border - Border styling options

Build docs developers (and LLMs) love