Skip to main content

euv_ui/component/table/view/
struct.rs

1use super::*;
2
3/// The horizontal alignment of a table column and of every cell in it.
4///
5/// Drives the `c_euv_table_cell_center` / `c_euv_table_cell_right`
6/// modifier stacked on top of the shared `c_euv_table_cell` base, so a
7/// column's alignment is expressed in one place instead of being repeated
8/// per cell.
9#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub enum EuvTableAlign {
11    /// Flush-left content; renders the base `c_euv_table_cell` alone.
12    #[default]
13    Left,
14    /// Horizontally centred content.
15    Center,
16    /// Flush-right content, the usual home for numeric columns.
17    Right,
18}
19
20/// One column of the [`euv_table`] component.
21///
22/// `key` is the stable identity used for the column's own diffing key; it
23/// is not rendered, so a caller can pass a short slug (`"qty"`) while
24/// `label` carries the visible uppercase heading.
25#[derive(Clone, Copy, Debug, Default)]
26pub struct EuvTableColumn {
27    /// The stable column identity, used as the diffing key only.
28    pub key: &'static str,
29    /// The visible column heading text.
30    pub label: &'static str,
31    /// The horizontal alignment applied to this column's cells.
32    pub align: EuvTableAlign,
33}
34
35/// One body row of the [`euv_table`] component.
36///
37/// `cells` is positional: cell `i` is rendered under `columns[i]`, and a
38/// row shorter than the column list simply renders fewer cells. Extra
39/// cells beyond the column list are dropped, so a ragged row can never
40/// escape the header.
41#[derive(Clone, Debug, Default)]
42pub struct EuvTableRow {
43    /// The cell texts, positionally matched to [`EuvTableProps::columns`].
44    pub cells: Vec<&'static str>,
45    /// The stable row identity, used as the diffing key only.
46    pub key: &'static str,
47}
48
49/// Props for the [`euv_table`] component.
50///
51/// Defines the strongly-typed interface for a bordered data table with a
52/// header, a zebra mode, and an optional caption.
53#[derive(Clone, CustomDebug, Default)]
54pub struct EuvTableProps {
55    /// The column definitions driving the header and each cell's alignment.
56    pub columns: Vec<EuvTableColumn>,
57    /// The body rows; an empty list renders an empty `<tbody>`.
58    pub rows: Vec<EuvTableRow>,
59    /// The caption rendered under the table (skipped when empty).
60    pub caption: &'static str,
61    /// Whether every other row gets the `c_euv_table_row_zebra` fill.
62    pub zebra: bool,
63}