Skip to content

Structs and Enums

Define named structures using the struct keyword:

export struct Player {
name: string,
score: int,
}
export component Example {
in-out property<Player> player: { name: "Foo", score: 100 };
}
slint

The default value of a struct, is initialized with all its fields set to their default value.

Declare anonymous structures using { identifier1: type1, identifier2: type2 } syntax, and initialize them using { identifier1: expression1, identifier2: expression2 }.

You may have a trailing , after the last expression or type.

export component Example {
in-out property<{name: string, score: int}> player: { name: "Foo", score: 100 };
in-out property<{a: int, }> foo: { a: 3 };
}
slint

Define an enumeration with the enum keyword:

export enum CardSuit { clubs, diamonds, hearts, spade }
export component Example {
in-out property<CardSuit> card: spade;
out property<bool> is-clubs: card == CardSuit.clubs;
}
slint

Enum values can be referenced by using the name of the enum and the name of the value separated by a dot. (eg: CardSuit.spade)

The name of the enum can be omitted wherever a value of that enum type is expected, such as in a binding, a struct field, an array element, a function or callback argument, or a return value:

export enum CardSuit { clubs, diamonds, hearts, spade }
export struct Card { suit: CardSuit, value: int }
export component Example {
// in a struct field and an array element
out property<Card> card: { suit: hearts, value: 10 };
out property<[CardSuit]> deck: [clubs, diamonds, hearts, spade];
pure function is-red(suit: CardSuit) -> bool {
return suit == hearts || suit == diamonds;
}
// as a function argument
out property<bool> spade-is-red: is-red(spade);
}
slint

In a comparison the name can be omitted only on the right-hand side, which takes the type of the left: card.suit == hearts works, but hearts == card.suit does not.

The default value of each enum type is always the first value.


© 2026 SixtyFPS GmbH