pub struct Grid { /* private fields */ }
Expand description

Grid provides a set of methods for building a text-based table

Implementations

The new method creates a grid instance with default styles.

The size of the grid can not be changed after the instance is created.

Example
use papergrid::{Grid, Entity, Settings, Border};


let mut grid = Grid::new(2, 2);

grid.set(
    Entity::Global,
    Settings::new()
        .text("Hello World")
        .border(Border {
            right: Some(' '),
            ..Default::default()
        })
);

assert_eq!(
    grid.to_string(),
    "Hello World Hello World \n\
     Hello World Hello World "
);

Not empty initialization but empty content

use papergrid::Grid;

let mut grid = Grid::new(2, 2);
assert_eq!(grid.to_string(), "\n");

Empty

use papergrid::Grid;

let mut grid = Grid::new(0, 0);
assert_eq!(grid.to_string(), "");

Set method is responsible for modification of cell/row/column.

The method panics if incorrect cell/row/column index is given.

Example
use papergrid::{Grid, Entity, Settings, Borders};

let mut grid = Grid::new(2, 2);

grid.set_borders(Borders {
    vertical_intersection: Some('|'),
    horizontal: Some('-'),
    ..Default::default()
});

grid.set(Entity::Row(0), Settings::new().text("row 1"));
grid.set(Entity::Row(1), Settings::new().text("row 2"));
assert_eq!(
     grid.to_string(),
     "row 1|row 1\n\
      ----- -----\n\
      row 2|row 2"
)

Set a Margin value.

Returns a Margin value currently set.

Clears all theme changes. And sets it to default.

Set the Borders value as currect one.

Set the Borders value as currect one.

Returns a current Borders structure.

Set border set a border value to all cells in Entity.

Sets off all borders possible on the Entity.

It doesn’t changes globaly set borders through Grid::set_borders.

Set the border line by row index.

Row 0 means the top row. Row grid.count_rows() means the bottom row.

Sets off the border line by row index if any were set

Row 0 means the top row. Row grid.count_rows() means the bottom row.

Gets a overriden line.

Row 0 means the top row. Row grid.count_rows() means the bottom row.

This function returns a settings of a cell

Returns a border of a cell.

This function returns content without any style changes

This function returns content with style changes

This function returns a string width.

This function returns an amount of rows on the grid

This function returns an amount of columns on the grid

Set text value to all cells in Entity.

Creates a new Grid from original, Coping the things like styles and borders.

It doesn’t copy styles which were set for specific Entity.

Returns a total width of table, including split lines.

Override the split line with a custom text.

If borders are not set the string won’t be rendered.

The function returns all cells by lines.

It’s considered that string_width on these cells will be the same as the one which will be used in rendering.

The function returns whether the cells will be rendered or it will be hidden by a cell with a span.

Set a column span to a given cells.

Set a padding to a given cells.

Get a padding for a given Entity.

Set a formatting to a given cells.

Get a formatting settings for a given Entity.

Set a vertical alignment to a given cells.

Get a vertical alignment for a given Entity.

Set a horizontal alignment to a given cells.

Get a horizontal alignment for a given Entity.

Get a span value of the cell, if any is set.

Get a span value of the cell, if any is set.

Verifies if there’s any spans set.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.