当前位置: 首页 > news >正文

【Rust GUI开发入门】编写一个本地音乐播放器(10. 拼装UI组件) - Jordan

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

将前文写的零散的UI组件(歌曲列表/播放控制面板/歌词面板/设置面板)拼装起来,组成最终的音乐播放器UI,用TabWidget分成多标签页,每一个标签页分担不同的功能:

player.png

export component MainWindow inherits Window {preferred-width: 850px;preferred-height: 500px;min-width: 850px;min-height: 500px;title: "Zeedle";icon: @image-url("cover.svg");callback toggle_play();callback play(SongInfo, TriggerSource);callback play_next();callback play_prev();callback change_progress(float);callback switch_mode(PlayMode);callback refresh_song_list(string);callback sort_song_list(SortKey, bool);callback set_lang(string);pure callback format_duration(float) -> string;public function set_light_theme(yes: bool) {UIState.light_ui = yes;if (yes) {Palette.color-scheme = ColorScheme.light;} else {Palette.color-scheme = ColorScheme.dark;}}tabs := TabWidget {Tab {title: @tr("Gallery");VerticalLayout {SongListView {ascending <=> UIState.sort_ascending;sort-key <=> UIState.sort_key;last-sort-key <=> UIState.last_sort_key;song-list <=> UIState.song_list;sort-songs(key, asc) => {root.sort_song_list(key, asc);}play-song(info, src) => {root.play(info, src);}}ControlPanel {max-height: 80px;min-height: 50px;preferred-height: 60px;progress <=> UIState.progress;duration <=> UIState.duration;paused <=> UIState.paused;dragging <=> UIState.dragging;play_mode <=> UIState.play_mode;current_song <=> UIState.current_song;album_image <=> UIState.album_image;change-progress(p) => {root.change_progress(p);root.focus();}toggle-play() => {root.toggle_play();}play-next() => {root.play_next();}play-prev() => {root.play_prev();}switch-mode(m) => {root.switch_mode(m);}double-clicked() => {tabs.current-index = 1; // 切换到歌词页}format-duration(d) => {return root.format_duration(d);}}}}Tab {title: @tr("Lyrics");Rectangle {width: 100%;height: 100%;z: -5;TouchArea {double-clicked => {tabs.current-index = 0; // 切换到歌曲列表页}}}LyricsPanel {width: 100%;height: 100%;album_image <=> UIState.album_image;current_song <=> UIState.current_song;lyrics <=> UIState.lyrics;progress <=> UIState.progress;lyric_viewport_y <=> UIState.lyric_viewport_y;}}Tab {title: @tr("Settings");SettingsPanel {width: 100%;height: 100%;song_dir <=> UIState.song_dir;lang <=> UIState.lang;light_ui <=> UIState.light_ui;refresh_song_list(p) => {root.refresh_song_list(p);}set_lang(l) => {root.set_lang(l);}set_light_theme(yes) => {root.set_light_theme(yes);}}}Tab {title: @tr("About");Text {width: 100%;height: 100%;font-size: 16px;text: UIState.about_info;horizontal-alignment: center;vertical-alignment: center;}}}
}
http://www.hskmm.com/?act=detail&tid=21700

相关文章:

  • 国产数据库-达梦docker镜像安装
  • CAP 8.4 版本发布通告
  • 【Leetcode】随笔 - 详解
  • DevEco Studio 编辑器的使用 - 实践
  • docker安装MySQL8.0.25的坑
  • WPF 深入系列.2.布局系统.尺寸属性 - 指南
  • 实训
  • Kosaraju算法
  • bat批处理设置临时PATH路径不能访问
  • 10. Spring AI + RAG - Rainbow
  • 《AI智能体实战研发教程(从0到企业级项目落地)》全网上线|CSDN B站同步首发
  • 9. Spring AI 当中对应 MCP 的操作 - Rainbow
  • 9/30
  • rhel8无法输入中文问题(红帽8安装中文输入法)
  • 威佐夫博弈(Wythoff‘s Game)
  • C语言⽂件管理讲解(1)
  • 2025年9月30日
  • Min-p采样:通过动态调整截断阈值让大模型文本生成兼顾创造力与逻辑性
  • 2025 年快速卷帘门品牌最新推荐排行榜:聚焦智能定制与高效供货,精选快速卷帘门实力厂家
  • ARL灯塔搭建
  • 记 Charles 抓不到包 - Higurashi
  • STM32H743-ARM例程13-SDIO - 实践
  • 贼猴 0930 模拟赛 T2 | 计数
  • 题解:AT_abc311_h [ABC311Ex] Many Illumination Plans
  • 一个孤单的程序员
  • 根号大杂烩
  • 学习java的第二天
  • 日记.txt
  • Beatty 定理
  • 2025-9-27 提高组模拟赛 div2