Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TableCell

Layer: cell · Path: src/cells/table_cell.rs · Exports: table_cell::{CellAlign, TableCell}

One cell of a table: a container that places its content (text by default, or an arbitrary widget) inside the column it is handed. A cell and a header are the same container — they differ chiefly in text weight (header = label_strong). Padding and alignment are token-driven; optionally a leading status dot (ColorSwatch) precedes the content. Carries a lifetime 'a because custom may borrow.

Design

  • Purpose / when to use — Building block for the Table organism (and ad-hoc fixed-width row layouts). Use text(...) for the common case, custom(...) to embed any widget.

  • Anatomy — A ui.with_layout(...) block: leading core::SPACE_2 pad, optional circular ColorSwatch status dot + core::SPACE_1 gap, then the content — a Text atom (weight/muted per flags) or the custom closure’s widget.

  • Variants / states

    ModifierEffect
    text(s)text content (default)
    custom(add)arbitrary widget content
    header()Text::label_strong() (stronger weight)
    muted()Text::muted() foreground (text content only; ignored for custom)
    status(color)leading circular color dot, core::SPACE_2 diameter
    align: align(CellAlign) / center() / end()content alignment within the cell
  • Tokens / layout consumedcore::SPACE_2 (leading pad + status dot size), core::SPACE_1 (dot→content gap). See tokens.

CellAlign

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] — chooses the cell’s egui Layout:

VariantLayout
Start (default)Layout::left_to_right(Align::Center)
CenterLayout::centered_and_justified(Direction::LeftToRight)
EndLayout::right_to_left(Align::Center)

API

MethodSignatureEffect
texttext(text: impl Into<String>) -> SelfText cell (the default content kind).
customcustom(add: impl FnMut(&mut Ui) + 'a) -> SelfCell holding an arbitrary widget via the closure.
headerheader(self) -> SelfRender as a header (strong text weight).
alignalign(self, align: CellAlign) -> SelfSet horizontal alignment.
centercenter(self) -> SelfShorthand for align(CellAlign::Center).
endend(self) -> SelfShorthand for align(CellAlign::End).
statusstatus(self, color: Color32) -> SelfLeading status dot in color.
mutedmuted(self) -> SelfMuted text foreground (text cells only).
showshow(self, ui: &mut Ui) -> ResponseFill the column cell it is given; returns the layout block Response.

Usage

#![allow(unused)]
fn main() {
use ouroboros_ui::cells::{TableCell, CellAlign};

TableCell::text("Name").header().show(ui);          // header cell
TableCell::text("2.1 MB").end().show(ui);           // right-aligned value
TableCell::text("ref").status(theme.success).show(ui); // leading status dot
}
#![allow(unused)]
fn main() {
// realistic — building rows for the Table organism (see TableRow)
use ouroboros_ui::cells::{TableCell, TableRow};

TableRow::new([
    TableCell::text(&d.name),
    TableCell::text(&d.size).end(),
    TableCell::text(&d.status).status(color),
]);
}
#![allow(unused)]
fn main() {
// custom widget inside a cell
TableCell::custom(|ui| { Button::new("Open").show(ui); }).center().show(ui);
}

Composition

Composes the Text atom and (optionally) the ColorSwatch atom; custom cells embed whatever the closure adds. The cell never paints — alignment is an egui Layout, visuals come from the atoms. Enforced by tests/no_painter_in_molecules.rs.

Notes

  • muted() is ignored for custom content (only text honors it).
  • The cell fills the width it is handed; the surrounding column width is set by the Table organism (via egui_extras) — the cell itself does not size the column.
  • 'a lifetime: a custom closure may borrow from the surrounding scope, which propagates through TableRow<'a>.