【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);
                }
            }
        }
    }
}

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

相关推荐
badmonster09 小时前
AI ETL需要不同的原语:从构建CocoIndex中学到的Rust经验🦀
rust·aigc
Source.Liu11 小时前
【Chrono库】Chrono 本地时区模块解析(src/offset/local/mod.rs)
rust·time
干饭比赛第一名获得者12 小时前
🚀 终极指南:Mac M4 编译 Rust 至 Linux (AMD64)
后端·rust
未来之窗软件服务13 小时前
幽冥大陆(三十六)S18酒店门锁SDK rust语言——东方仙盟筑基期
开发语言·c++·rust·智能门锁·东方仙盟sdk·东方仙盟一体化
ALex_zry15 小时前
C语言底层编程与Rust的现代演进:内存管理、系统调用与零成本抽象
c语言·算法·rust
ALex_zry15 小时前
内核开发者的视角:C与Rust在系统编程中的哲学与实践
c语言·开发语言·rust
u***451615 小时前
Windows安装Rust环境(详细教程)
开发语言·windows·rust
星释16 小时前
Rust 练习册 101:字符串序列切片的艺术
开发语言·后端·rust
Source.Liu17 小时前
【Chrono库】Android和OpenHarmony系统绑定(src/offset/local/tz_data.rs)
rust·time
S***q1921 天前
Rust在系统工具中的内存安全给代码上了三道保险锁。但正是这种“编译期的严苛”,换来了运行时的安心。比如这段代码:
开发语言·后端·rust