Skip to content

Commit

Permalink
Add Column::remove_constraint()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Jan 29, 2020
1 parent f8679c4 commit 4e70011
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#v0.0.5

- Add `Column::remove_constraint()`
- Preset `UTF8_NO_BORDERS`
- Preset `UTF8_HORIZONTAL_BORDERS_ONLY`
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "comfy-table"
description = "A easy to use, dynamically wrapping and highly configurable commandline table builder library."
version = "0.0.4"
version = "0.0.5"
authors = ["Arne Beer <[email protected]>"]
homepage = "https://github.com/nukesor/comfy-table"
repository = "https://github.com/nukesor/comfy-table"
Expand Down
27 changes: 27 additions & 0 deletions src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,36 @@ impl Column {
self.constraint.as_ref()
}

/// Remove any constraint on this column
pub fn remove_constraint(&mut self) -> &mut Self{
self.constraint = None;

self
}

/// Set the alignment for content inside of cells for this column. \
/// **Note:** Alignment on a cell will always overwrite the column's setting.
pub fn set_cell_alignment(&mut self, alignment: CellAlignment) {
self.cell_alignment = Some(alignment);
}
}



#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_column() {
let mut column = Column::new(0);
column.set_padding((0, 0));
assert_eq!(column.get_max_content_width(), 0);

column.set_constraint(ColumnConstraint::ContentWidth);
assert_eq!(column.get_constraint(), Some(&ColumnConstraint::ContentWidth));

column.remove_constraint();
assert_eq!(column.get_constraint(), None);
}
}
2 changes: 1 addition & 1 deletion src/style/column.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Constraints can be added to (columns)[crate::Column].\
/// They allow some control over the dynamic content arrangement process. \
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ColumnConstraint {
/// Force the column to be as long as it's content.
/// Use with caution! This can easily break your table, if the column's content is overly long.
Expand Down

0 comments on commit 4e70011

Please sign in to comment.