render!() { /* proc-macro */ }
Expand description

Macro for rendering components.

Usage

This macro is meant to be used when returning from Component::render, and uses a SwiftUI-like syntax.

For example:

render! {
  VStack() {
    Section(title: "Top Section") {
      Text(text: "Hello")
    }

    Section(title: "Bottom Section") {
      Text(text: "World")
    }
  }
}

is rendering a VStack (with default parameters), and two children. The child components are Sections, each with their own Text child components.

Parameters

Parameters passed to components look like function arguments but are actually much closer to structure initialization. Like struct fields, they can be passed in any order, and they require the field name, unless the parameter and value are the same identifier. Unlike struct fields, you can omit parameters, as any omitted parameters are implicitly passed in with their default values.

Children

Children to a component come after the component surrounded by braces ({ ... }). Like parameters, children are optional, but are only valid for components that accept them (for example Text accepts no children, but Section does).

Children are passed as arrays ([AnyComponent; N]), so components specify exactly how many children they take in. Some components, like VStack and HStack take in a variable number of children, while some, like Section, only accept a single child component.