Skip to content

Commit 31bf128

Browse files
authored
Merge pull request #37 from tertsdiepraam/expose-column-widths
expose the widths of the columns
2 parents 3e1b70a + 52ba9ab commit 31bf128

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ impl<T: AsRef<str>> Grid<T> {
130130
self.dimensions.num_lines
131131
}
132132

133+
/// The width of each column
134+
pub fn column_widths(&self) -> &[usize] {
135+
&self.dimensions.widths
136+
}
137+
133138
/// Returns whether this display takes up as many columns as were allotted
134139
/// to it.
135140
///
@@ -141,7 +146,7 @@ impl<T: AsRef<str>> Grid<T> {
141146
self.dimensions.widths.iter().all(|&x| x > 0)
142147
}
143148

144-
fn column_widths(&self, num_lines: usize, num_columns: usize) -> Dimensions {
149+
fn compute_dimensions(&self, num_lines: usize, num_columns: usize) -> Dimensions {
145150
let mut column_widths = vec![0; num_columns];
146151
for (index, cell_width) in self.widths.iter().copied().enumerate() {
147152
let index = match self.options.direction {
@@ -238,7 +243,7 @@ impl<T: AsRef<str>> Grid<T> {
238243
// Remove the separator width from the available space.
239244
let adjusted_width = maximum_width - total_separator_width;
240245

241-
let potential_dimensions = self.column_widths(num_lines, num_columns);
246+
let potential_dimensions = self.compute_dimensions(num_lines, num_columns);
242247
if potential_dimensions.widths.iter().sum::<usize>() <= adjusted_width {
243248
smallest_dimensions_yet = Some(potential_dimensions);
244249
} else {

0 commit comments

Comments
 (0)