Skip to main content

Module layout

Module layout 

Source
Expand description

Rows, grids and flows: UiPop::row and UiPop::grid place cells on tracks, align them on their text’s baseline, and leave gaps of Space only; UiPop::flow places whole cells left to right and wraps them.

A track is sized by its content (Track::CONTENT), by a share of what is left (Track::fr), by a share of the container (Track::percent) or in lines of body text (Track::em), each between an optional Length minimum and maximum.

use egui_pop_core::theme::{self, ThemeSpec};
use egui_pop_core::ui::{Align, Flow, Grid, Length, Row, Space, Track, UiPop};

let ctx = egui::Context::default();
theme::install(&ctx, &ThemeSpec::new("pop-dark"));
let mut name = String::from("IMG_0001");
let mut out = ctx.run_ui(Default::default(), |ui| {
    // A line: a title, a field taking what is left (between 8 and 24
    // em), a button sized to its content, all on one baseline.
    let field = Track::fr(1.0).min(Length::Em(8.0)).max(Length::Em(24.0));
    ui.row(Row::new([Track::CONTENT, field, Track::CONTENT]), |r| {
        r.cell(|ui| ui.section_title("Name"));
        r.cell(|ui| ui.text_edit_singleline(&mut name));
        r.cell(|ui| ui.button("Rename"));
    });
    // Headers as wide as the widest, values take the rest; one column
    // when narrower than 30 em.
    let grid = Grid::new("details", [Track::CONTENT, Track::fr(1.0)])
        .fold_below(Length::Em(30.0));
    ui.grid(grid, |g| {
        g.header("Kind");
        g.cell(|ui| ui.label("Raw image"));
        g.header("Size");
        g.cell(|ui| ui.label("24 MB"));
    });
    // A button bar: buttons as wide as the widest, at the end.
    let bar = Row::new([Track::CONTENT; 2]).justify(Align::End).equal_widths();
    ui.row(bar, |r| {
        r.cell(|ui| ui.button("Cancel"));
        r.cell(|ui| ui.button("OK"));
    });
    // Actions that wrap whole when narrow, never inside a button.
    ui.flow(Flow::new(), |f| {
        f.cell(|ui| ui.button("Save as template"));
        f.cell(|ui| ui.add_enabled_ui(false, |ui| ui.button("Delete")).inner);
    });
    ui.space_role(Space::Group);
});
out.textures_delta.clear();

How it measures: egui places each widget once, so cells are placed from the sizes and baselines they had on the previous pass (kept in the context’s temporary memory under the layout’s id). When they change, the layout asks egui to discard the pass and run another, as egui’s own Grid does; at rest nothing is measured twice. A cell’s baseline is the first baseline of the text it paints; a cell painting no text is taken as a single-line widget with body text centred in it, as egui draws its own.

Structs§

Cells
The cells of a Row or a Grid, filled in order.
Flow
Whole cells left to right, wrapping to the next line those that do not fit, shown by UiPop::flow: a bar of action buttons that keeps each button on one line in a narrow container. Cells are Space::Inline apart, lines Space::Inline apart, each cell centred on its line.
FlowCells
The cells of a Flow, placed in order.
Grid
Lines of cells on shared tracks, shown by UiPop::grid: cells fill the tracks left to right, a line per track count. Columns are Space::Group apart, lines Space::Inline.
Row
One line of cells, one per track, shown by UiPop::row. Cells are Space::Inline apart and on one baseline unless told otherwise.
Track
The width of a column of a Row or a Grid.

Enums§

Align
How cells sit in their line (Row::align, Grid::align), or a line in its container (Row::justify).
Length
A length for a track’s size, minimum or maximum, never in points.