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
impl Column
sourcepub fn priority(&mut self, priority: usize) -> &mut Self
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);
sourcepub fn max_width(
&mut self,
max_width: usize
) -> Result<&mut Self, ColonnadeError>
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)?;
sourcepub fn min_width(
&mut self,
min_width: usize
) -> Result<&mut Self, ColonnadeError>
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)?;
sourcepub fn fixed_width(&mut self, width: usize) -> Result<&mut Self, ColonnadeError>
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)?;
sourcepub fn clear_limits(&mut self) -> &mut Self
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();
sourcepub fn vertical_alignment(
&mut self,
vertical_alignment: VerticalAlignment
) -> &mut Self
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);
sourcepub fn left_margin(&mut self, left_margin: usize) -> &mut Self
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);
sourcepub fn padding(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_horizontal(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_left(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_right(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_vertical(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_top(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn padding_bottom(&mut self, padding: usize) -> &mut Self
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);
sourcepub fn hyphenate(&mut self, hyphenate: bool) -> &mut Self
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