【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);
                }
            }
        }
    }
}
相关推荐
追逐时光者5 分钟前
小伙伴们学习 C#/.NET 相关技术栈的学习心得和路线
后端·.net
gelald14 分钟前
Spring Security 核心组件
后端·spring
码事漫谈31 分钟前
Blazor现状调研分析:2025年全栈开发的新选择
后端
码事漫谈32 分钟前
C++的开发难点在哪里?
后端
刘一说1 小时前
Spring Boot 应用的指标收集与监控体系构建指南
java·spring boot·后端
穿西装的水獭1 小时前
python将Excel数据写进图片中
开发语言·python·excel
老友@1 小时前
Java Excel 导出:EasyExcel 使用详解
java·开发语言·excel·easyexcel·excel导出
冰_河2 小时前
《Nginx核心技术》第11章:实现MySQL数据库的负载均衡
后端·nginx·架构
tryCbest2 小时前
Python基础之爬虫技术(一)
开发语言·爬虫·python
hixiong1232 小时前
C# OpenCVSharp实现Hand Pose Estimation Mediapipe
开发语言·opencv·ai·c#·手势识别