Skip to main content

grid

Macro grid 

Source
macro_rules! grid {
    ( $($tt:tt)* ) => { ... };
}
Expand description

Make a Grid widget

Constructs a table with auto-determined number of rows and columns.

Cells are allowed to overlap but are not guaranteed to draw correctly in this case. The first declared widget of the overlap is “on top”.

§Syntax

Collection :
   grid! { ItemArms? }

ItemArms :
   (ItemArm ,)* ItemArm ,?

ItemArm :
   Cell | RowMacro | ColumnMacro

Cell :
   ( Column , Row ) => Item

Column, Row :
   LitInt | ( LitInt ..= LitInt )

RowMacro :
&npsb;  row! [ (Item , | _ ,)* Item ]

ColumnMacro :
&npsb;  column! [ (Item , | _ ,)* Item ]

Here, Column and Row are selected via an index (from 0) or an inclusive range, for example 2 or 2..=3.

A row! macro resolves to a list of cells whose column index is one larger than maximum prior column index and whose row indices count from 0. As a special case, _ may be used to skip a cell (infer an empty cell). A column! macro functions similarly.

§Stand-alone usage

When used as a stand-alone macro, grid! { /* ... */ } is just syntactic sugar for Grid::new(kas::cell_collection! { /* ... */ }).

In this case, Item may be:

  • A string literal (interpreted as a label widget), optionally followed by any of the following method calls: align, pack, with_stretch
  • An expression yielding an object implementing Widget<Data = _A>

In case all Item instances are a string literal, the data type of the grid! widget will be (); otherwise the data type of the widget is _A where _A is a generic type parameter of the widget.

§Usage within widget layout syntax

In this case, Item uses widget layout syntax. This is broadly similar to the above with a couple of exceptions:

  • Supported layout macros do not need to be imported to the module scope
  • An Item may be a #[widget] field of the widget

§Example

let my_widget = kas_widgets::grid! {
    (0, 0) => "one",
    (1, 0) => "two",
    (0..=1, 1) => "three",
};