Skip to main content

list

Macro list 

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

Make a List widget

§Syntax

Collection :
   list! [ Items? ]

Items :
   (Item ,)* Item ,?

§Stand-alone usage

When used as a stand-alone macro, list! [/* ... */] is just syntactic sugar for List::new(kas::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 list! 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

When called within widget layout syntax, list! may be evaluated as a recursive macro and the result does not have a specified type, except that methods map_any, align, pack, with_stretch and with_direction are supported via emulation. In this case, calling with_direction is required. Note that the argument passed to with_direction is expanded at the use site, so for example .with_direction(self.dir) will read self.dir whenever layout is computed.

In this case, Item is evaluated using 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::list! ["one", "two"]
    .with_direction(kas::dir::Left);