import { VerticalBox , Button, LineEdit} from "std-widgets.slint";

export component Field inherits VerticalBox {
    padding: 0;
    in property <string> description;
    in-out property <string> value;
}

export component TextField inherits Field {    
    Text { text: root.description; height: 20px; }
    LineEdit { text <=> root.value; height: 30px; }
}

export component MainWindow inherits Window {
    default-font-size: 14px;

    preferred-width: 300px;
    preferred-height: 300px;

    in-out property <string> value;

    VerticalBox {
        Text { text: "Hi, Felix!"; height: 20px;}
        TextField { description: "Do you like tea?"; value <=> value; }
        TextField { description: "Your output is:"; value <=> value; }
        Button { text: "Quit"; height: 30px; }
    }
}

注:本示例在 Slint v1.2.2 上测试。

下面简单总结 Slint 组件属性标记:

属性标记总结
in只可外部指定的属性,如 Button { text: "Quit" }TextField { description: "Do you like tea?"; },此属性可以赋值
out只可外部访问的属性,如 button.pressed,此属性不能赋值
in-out可外部指定也可以外部访问的属性,如 button.checked,此属性可以赋值
最后修改:2024 年 03 月 02 日
如果觉得我的文章对你有用,请随意赞赏