Trait text_grid::RowWrite

source ·
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.

Required Methods§

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 |

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§

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 |

Implementors§