add more documentation

This commit is contained in:
René Rössler 2022-01-07 17:26:43 +01:00
parent 4f6f871f29
commit a346bcf8a3
3 changed files with 37 additions and 1 deletions

View file

@ -14,6 +14,8 @@ pub struct HorizontalGridBuilder<'a> {
}
impl<'a> HorizontalGridBuilder<'a> {
/// Create new grid builder for horizontal grid
/// After adding size hints with [Self::column]/[Self::columns] the grid can be build with [Self::build]
pub(crate) fn new(ui: &'a mut Ui, padding: Padding) -> Self {
let layouter = Sizing::new(
ui.available_rect_before_wrap().width() - 2.0 * padding.outer,
@ -27,11 +29,13 @@ impl<'a> HorizontalGridBuilder<'a> {
}
}
/// Add size hint for column
pub fn column(mut self, size: Size) -> Self {
self.sizing.add_size(size);
self
}
/// Add size hint for columns [count] times
pub fn columns(mut self, size: Size, count: usize) -> Self {
for _ in 0..count {
self.sizing.add_size(size.clone());
@ -39,6 +43,7 @@ impl<'a> HorizontalGridBuilder<'a> {
self
}
/// Build grid
pub fn build<F>(self, horizontal_grid: F)
where
F: for<'b> FnOnce(HorizontalGrid<'a, 'b>),
@ -61,6 +66,7 @@ pub struct HorizontalGrid<'a, 'b> {
}
impl<'a, 'b> HorizontalGrid<'a, 'b> {
/// Add empty cell
pub fn empty(&mut self) {
assert!(
!self.widths.is_empty(),
@ -87,10 +93,12 @@ impl<'a, 'b> HorizontalGrid<'a, 'b> {
);
}
/// Add cell, content is clipped
pub fn cell(&mut self, add_contents: impl FnOnce(&mut Ui)) {
self._cell(true, add_contents);
}
/// Add cell, content is not clipped
pub fn cell_noclip(&mut self, add_contents: impl FnOnce(&mut Ui)) {
self._cell(false, add_contents);
}
@ -105,11 +113,12 @@ impl<'a, 'b> HorizontalGrid<'a, 'b> {
horizontal_grid_builder(HorizontalGridBuilder::new(ui, padding));
});
}
/// Add horizontal grid as cell, content is clipped
pub fn horizontal(&mut self, horizontal_grid_builder: impl FnOnce(HorizontalGridBuilder)) {
self._horizontal(true, horizontal_grid_builder)
}
/// Add horizontal grid as cell, content is not clipped
pub fn horizontal_noclip(
&mut self,
horizontal_grid_builder: impl FnOnce(HorizontalGridBuilder),
@ -128,10 +137,12 @@ impl<'a, 'b> HorizontalGrid<'a, 'b> {
});
}
/// Add vertical grid as cell, content is clipped
pub fn vertical(&mut self, vertical_grid_builder: impl FnOnce(VerticalGridBuilder)) {
self._vertical(true, vertical_grid_builder);
}
/// Add vertical grid as cell, content is not clipped
pub fn vertical_noclip(&mut self, vertical_grid_builder: impl FnOnce(VerticalGridBuilder)) {
self._vertical(false, vertical_grid_builder);
}

View file

@ -10,6 +10,8 @@ pub struct VerticalGridBuilder<'a> {
}
impl<'a> VerticalGridBuilder<'a> {
/// Create new grid builder for vertical grid
/// After adding size hints with [Self::row]/[Self::rows] the grid can be build with [Self::build]
pub(crate) fn new(ui: &'a mut Ui, padding: Padding) -> Self {
let layouter = Sizing::new(
ui.available_rect_before_wrap().height() - 2.0 * padding.outer,
@ -23,11 +25,13 @@ impl<'a> VerticalGridBuilder<'a> {
}
}
/// Add size hint for row
pub fn row(mut self, size: Size) -> Self {
self.sizing.add_size(size);
self
}
/// Add size hint for rows [count] times
pub fn rows(mut self, size: Size, count: usize) -> Self {
for _ in 0..count {
self.sizing.add_size(size.clone());
@ -35,6 +39,7 @@ impl<'a> VerticalGridBuilder<'a> {
self
}
/// Build grid
pub fn build<F>(self, vertical_grid: F)
where
F: for<'b> FnOnce(VerticalGrid<'a, 'b>),
@ -61,6 +66,7 @@ pub struct VerticalGrid<'a, 'b> {
}
impl<'a, 'b> VerticalGrid<'a, 'b> {
/// Add empty cell
pub fn empty(&mut self) {
assert!(
!self.heights.is_empty(),
@ -87,10 +93,12 @@ impl<'a, 'b> VerticalGrid<'a, 'b> {
);
}
/// Add cell, content is clipped
pub fn cell(&mut self, add_contents: impl FnOnce(&mut Ui)) {
self._cell(true, add_contents);
}
/// Add cell, content is not clipped
pub fn cell_noclip(&mut self, add_contents: impl FnOnce(&mut Ui)) {
self._cell(false, add_contents);
}
@ -106,10 +114,12 @@ impl<'a, 'b> VerticalGrid<'a, 'b> {
});
}
/// Add horizontal grid as cell, content is clipped
pub fn horizontal(&mut self, horizontal_grid_builder: impl FnOnce(HorizontalGridBuilder)) {
self._horizontal(true, horizontal_grid_builder)
}
/// Add horizontal grid as cell, content is not clipped
pub fn horizontal_noclip(
&mut self,
horizontal_grid_builder: impl FnOnce(HorizontalGridBuilder),
@ -128,10 +138,12 @@ impl<'a, 'b> VerticalGrid<'a, 'b> {
});
}
/// Add vertical grid as cell, content is clipped
pub fn vertical(&mut self, vertical_grid_builder: impl FnOnce(VerticalGridBuilder)) {
self._vertical(true, vertical_grid_builder);
}
/// Add vertical grid as cell, content is not clipped
pub fn vertical_noclip(&mut self, vertical_grid_builder: impl FnOnce(VerticalGridBuilder)) {
self._vertical(false, vertical_grid_builder);
}

View file

@ -34,21 +34,25 @@ impl<'a> TableBuilder<'a> {
}
}
/// Enable scrollview in body (default: true)
pub fn scroll(mut self, scroll: bool) -> Self {
self.scroll = scroll;
self
}
/// Enable striped row background (default: false)
pub fn striped(mut self, striped: bool) -> Self {
self.striped = striped;
self
}
/// Add size hint for column
pub fn column(mut self, width: Size) -> Self {
self.sizing.add_size(width);
self
}
/// Add size hint for column [count] times
pub fn columns(mut self, size: Size, count: usize) -> Self {
for _ in 0..count {
self.sizing.add_size(size.clone());
@ -56,6 +60,7 @@ impl<'a> TableBuilder<'a> {
self
}
/// Create a header row which always stays visible and at the top
pub fn header(self, height: f32, header: impl FnOnce(TableRow<'_, '_>)) -> Table<'a> {
let widths = self.sizing.into_lengths();
let ui = self.ui;
@ -82,6 +87,7 @@ impl<'a> TableBuilder<'a> {
}
}
/// Create table body without a header row
pub fn body<F>(self, body: F)
where
F: for<'b> FnOnce(TableBody<'b>),
@ -108,6 +114,7 @@ pub struct Table<'a> {
}
impl<'a> Table<'a> {
/// Create table body after adding a header row
pub fn body<F>(self, body: F)
where
F: for<'b> FnOnce(TableBody<'b>),
@ -144,6 +151,8 @@ pub struct TableBody<'a> {
}
impl<'a> TableBody<'a> {
/// Add rows with same height
/// Is a lot more performant than adding each individual row as non visible rows must not be rendered
pub fn rows(mut self, height: f32, rows: usize, mut row: impl FnMut(usize, TableRow)) {
let delta = self.layout.current_y() - self.start_y;
let mut start = 0;
@ -198,6 +207,7 @@ impl<'a> TableBody<'a> {
}
}
/// Add row with individual height
pub fn row(&mut self, height: f32, row: impl FnOnce(TableRow<'a, '_>)) {
row(TableRow {
layout: &mut self.layout,
@ -220,6 +230,7 @@ pub struct TableRow<'a, 'b> {
}
impl<'a, 'b> TableRow<'a, 'b> {
/// Check if row was clicked
pub fn clicked(&self) -> bool {
self.clicked
}
@ -248,10 +259,12 @@ impl<'a, 'b> TableRow<'a, 'b> {
response
}
/// Add column, content is clipped
pub fn col(&mut self, add_contents: impl FnOnce(&mut Ui)) -> Response {
self._col(true, add_contents)
}
/// Add column, content is not clipped
pub fn col_noclip(&mut self, add_contents: impl FnOnce(&mut Ui)) -> Response {
self._col(false, add_contents)
}