pub trait RowWrite<'a, S: 'a + ?Sized> {
fn group(&mut self, header: impl CellSource, f: impl FnOnce(&mut Self));
fn content<T: CellSource>(&mut self, f: impl FnOnce(&'a S) -> T);
fn column<T: CellSource>(
&mut self,
header: impl CellSource,
f: impl FnOnce(&'a S) -> T
) { ... }
}
Expand description
Used to define column information within RowSource::fmt_row
.
- Use
Self::column
to create column. - Use
Self::group
to create multi level header. - Use
Self::content
to create shared header columns.
Required Methods§
sourcefn group(&mut self, header: impl CellSource, f: impl FnOnce(&mut Self))
fn group(&mut self, header: impl CellSource, f: impl FnOnce(&mut Self))
Define column group. Used to create multi row header.
- header : Column group header’s cell. If horizontal alignment is not specified, it is set to the center.
- f : A function to define group contents.
Examples
use text_grid::*;
struct RowData {
a: u32,
b_1: u32,
b_2: u32,
}
impl RowSource for RowData {
fn fmt_row<'a>(w: &mut impl RowWrite<'a, Self>) {
w.column("a", |s| s.a);
w.group("b", |w| {
w.column("1", |s| s.b_1);
w.column("2", |s| s.b_2);
});
}
}
let mut g = Grid::new();
g.push_row(&RowData {
a: 300,
b_1: 10,
b_2: 20,
});
g.push_row(&RowData {
a: 300,
b_1: 1,
b_2: 500,
});
print!("{}", g);
a | b |
-----|----------|
| 1 | 2 |
-----|----|-----|
300 | 10 | 20 |
300 | 1 | 500 |
sourcefn content<T: CellSource>(&mut self, f: impl FnOnce(&'a S) -> T)
fn content<T: CellSource>(&mut self, f: impl FnOnce(&'a S) -> T)
Define column content. Used to create shared header column.
- f : A function to obtain CellSource from RowSource.
Examples
use text_grid::*;
struct RowData {
a: u32,
b_1: u32,
b_2: u32,
}
impl RowSource for RowData {
fn fmt_row<'a>(w: &mut impl RowWrite<'a, Self>) {
w.column("a", |s| s.a);
w.group("b", |w| {
w.content(|s| s.b_1);
w.content(|_| " ");
w.content(|s| s.b_2);
});
}
}
let mut g = Grid::new();
g.push_row(&RowData {
a: 300,
b_1: 10,
b_2: 20,
});
g.push_row(&RowData {
a: 300,
b_1: 1,
b_2: 500,
});
print!("{}", g);
a | b |
-----|--------|
300 | 10 20 |
300 | 1 500 |
Provided Methods§
sourcefn column<T: CellSource>(
&mut self,
header: impl CellSource,
f: impl FnOnce(&'a S) -> T
)
fn column<T: CellSource>(
&mut self,
header: impl CellSource,
f: impl FnOnce(&'a S) -> T
)
Define column.
- header : Column header’s cell. If horizontal alignment is not specified, it is set to the center.
- f : A function to obtain CellSource from RowSource.
Examples
use text_grid::*;
struct RowData {
a: u32,
b: u32,
}
impl RowSource for RowData {
fn fmt_row<'a>(w: &mut impl RowWrite<'a, Self>) {
w.column("a", |s| s.a);
w.column("b", |s| s.b);
}
}
let mut g = Grid::new();
g.push_row(&RowData { a: 300, b: 1 });
g.push_row(&RowData { a: 2, b: 200 });
print!("{}", g);
a | b |
-----|-----|
300 | 1 |
2 | 200 |