grid

Macro grid 

Source
macro_rules! grid {
    ( $( ($cc:expr, $rr:expr) => $ee:expr ),* ) => { ... };
    ( $( ($cc:expr, $rr:expr) => $ee:expr ),+ , ) => { ... };
}
Expand description

Make a Grid widget

Constructs a table with auto-determined number of rows and columns. Cells may overlap, in which case behaviour is identical to float!: the first declared item is on top.

§Syntax

Collection :
   collection! [ ItemArms? ]

ItemArms :
   (ItemArm ,)* ItemArm ,?

ItemArm :
   ( Column , Row ) => Item

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

Here, Column and Row are selected via an index (from 0), a range of indices, or a start + increment. For example, 2 = 2..+1 = 2..3 = 2..=2 while 5..+2 = 5..7 = 5..=6.

§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 an align or pack method call
  • 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..2, 1) => "three",
};