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§

source§

impl Column

source

pub fn priority(&mut self, priority: usize) -> &mut Self

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);
source

pub fn max_width( &mut self, max_width: usize ) -> Result<&mut Self, ColonnadeError>

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)?;
source

pub fn min_width( &mut self, min_width: usize ) -> Result<&mut Self, ColonnadeError>

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)?;
source

pub fn fixed_width(&mut self, width: usize) -> Result<&mut Self, ColonnadeError>

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)?;
source

pub fn clear_limits(&mut self) -> &mut Self

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();
source

pub fn alignment(&mut self, alignment: Alignment) -> &mut Self

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);
source

pub fn vertical_alignment( &mut self, vertical_alignment: VerticalAlignment ) -> &mut Self

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);
source

pub fn left_margin(&mut self, left_margin: usize) -> &mut Self

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);
source

pub fn padding(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_horizontal(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_left(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_right(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_vertical(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_top(&mut self, padding: usize) -> &mut Self

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);
source

pub fn padding_bottom(&mut self, padding: usize) -> &mut Self

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);
source

pub fn hyphenate(&mut self, hyphenate: bool) -> &mut Self

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§

source§

impl Clone for Column

source§

fn clone(&self) -> Column

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Column

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.