-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from zhiburt/patch/rework-span
Rework `Span`
- Loading branch information
Showing
10 changed files
with
474 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! [COMMENTED] A list of examples for a span use. | ||
use tabled::{ | ||
settings::{style::BorderSpanCorrection, Alignment, Span, Style}, | ||
Table, | ||
}; | ||
|
||
fn main() { | ||
let data = [ | ||
(1, 2, 3), | ||
(4, 5, 6), | ||
(7, 8, 9), | ||
(10, 11, 12), | ||
(13, 14, 15), | ||
(16, 17, 18), | ||
(19, 20, 21), | ||
]; | ||
let mut table = Table::new(data); | ||
|
||
table.with(Style::modern_rounded()); | ||
|
||
// Here we show how original table looks. | ||
println!("{table}"); | ||
|
||
// Then there's a list of Span appliences and it's affects. | ||
|
||
// Spread cell by 1 column to the right. | ||
table.modify((0, 1), Span::column(2)); | ||
|
||
// Spread cell all the way to the right, | ||
// Which essentially covers all row. | ||
table.modify((1, 0), Span::column(isize::MAX)); | ||
|
||
// Spread cell by 1 column to the left. | ||
table.modify((2, 1), Span::column(-1)); | ||
|
||
// Spread cell all the way to the left. | ||
table.modify((3, 2), Span::column(isize::MIN)); | ||
|
||
// Spread cell to cover the whole row. | ||
table.modify((4, 0), Span::column(0)); | ||
|
||
// Spread cell to cover the whole row. | ||
table.modify((5, 1), Span::column(0)); | ||
|
||
// Spread cell to cover the whole row. | ||
table.modify((6, 2), Span::column(0)); | ||
|
||
// Set a default span for a cell, | ||
// Essentially removing a span setting for it. | ||
table.modify((4, 0), Span::column(1)); | ||
|
||
// Correct the style to look good | ||
table.with(BorderSpanCorrection); | ||
table.with(Alignment::center()); | ||
|
||
println!("{table}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! [COMMENTED] A list of examples for a span use. | ||
use tabled::{ | ||
settings::{style::BorderSpanCorrection, Alignment, Span, Style}, | ||
Table, | ||
}; | ||
|
||
fn main() { | ||
let data = [ | ||
(1, 2, 3, 5, (6, 7, 8)), | ||
(9, 10, 11, 12, (13, 14, 15)), | ||
(16, 17, 18, 19, (20, 21, 22)), | ||
(23, 24, 25, 26, (27, 28, 29)), | ||
]; | ||
let mut table = Table::new(data); | ||
|
||
table.with(Style::modern_rounded()); | ||
|
||
// Here we show how original table looks. | ||
println!("{table}"); | ||
|
||
// Then there's a list of Span appliences and it's affects. | ||
|
||
// Spread cell by 1 row to the right. | ||
table.modify((0, 0), Span::row(2)); | ||
|
||
// Spread cell all the way to the right, | ||
// Which essentially covers all columns. | ||
table.modify((0, 1), Span::row(isize::MAX)); | ||
|
||
// Spread cell by 1 row to the top. | ||
table.modify((1, 2), Span::row(-1)); | ||
|
||
// Spread cell all the way to the top. | ||
table.modify((2, 3), Span::row(isize::MIN)); | ||
|
||
// Spread cell to cover the whole column. | ||
table.modify((0, 4), Span::row(0)); | ||
|
||
// Spread cell to cover the whole column. | ||
table.modify((1, 5), Span::row(0)); | ||
|
||
// Spread cell to cover the whole column. | ||
table.modify((2, 6), Span::row(0)); | ||
|
||
// Set a default span for a cell, | ||
// Essentially removing a span setting for it. | ||
table.modify((0, 4), Span::row(1)); | ||
|
||
// Correct the style to look good | ||
table.with(BorderSpanCorrection); | ||
table.with(Alignment::center_vertical()); | ||
|
||
println!("{table}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.