【Rust GUI开发入门】编写一个本地音乐播放器(9. 制作设置面板)

本系列教程对应的代码已开源在 Github zeedle

目的是制作这样的一个简单设置面板,里面有一些简单设置项,居中在屏幕中央:

即,每个设置项之间竖直方向布局,然后设置项内部,文字和控件水平布局:

slint 复制代码
export component SettingsPanel inherits Window {
    in property <string> song_dir;
    in property <string> lang;
    in property <bool> light_ui;
    callback refresh_song_list(string);
    callback set_lang(string);
    callback set_light_theme(bool);
    VerticalLayout {
        width: 100%;
        height: 100%;
        alignment: center;
        spacing: 20px;
        HorizontalLayout {
            alignment: center;
            spacing: 10px;
            Rectangle {
                height: 30px;
                width: 200px;
                Text {
                    x: parent.width - self.width;
                    vertical-alignment: center;
                    text: @tr("Music directory: ");
                }
            }

            LineEdit {
                text: song_dir;
                width: 200px;
                accepted(p) => {
                    refresh_song_list(p);
                }
            }
        }

        HorizontalLayout {
            alignment: center;
            spacing: 10px;
            Rectangle {
                height: 30px;
                width: 200px;
                Text {
                    x: parent.width - self.width;
                    vertical-alignment: center;
                    text: @tr("Language: ");
                }
            }

            ComboBox {
                width: 200px;
                current-value: lang;
                model: ["", "zh_CN", "es", "fr", "de", "ru"];
                selected(current-value) => {
                    root.set_lang(current-value);
                }
            }
        }

        HorizontalLayout {
            alignment: center;
            spacing: 10px;
            Rectangle {
                height: 30px;
                width: 200px;
                Text {
                    x: parent.width - self.width;
                    vertical-alignment: center;
                    text: @tr("Light theme: ");
                }
            }

            Switch {
                width: 200px;
                checked: light_ui;
                text: self.checked ? @tr("On") : @tr("Off");
                toggled => {
                    root.set_light_theme(self.checked);
                }
            }
        }
    }
}
相关推荐
wearegogog1231 天前
使用MATLAB实现平方倍频法对DSSS/BPSK信号进行载频估计
开发语言·matlab
蓝眸少年CY1 天前
Python科学计算 Numpy库
开发语言·python·numpy
困惑阿三1 天前
深入理解 JavaScript 中的(Promise.race)
开发语言·前端·javascript·ecmascript·reactjs
我命由我123451 天前
微信小程序 bind:tap 与 bindtap 的区别
开发语言·前端·javascript·微信小程序·小程序·前端框架·js
p***23361 天前
SpringBoot教程(三十二) SpringBoot集成Skywalking链路跟踪
spring boot·后端·skywalking
Yolo566Q1 天前
基于ArcGIS、InVEST与RUSLE水土流失模拟及分析
开发语言·python
八个程序员1 天前
c++——探讨a÷b(long long)
开发语言·c++
绝无仅有1 天前
Elasticsearch经典面试题案例分析
后端·面试·架构
Amarantine、沐风倩✨1 天前
深度解析:轨迹数据抽稀到底该放数据库还是 Java?(以 56800 条数据为例)
java·开发语言·数据库
绝无仅有1 天前
面试实战:如何实现一个完整的项目从注册到登录的功能?
后端·面试·架构