Struct colonnade::Column

source ·
pub struct Column {
    pub width: usize,
    /* private fields */
}
Expand description

A struct holding formatting information for a particular column.

Fields§

§width: usize

the width of the column excluding any left margin

Implementations§

Assign a particular priority to the column.

Priority determines the order in which columns give up space when the viewport lacks sufficient space to display all columns without wrapping. Lower priority columns give up space first.

Arguments
  • priority - The column’s priority. Lower numbers confer higher priority; 0 is the highest priority.
Example
let mut colonnade = Colonnade::new(4, 100)?;
// assign all columns the highest priority
colonnade.priority(0);
// now demote the last column
colonnade.columns[3].priority(1);

Assign the same maximum width to all columns. By default columns have no maximum width.

Arguments
  • max_width - The common maximum width.
Errors
  • ColonnadeError::MinGreaterThanMax - Assigning a maximum width in conflict with some assigned minimum width.
  • ColonnadeError::OutOfBounds - Attemping to assign a maximum width to a column that does not exist.
Example
let mut colonnade = Colonnade::new(4, 100)?;
// assign the first column a maximum width of 20
colonnade.columns[0].max_width(20)?;

Assign a particular minimum width to a particular column. By default columns have no minimum width.

Arguments
  • min_width - The common minimum width.
Errors
  • ColonnadeError::MinGreaterThanMax - Assigning a maximum width in conflict with some assigned minimum width.
Example
let mut colonnade = Colonnade::new(4, 100)?;
// assign the first column a minimum width of 20
colonnade.columns[0].min_width(20)?;

Assign a particular maximum and minimum width to a particular column. By default columns have neither a maximum nor a minimum width.

Arguments
  • width - The common width.
Errors

This method is a convenience method which assigns the column in question the same maximum and minimum width. Therefore the errors thrown are those thrown by max_width and min_width.

Example
let mut colonnade = Colonnade::new(4, 100)?;
// assign the first column a width of 20
colonnade.columns[0].fixed_width(20)?;

Remove maximum or minimum column widths from a particular column.

Example
let mut colonnade = Colonnade::new(4, 100)?;
// initially assign all columns a width of 20
colonnade.fixed_width(20);
// but we want the first column to be flexible
colonnade.columns[0].clear_limits();

Assign a particular column a particular alignment. The default alignment is left.

Arguments
  • alignment - The desired alignment.
Example
let mut colonnade = Colonnade::new(4, 100)?;
// the first column should be right-aligned (it's numeric)
colonnade.columns[0].alignment(Alignment::Right);

Assign a particular column a particular vertical alignment. The default alignment is top.

Arguments
  • vertical_alignment - The desired alignment.
Example
let mut colonnade = Colonnade::new(4, 100)?;
// the first column should be right-aligned (it's numeric)
colonnade.columns[0].vertical_alignment(VerticalAlignment::Middle);

Assign a particular column a particular left margin. The left margin is a number of blank spaces before the content of the column. By default the first column has a left margin of 0 and the other columns have a left margin of 1.

Arguments
  • left_margin - The width in blank spaces of the desired margin.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].left_margin(2);

Assign a particular column a particular padding.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding(1);

Assign a particular column a particular horizontal padding – space before and after the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_horizontal(1);

Assign a particular column a particular left padding – space before the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_left(1);

Assign a particular column a particular right padding – space after the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_right(1);

Assign a particular column a particular vertical padding – blank lines before and after the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_vertical(1);

Assign a particular column a particular top padding – blank lines before the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_top(1);

Assign a particular column a particular bottom padding – blank lines after the column’s text.

See Colonnade::padding.

Arguments
  • padding - The width in blank spaces/lines of the desired padding.
Example
let mut colonnade = Colonnade::new(4, 100)?;
colonnade.columns[0].padding_bottom(1);

Toggle whether words too wide to fit in the column are hyphenated when spit. By default this is true. If there is only 1 character of available space in a column, though, there is never any hyphenation.

Arguments
  • hyphenate - Whether to hyphenate when splitting words.
Example
let mut colonnade = Colonnade::new(1, 3)?;
colonnade.alignment(Alignment::Right);
for line in colonnade.tabulate(&[[1234]])? {
    println!("{}", line);
}
// 12-
//  34
colonnade.columns[0].hyphenate(false);
for line in colonnade.tabulate(&[[1234]])? {
    println!("{}", line);
}
// 123
//   4

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

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
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.