【Rust GUI开发入门】编写一个本地音乐播放器(7. 制作歌词显示面板)

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

目的是要制作一个这样的面板显示歌词:

水平布局:

  • 左边30%显示专辑封面
  • 右边70%显示歌词

歌词仍然使用ListView来构建,跟前文的歌曲列表一样,代码如下:

slint 复制代码
export component LyricsPanel inherits Window {
    in property <image> album_image;
    in property <SongInfo> current_song;
    in property <[LyricItem]> lyrics;
    in property <float> progress;
    in-out property <length> lyric_viewport_y;
    HorizontalLayout {
        width: 100%;
        height: 100%;
        VerticalLayout {
            width: 30%;
            alignment: center;
            lyric-image := Rectangle {
                x: parent.width / 2 - self.width / 2;
                width: 180px;
                height: self.width;
                clip: true;
                border-radius: 8px;
                drop-shadow-blur: 8px;
                Image {
                    width: 100%;
                    height: 100%;
                    source: album_image;
                }
            }

            Text {
                width: 100%;
                height: 25px;
                font-size: 13px;
                x: lyric-image.x;
                vertical-alignment: bottom;
                text: @tr("Artist: {}", current_song.singer);
                overflow: elide;
            }

            Text {
                width: 100%;
                height: 25px;
                font-size: 13px;
                x: lyric-image.x;
                vertical-alignment: bottom;
                text: @tr("Title: {}", current_song.song_name);
                overflow: elide;
            }
        }

        VerticalLayout {
            width: 70%;
            alignment: center;
            ListView {
                height: 100%;
                width: 100%;
                mouse-drag-pan-enabled: false;
                viewport-y <=> lyric_viewport_y;
                for item in lyrics: LyricLine {
                    content: item.text;
                    playing: (progress >= item.time) && (progress < item.time + item.duration);
                }
            }
        }
    }
}

重点在于从文件中解析歌词,将在下文介绍。

相关推荐
Source.Liu1 分钟前
【Rust】范围 Range详解
rust
Zhangzy@1 天前
pip安装Transformers / tokenizers 报错(Failed building wheel for tokenizers)
rust·pip
雷中听风1 天前
使用字节的源安装rust
开发语言·后端·rust
万法若空2 天前
【wxWidgets教程】控件基础知识
c++·gui·wxwidgets·事件处理
简单点好不好2 天前
2025-简单点-从0开始学Rust-更新
rust
余俊晖2 天前
从豆包手机等看GUI Agent:MobileRL GUI Agent训练框架和安卓XML预处理
人工智能·语言模型·自然语言处理·gui
EniacCheng3 天前
【RUST】学习笔记-整型
笔记·学习·rust
小灰灰搞电子4 天前
Rust可以取代C++么?
开发语言·c++·rust
百锦再4 天前
京东云鼎入驻方案解读——通往协同的“高架桥”与“快速路”
android·java·python·rust·django·restful·京东云
异步思考者4 天前
Rust实战:一个内存消息队列的 Trait 驱动开发
rust