add doc example

This commit is contained in:
René Rössler 2022-02-09 16:42:02 +01:00
parent 5ccfa1117e
commit 5adb99cfc2
2 changed files with 64 additions and 2 deletions

View file

@ -21,7 +21,33 @@ pub struct GridBuilder<'a> {
impl<'a> GridBuilder<'a> {
/// Create new grid builder
/// After adding size hints with `[Self::column]`/`[Self::columns]` the grid can be build with `[Self::horizontal]`/`[Self::vertical]`
///
/// After adding size hints with `[Self::column]`/`[Self::columns]` the grid can be build with `[Self::horizontal]`/`[Self::vertical]`.
///
/// ### Example
/// ```
/// # egui::__run_test_ui(|ui| {
/// use egui_extras::{GridBuilder, Size};
/// GridBuilder::new(ui)
/// .column(Size::RemainderMinimum(100.0))
/// .column(Size::Absolute(40.0))
/// .vertical(|mut grid| {
/// grid.grid(|builder| {
/// builder.sizes(Size::Remainder, 2).horizontal(|mut grid| {
/// grid.cell(|ui| {
/// ui.label("Top Left");
/// });
/// grid.cell(|ui| {
/// ui.label("Top Right");
/// });
/// });
/// });
/// grid.cell(|ui| {
/// ui.label("Fixed");
/// });
/// });
/// # });
/// ```
pub fn new(ui: &'a mut Ui) -> Self {
let sizing = Sizing::new();

View file

@ -1,7 +1,8 @@
//! 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.
//! Takes all available height, so if you want something below the table, put it in a grid.
use crate::{
layout::{CellSize, LineDirection},
sizing::Sizing,
@ -19,6 +20,41 @@ pub struct TableBuilder<'a> {
}
impl<'a> TableBuilder<'a> {
/// Build a table 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.
///
/// ### Example
/// ```
/// # egui::__run_test_ui(|ui| {
/// use egui_extras::{TableBuilder, Size};
/// TableBuilder::new(ui)
/// .column(Size::RemainderMinimum(100.0))
/// .column(Size::Absolute(40.0))
/// .header(20.0, |mut header| {
/// header.col(|ui| {
/// ui.heading("Growing");
/// });
/// header.col(|ui| {
/// ui.heading("Fixed");
/// });
/// })
/// .body(|mut body| {
/// body.row(30.0, |mut row| {
/// row.col(|ui| {
/// ui.label("first row growing cell");
/// });
/// row.col_clip(|ui| {
/// ui.button("action");
/// });
/// });
/// });
/// # });
/// ```
pub fn new(ui: &'a mut Ui) -> Self {
let sizing = Sizing::new();