结构体
使用 struct 关键字定义命名结构:
slint
export struct Player { name: string, score: int,}
export component Example { in-out property<Player> player: { name: "Foo", score: 100 };}结构体的默认值初始化为其所有字段都设置为各自默认值的状态。
匿名结构
使用 { identifier1: type1, identifier2: type2 } 语法声明匿名结构,并使用 { identifier1: expression1, identifier2: expression2 } 对其进行初始化。
你可以在最后一个表达式或类型后面加上一个尾随 ,。
slint
export component Example { in-out property<{name: string, score: int}> player: { name: "Foo", score: 100 }; in-out property<{a: int, }> foo: { a: 3 };}枚举
使用 enum 关键字定义枚举:
slint
export enum CardSuit { clubs, diamonds, hearts, spade }
export component Example { in-out property<CardSuit> card: spade; out property<bool> is-clubs: card == CardSuit.clubs;}可以使用枚举名称和值名称以点分隔的形式引用枚举值。(例如:CardSuit.spade)
在该枚举类型的绑定中,或者当回调的返回值是该枚举类型时,可以省略枚举的名称。
每种枚举类型的默认值始终是第一个值。