add sourcecode links, document slow growing

This commit is contained in:
René Rössler 2022-02-09 12:02:19 +01:00
parent 10c51364c5
commit ae71f91f8c
4 changed files with 70 additions and 48 deletions

View file

@ -32,6 +32,7 @@ impl super::View for GridDemo {
relative: 0.5, relative: 0.5,
minimum: 60.0, minimum: 60.0,
}) })
.size(Size::Absolute(14.0))
.vertical(|mut grid| { .vertical(|mut grid| {
grid.cell(|ui| { grid.cell(|ui| {
ui.painter() ui.painter()
@ -99,6 +100,11 @@ impl super::View for GridDemo {
}); });
}); });
}); });
grid.cell(|ui| {
ui.vertical_centered(|ui| {
ui.add(crate::__egui_github_link_file!());
});
});
}); });
} }
} }

View file

@ -1,5 +1,5 @@
use egui::{Label, RichText}; use egui::{Label, RichText};
use egui_extras::{Padding, Size, TableBuilder}; use egui_extras::{GridBuilder, Padding, Size, TableBuilder};
/// Shows off a table with dynamic layout /// Shows off a table with dynamic layout
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@ -29,64 +29,77 @@ impl super::View for TableDemo {
fn ui(&mut self, ui: &mut egui::Ui) { fn ui(&mut self, ui: &mut egui::Ui) {
ui.checkbox(&mut self.virtual_scrool, "Virtual scroll demo"); ui.checkbox(&mut self.virtual_scrool, "Virtual scroll demo");
// TODO: Fix table as a padding smaller than 16 grows the window // The table is inside a grid as its container would otherwise grow slowly as it takes all available height
TableBuilder::new(ui, Padding::new(3.0, 16.0)) GridBuilder::new(ui, Padding::new(0.0, 0.0))
.striped(true) .size(Size::Remainder)
.column(Size::Absolute(120.0)) .size(Size::Absolute(14.0))
.column(Size::RemainderMinimum(180.0)) .vertical(|mut grid| {
.column(Size::Absolute(100.0)) grid.cell(|ui| {
.header(20.0, |mut header| { // TODO: Fix table as a padding smaller than 16 grows the window
header.col(|ui| { TableBuilder::new(ui, Padding::new(3.0, 16.0))
ui.label(RichText::new("Left").heading()); .striped(true)
}); .column(Size::Absolute(120.0))
header.col(|ui| { .column(Size::RemainderMinimum(180.0))
ui.label(RichText::new("Middle").heading()); .column(Size::Absolute(100.0))
}); .header(20.0, |mut header| {
header.col(|ui| { header.col(|ui| {
ui.label(RichText::new("Right").heading()); ui.label(RichText::new("Left").heading());
});
})
.body(|mut body| {
if self.virtual_scrool {
body.rows(20.0, 100_000, |index, mut row| {
row.col(|ui| {
ui.label(format!("{}", index));
});
row.col(|ui| {
ui.add(
Label::new("virtual scroll, easily with thousands of rows!")
.wrap(false),
);
});
row.col(|ui| {
ui.label(format!("{}", index));
});
}); });
} else { header.col(|ui| {
for i in 0..100 { ui.label(RichText::new("Middle").heading());
let height = match i % 8 { });
0 => 25.0, header.col(|ui| {
4 => 30.0, ui.label(RichText::new("Right").heading());
_ => 20.0, });
}; })
body.row(height, |mut row| { .body(|mut body| {
if self.virtual_scrool {
body.rows(20.0, 100_000, |index, mut row| {
row.col(|ui| { row.col(|ui| {
ui.label(format!("{}", i)); ui.label(format!("{}", index));
}); });
row.col(|ui| { row.col(|ui| {
ui.add( ui.add(
Label::new( Label::new("virtual scroll, easily with thousands of rows!")
format!("Normal scroll, each row can have a different height. Height: {}", height), .wrap(false),
)
.wrap(false),
); );
}); });
row.col(|ui| { row.col(|ui| {
ui.label(format!("{}", i)); ui.label(format!("{}", index));
}); });
}); });
} else {
for i in 0..100 {
let height = match i % 8 {
0 => 25.0,
4 => 30.0,
_ => 20.0,
};
body.row(height, |mut row| {
row.col(|ui| {
ui.label(format!("{}", i));
});
row.col(|ui| {
ui.add(
Label::new(
format!("Normal scroll, each row can have a different height. Height: {}", height),
)
.wrap(false),
);
});
row.col(|ui| {
ui.label(format!("{}", i));
});
});
}
} }
} });
}); });
grid.cell(|ui| {
ui.vertical_centered(|ui| {
ui.add(crate::__egui_github_link_file!());
});
});
});
} }
} }

View file

@ -44,6 +44,7 @@ impl<'a> GridBuilder<'a> {
} }
/// Build horizontal grid /// Build horizontal grid
/// Takes the available horizontal width, so there can't be anything right of the grid or the container will grow slowly!
pub fn horizontal<F>(self, grid: F) pub fn horizontal<F>(self, grid: F)
where where
F: for<'b> FnOnce(Grid<'a, 'b>), F: for<'b> FnOnce(Grid<'a, 'b>),
@ -62,6 +63,7 @@ impl<'a> GridBuilder<'a> {
} }
/// Build vertical grid /// Build vertical grid
/// Takes the full available vertical height, so there can't be anything below of the grid or the container will grow slowly!
pub fn vertical<F>(self, grid: F) pub fn vertical<F>(self, grid: F)
where where
F: for<'b> FnOnce(Grid<'a, 'b>), F: for<'b> FnOnce(Grid<'a, 'b>),

View file

@ -1,6 +1,7 @@
/// Table view with (optional) fixed header and scrolling body. /// Table view with (optional) fixed header and scrolling body.
/// Cell widths are precalculated with given size hints so we can have tables like this: /// Cell widths are precalculated with given size hints so we can have tables like this:
/// | fixed size | all available space/minimum | 30% of available width | fixed size | /// | fixed size | all available space/minimum | 30% of available width | fixed size |
/// Takes all available height, so if you want something below the table, put it in a grid.
use crate::{ use crate::{
layout::{CellSize, LineDirection}, layout::{CellSize, LineDirection},
sizing::Sizing, sizing::Sizing,