Slint 的所有组件的属性都有一个类型,Slint基础的类型如下:
90deg, 1.2rad 0.25turn用于描述控件的渐变效果,允许指定不同的角度、线性插值等,能非常便捷的还原 UI 设计原稿。
用于描述放射方向的渐变效果
import { VerticalBox } from "std-widgets.slint";
export component Example inherits Window {
preferred-width: 500px;
preferred-height: 400px;
VerticalBox {
Rectangle {
background: @linear-gradient(90deg, #3f87a6 0%, #ebf8e1 50%, #f69d3c 100%);
}
Rectangle {
background: @radial-gradient(circle, #f00 0%, #0f0 50%, #00f 100%);
}
}
}
export struct Player {
name: string,
score: int,
}
export component Example {
in-out property<Player> player: { name: "Foo", score: 100 };
}
export component Example {
in-out property<{name: string, score: int}> player: { name: "Foo", score: 100 };
in-out property<{a: int, }> foo: { a: 3 };
}
export enum CardSuit { clubs, diamonds, hearts, spade }
export component Example {
in-out property<CardSuit> card: spade;
out property<bool> is-clubs: card == CardSuit.clubs;
}
[]来包裹这个数组的元素,可用索引的方式读写各节点,模组使用[{}]包裹元素,允许内部元素类型不一样。export component Example {
# 数组
in-out property<[int]> list-of-int: [1,2,3];
# 模组
in-out property<[{a: int, b: string}]> list-of-structs: [{ a: 1, b: "hello" }, {a: 2, b: "world"}];
}
原文作者:Rust嵌入式;如有侵权,请联系管理员删除。