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,
minimum: 60.0,
})
.size(Size::Absolute(14.0))
.vertical(|mut grid| {
grid.cell(|ui| {
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_extras::{Padding, Size, TableBuilder};
use egui_extras::{GridBuilder, Padding, Size, TableBuilder};
/// Shows off a table with dynamic layout
#[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) {
ui.checkbox(&mut self.virtual_scrool, "Virtual scroll demo");
// TODO: Fix table as a padding smaller than 16 grows the window
TableBuilder::new(ui, Padding::new(3.0, 16.0))
.striped(true)
.column(Size::Absolute(120.0))
.column(Size::RemainderMinimum(180.0))
.column(Size::Absolute(100.0))
.header(20.0, |mut header| {
header.col(|ui| {
ui.label(RichText::new("Left").heading());
});
header.col(|ui| {
ui.label(RichText::new("Middle").heading());
});
header.col(|ui| {
ui.label(RichText::new("Right").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));
});
// The table is inside a grid as its container would otherwise grow slowly as it takes all available height
GridBuilder::new(ui, Padding::new(0.0, 0.0))
.size(Size::Remainder)
.size(Size::Absolute(14.0))
.vertical(|mut grid| {
grid.cell(|ui| {
// TODO: Fix table as a padding smaller than 16 grows the window
TableBuilder::new(ui, Padding::new(3.0, 16.0))
.striped(true)
.column(Size::Absolute(120.0))
.column(Size::RemainderMinimum(180.0))
.column(Size::Absolute(100.0))
.header(20.0, |mut header| {
header.col(|ui| {
ui.label(RichText::new("Left").heading());
});
} else {
for i in 0..100 {
let height = match i % 8 {
0 => 25.0,
4 => 30.0,
_ => 20.0,
};
body.row(height, |mut row| {
header.col(|ui| {
ui.label(RichText::new("Middle").heading());
});
header.col(|ui| {
ui.label(RichText::new("Right").heading());
});
})
.body(|mut body| {
if self.virtual_scrool {
body.rows(20.0, 100_000, |index, mut row| {
row.col(|ui| {
ui.label(format!("{}", i));
ui.label(format!("{}", index));
});
row.col(|ui| {
ui.add(
Label::new(
format!("Normal scroll, each row can have a different height. Height: {}", height),
)
.wrap(false),
Label::new("virtual scroll, easily with thousands of rows!")
.wrap(false),
);
});
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
/// 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)
where
F: for<'b> FnOnce(Grid<'a, 'b>),
@ -62,6 +63,7 @@ impl<'a> GridBuilder<'a> {
}
/// 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)
where
F: for<'b> FnOnce(Grid<'a, 'b>),

View file

@ -1,6 +1,7 @@
/// Table view with (optional) fixed header and scrolling body.
/// 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 |
/// Takes all available height, so if you want something below the table, put it in a grid.
use crate::{
layout::{CellSize, LineDirection},
sizing::Sizing,