State, records and bindings

State

All dialog, screen, and component property declarations are mutable state, including those with defaults. The application sets them during construction and afterwards through generated setters:

qml
component PriceTab : Item {
    property bool selected
    Text labelText {
        color: selected ? theme.interactiveColor : theme.textColor
    }
    Rect bar { visible: selected; size: labelText.width + 30, 6 }
}
cpp
tab->setSelected(i == index);

What follows a change:

Equal values: A setter given the state's existing value does nothing (records and lists are compared with ==). The application can therefore set system information every second, for example; only changed content is rebuilt.

What does not follow: One-time properties (name, source, onTap, pressSink, spin) and constants (const). A reevaluated group also resets its geometry; elements moved by the application itself (such as a scroll thumb) should therefore have no position in the .aura file.

Named states (state) and when

A state with fixed values (like QML states), plus blocks that change properties while a condition holds:

qml
component SaveButton : Rect {
    state mode: idle, busy, done           // der erste Wert ist der Start
    color: theme.mainColor

    Text label { text: tr("ui_save", "Speichern") }
    Svg spinner { source: "icon_spinner.svg"; visible: false; spin: 1000 }

    when mode == busy {
        opacity: 0.5                        // das Element mit dem when
        // ein Element darin, über seine ID
        label.text: tr("ui_saving", "Speichert …")
        spinner.visible: true
    }
    when root.pressed { color: theme.mainColorDark }
}

Animations (animate, enter)

Changing properties move smoothly to their new values rather than jumping; appearing elements can fade in:

qml
Rect panel {
    opacity: 1
    // Eigenschaft, ms, Easing (ohne: outQuad)
    animate: opacity 200, color 150 linear
    when mode == busy { opacity: 0.5; color: theme.lightGrey }
}
if view == thanks {
    Rect thanks {
        enter: opacity 0 300        // beim Erscheinen von 0 zum Wert
        exit: opacity 0 300         // beim Abbau zu 0, dann weg
    }
}

Previews

A preview shows a dialog, screen or component with preset values in the preview tools (VS Code, aura-view), similar to SwiftUI's #Preview:

qml
preview "Busy" for SaveButton {
    mode: busy
}
preview "Zwei Produkte" for ShoppingCart {
    lines: [
        { description: "test-Notebook", quantity: 12,
          unitPrice: "0,29 €", linePrice: "3,48 €" },
        { description: "test-Pencil", quantity: 1,
          unitPrice: "9,99 €", linePrice: "9,99 €" }
    ]
}

Records

A record describes application data made up of several values. A list of records replaces the loop in which the application previously built a component for each entry:

qml
// cart_screen.aura
record CartLine {
    string description
    string discount
    int quantity
    string unitPrice
    string linePrice
}

Screen ShoppingCart {
    property CartLine[] lines
    signal edit(int index)
    signal remove(int index)

    Column productRows {
        repeat line, i in lines {
            CartRow row {
                index: i
                line: line
                onEdit: edit(i)
                onRemove: remove(i)
            }
        }
    }
}

component CartRow : Rect {
    property int index
    property CartLine line
    signal edit
    signal remove
    Text { text: line.description }
    if line.discount != "" { Text { text: line.discount } }
}
cpp
std::vector<views::CartLine> lines{
    {"Notebook", "", 2, "3.00", "6.00"}
};
auto ui = views::ShoppingCart::build(frame, ctx, {lines});
ui->edit = [](double index) { /* handle the selected row */ };

Rebuilding repeat and if

If a repeat list or an if condition references state, changing that state rebuilds the block:

cpp
ui->setLines(lines); // update the record list

Lifetime

Dependencies (aura::Bindings) are attached to the root node; the struct holds only a weak reference. A setter called after closing does nothing.

Documentation source: docs/aura.md · Download Markdown

Search for topics, widgets or APIs.