import ui2 import math import libvendetta import time // queue_sidebar_w is the queue sidebar's full height panel width; the wheel // and the video hit test read the same width. const queue_sidebar_w = 348.0 // theme_editor_w is the theme editor sidebar's width, the same as the queue's. const theme_editor_w = 348.0 // queue_list_id names the sidebar's reorder container: the view builds the // tree with it, and the pointer / key handlers and the on_scroll feedback // find the same one through it. const queue_list_id = 'queue_list' // queue_row_h is one queue row's height inside the reorder container. const queue_row_h = 24.0 // stats_body turns the observed playback statistics into the popup's text. // A value of 0 means mpv reports nothing (no file, or the property is not // tracked), which is shown as a dash. fn (p &Player) stats_lines() []string { if !p.has_file { // The frame scheduler's counters matter most with no file open: the idle // window should report a callback per vsync and no builds between the // keep-alive repaints. return ['No file playing.', p.renderer_line()] } mut lines := []string{} lines << 'File: ${display_name(p.current_path, p.current_kind)}' lines << 'Position: ${libvendetta.fmt_time(p.pos)} / ${libvendetta.fmt_time(p.duration)}' lines << 'Speed: ${p.speed:.2f}x Volume: ${p.volume:.0f}' size := if p.video_w > 0 { '${p.video_w:.0f}x${p.video_h:.0f}' } else { '-' } fps := if p.container_fps > 0 { '${p.container_fps:.2f}' } else { '-' } vf := if p.vf_fps > 0 { '${p.vf_fps:.2f}' } else { '-' } dfs := if p.display_fps > 0 { '${p.display_fps:.2f}' } else { '-' } lines << 'Video: ${size} @ ${vf} fps (container ${fps}, display ${dfs})' lines << 'Hardware decoding: ${p.hwdec_current}' vbr := if p.video_bitrate > 0 { '${p.video_bitrate:.0f} kbps' } else { '-' } abr := if p.audio_bitrate > 0 { '${p.audio_bitrate:.0f} kbps' } else { '-' } lines << 'Bitrate: video ${vbr} / audio ${abr}' lines << 'Dropped: ${p.decoder_dropped:.0f} decoded / ${p.display_dropped:.0f} displayed' lines << 'Vo: ${p.vo_delayed:.0f} delayed / ${p.mistimed:.0f} mistimed' lines << 'A/V sync: ${p.avsync:.3f} (total ${p.avsync_change:.3f})' lines << 'Display sync: video ${p.video_speed_corr:.2f}x / audio ${p.audio_speed_corr:.2f}x' lines << 'VSync: ratio ${p.vsync_ratio:.2f} / jitter ${p.vsync_jitter:.2f}' lines << 'Cache: ${p.cache_duration:.0f} s buffered / ${p.cache_buffering:.0f}% used' // The frame scheduler's counters prove whether on_demand is actually // sleeping: an idle window reports a callback per vsync and no builds // between the keep-alive repaints, and playback should build near the // video's frame rate, not multiples of it. lines << p.renderer_line() // Boehm-GC holds whatever it grew, so the heap line ties the RSS the user // sees to what the allocator has reserved versus what it gave back. lines << p.gc_line() return lines } // renderer_line reports one second of frame scheduler work: builds, draws, // coalesced asks and frame callbacks. fn (p &Player) renderer_line() string { return 'Renderer: ${p.stats_builds} builds / ${p.stats_draws} draws / ${p.stats_coalesced} coalesced / ${p.stats_callbacks} callbacks per s' } // gc_line ties the RSS the user sees to what the Boehm allocator reserved // versus what it gave back to the operating system. fn (p &Player) gc_line() string { return 'V GC: heap ${p.stats_heap / 1048576.0:.0f} MiB / unmapped ${p.stats_unmapped / 1048576.0:.0f} MiB' } // main_area is the rect the player is laid out in: the window less the side // panels, which shrink the player instead of floating over it. The theme editor // takes the left, the queue the right. fn (p &Player) main_area(b ui2.Rect) ui2.Rect { editor_w := if p.theme_editor_open { theme_editor_w } else { 0.0 } queue_w := if p.show_queue { queue_sidebar_w } else { 0.0 } return ui2.rect(editor_w, 0, b.width - editor_w - queue_w, b.height) } // stats_popup_rect is the statistics popup's frame in the layout's coordinates. fn (p &Player) stats_popup_rect() ui2.Rect { return ui2.rect(16, 16, 348, 36 + p.stats_lines().len * 18 + 8) } // over_panel reports whether a point, in the layout's coordinates, lands on a // side panel or on the statistics popup: the video does not take the pointer // there. fn (p &Player) over_panel(x f64, y f64) bool { b := ui2.bounds() if p.theme_editor_open && x < theme_editor_w { return true } if p.show_queue && x >= b.width - queue_sidebar_w { return true } if p.show_stats { stats := p.stats_popup_rect() return x >= stats.x && x < stats.x + stats.width && y >= stats.y && y < stats.y + stats.height } return false } // view lays the window out from its current bounds. The widget builds the video // and its control strip; the app's panels, popups and dialogs sit on top of it. fn (mut p Player) view() ui2.Element { // Under the render-stats probe, time the tree build: the probe prints the // build duration per frame so a slow frame can be told apart from a slow // present. mut build_t0 := u64(0) $if render_stats_probe ? { build_t0 = time.sys_mono_now() } b := ui2.bounds() main_b := p.main_area(b) bar := libvendetta.control_bar(main_b, p.duration) button_box := ui2.BoxStyle{ bg: p.theme.btn_primary radius: 6 } button_text := ui2.TextStyle{ color: p.theme.text_main size: 16 valign: .middle } label_text := ui2.TextStyle{ color: p.theme.text_muted size: 13 } mut children := []ui2.Element{} children << p.build(main_b) // Statistics popup: a small panel of the mpv playback properties observed // under obs_. Toggled from View > Statistics or the i key, hidden by default. if p.show_stats { stats_header := ui2.TextStyle{ color: p.theme.btn_primary size: 11 } stats_body := ui2.TextStyle{ color: p.theme.text_muted size: 11 } mut stat_items := []ui2.Element{} stat_items << ui2.label('stats_title', 'Playback statistics', ui2.rect(12, 10, 324, 14), stats_header) for i, line in p.stats_lines() { stat_items << ui2.label('stats_line_${i}', line, ui2.rect(12, 36 + i * 18, 324, 14), stats_body) } children << ui2.view('stats_popup', p.stats_popup_rect(), ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 }, stat_items) } // Queue manager sidebar: shown when toggled from View -> Queue. Its list // is a ui2 reorder container — a row drags to a new place (the move // mirrors into mpv's playlist) and the keyboard cursor moves with Alt and // the arrows — so the per-row up/down buttons are gone. if p.show_queue { queue_title := ui2.TextStyle{ color: p.theme.btn_primary size: 11 } queue_text := ui2.TextStyle{ color: p.theme.text_muted size: 11 } mut queue_items := []ui2.Element{} queue_items << ui2.label('queue_title', 'Queue', ui2.rect(12, 10, 324, 14), queue_title) if p.queue.len == 0 { queue_items << ui2.label('queue_empty', 'Empty', ui2.rect(12, 36, 324, 14), queue_text) } else { // The container is built from this same frame on every event that // reaches it (see queue_config), so keep it on the player. p.queue_frame = ui2.rect(4, 28, queue_sidebar_w - 8, b.height - 28 - 46) if container := ui2.reorder_container(p.queue_config()) { queue_items << container } else { // A bad frame or a malformed row is a developer mistake; keep // the sidebar's chrome up and say so on stderr. eprintln('vendetta: queue reorder container: ${err}') } } // Proper right-aligned full-height sidebar. queue_items << ui2.button('queue_save', 'Save...', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 6 }, ui2.TextStyle{ color: p.theme.text_main size: 11 valign: .middle }) queue_items << ui2.button('queue_clear', 'Clear', ui2.rect(178, b.height - 40, 158, 28), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 6 }, ui2.TextStyle{ color: p.theme.text_main size: 11 valign: .middle }) children << ui2.view('queue_sidebar', ui2.rect(b.width - queue_sidebar_w, 0, queue_sidebar_w, b.height), ui2.BoxStyle{ bg: p.theme.bg_dark radius: 0 }, queue_items) } // Theme editor sidebar: the theme's name, one row per colour with a hex // field and a swatch that opens the RGB picker below, and Save. It mirrors // the queue sidebar and excludes it — the two right-side panels swap. if p.theme_editor_open { editor_text := ui2.TextStyle{ color: p.theme.text_main size: 11 } section_text := ui2.TextStyle{ color: p.theme.btn_primary size: 11 } field_box := ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } mut editor_items := []ui2.Element{} editor_items << ui2.label('theme_editor_title', 'Theme editor', ui2.rect(12, 10, 324, 14), section_text) editor_items << ui2.label('theme_name_label', 'Name:', ui2.rect(12, 40, 44, 24), editor_text) editor_items << ui2.text_input(ui2.TextInputConfig{ id: 'theme_name_input' action_id: 'theme_name_input' frame: ui2.rect(60, 38, 276, 26) text: p.theme_edit_name multiline: false box: field_box text_style: editor_text }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } editor_items << ui2.label('theme_colors_label', 'Colors:', ui2.rect(12, 72, 200, 14), editor_text) // The colour rows scroll in a pane; Save stays pinned at the bottom. mut rows := []ui2.Element{} for _, key in color_keys { mut row := []ui2.Element{} row << ui2.label('theme_color_label_${key}', color_label(key), ui2.rect(12, 3, 104, 24), ui2.TextStyle{ ...editor_text valign: .middle }) row << ui2.text_input(ui2.TextInputConfig{ id: 'theme_color_input_${key}' action_id: 'theme_color_input_${key}' frame: ui2.rect(120, 3, 130, 24) text: p.theme_edit_texts[key] multiline: false box: field_box text_style: editor_text }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } // The row's colour chooser: a swatch that opens the spectrum panel // (saturation and brightness area, hue slider) as a popover. row << ui2.color_picker(p.theme_picker_trigger_config(key)) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } rows << ui2.view('theme_row_${key}', ui2.rect(0, 0, 348, 30), ui2.BoxStyle{ transparent: true }, row) } editor_items << ui2.scrollable(ui2.ScrollableConfig{ id: 'theme_rows' frame: ui2.rect(0, 92, 348, b.height - 140) stack: .column children: rows background: p.theme.bg_dark }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } editor_items << ui2.button('theme_save', 'Save', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 6 }, ui2.TextStyle{ color: p.theme.text_main size: 11 valign: .middle }) children << ui2.view('theme_editor_sidebar', ui2.rect(0, 0, 348, b.height), ui2.BoxStyle{ bg: p.theme.bg_dark radius: 0 }, editor_items) // The choosers' popovers go last, so they cover everything above. for i, key in color_keys { children << ui2.color_picker_popover(p.theme_picker_config(key, i, b)) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } } } if p.notices.len > 0 { // The notice stack rides toasts in the theme's colour, sized to // roughly fit each text. One element per notice, keyed by its // serial, so the stack reads top down as messages arrive. for i, notice in p.notices { w := math.min(f64(notice.text.len) * 7.5 + 28, b.width - 40) children << ui2.view('notice_${notice.serial}', ui2.rect(20, 14 + i * 30, w, 26), ui2.BoxStyle{ bg: p.theme.notice_bg radius: 6 }, [ui2.label('', notice.text, ui2.rect(14, 5, w - 28, 16), label_text)]) } } dialog_body := [ ui2.label('', 'Playback speed (0.01 to 100)', ui2.rect(16, 16, 288, 22), label_text), ui2.text_input(ui2.TextInputConfig{ id: 'speed_input' frame: ui2.rect(16, 48, 288, 36) text: p.speed_text multiline: false submit_id: 'speed_apply' box: ui2.BoxStyle{ bg: p.theme.bg_dark radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(16, 48, 288, 36), label_text) }, ui2.button('speed_apply', 'Apply', ui2.rect(16, 110, 130, 36), button_box, button_text), ui2.button('speed_cancel', 'Cancel', ui2.rect(174, 110, 130, 36), button_box, button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'speed_dialog' frame: b open: p.custom_open dismiss_action_id: 'speed_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 170 content_box: ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 10 } content: ui2.view('', ui2.rect(0, 0, 320, 170), ui2.BoxStyle{ transparent: true }, dialog_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } queue_header := ui2.TextStyle{ color: p.theme.btn_primary size: 11 } queue_body_text := ui2.TextStyle{ color: p.theme.text_muted size: 11 } dialog_button := ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 6 } dialog_button_text := ui2.TextStyle{ color: p.theme.text_main size: 11 valign: .middle } // Max volume dialog: sets the upper bound of the volume slider. max_volume_body := [ ui2.label('', 'Max volume (1 to 1000)', ui2.rect(12, 10, 296, 14), queue_header), ui2.text_input(ui2.TextInputConfig{ id: 'max_volume_input' frame: ui2.rect(12, 34, 296, 28) text: p.max_volume_text multiline: false submit_id: 'max_volume_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, ui2.button('max_volume_apply', 'Apply', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), ui2.button('max_volume_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'max_volume_dialog' frame: b open: p.max_volume_open dismiss_action_id: 'max_volume_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ transparent: true }, max_volume_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Save-queue dialog: names the current queue, saved under // ~/.config/vendetta/queues/.json. Same panel style; the input is a // black inset on the dark card. queue_name_body := [ ui2.label('', 'Save queue', ui2.rect(12, 10, 296, 14), queue_header), ui2.text_input(ui2.TextInputConfig{ id: 'queue_name_input' frame: ui2.rect(12, 34, 296, 28) text: p.queue_name_text multiline: false submit_id: 'queue_name_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, ui2.button('queue_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), ui2.button('queue_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'queue_name_dialog' frame: b open: p.queue_name_open dismiss_action_id: 'queue_name_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ transparent: true }, queue_name_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Save-playlist dialog: names the current queue, saved as an mpv-format // playlist under ~/.config/vendetta/playlists/.m3u. Mirrors the // queue name dialog it sits beside; the same mpv demuxer-plus-editors // read the file, so the slot is not vendetta's private state. playlist_name_body := [ ui2.label('', 'Save playlist', ui2.rect(12, 10, 296, 14), queue_header), ui2.text_input(ui2.TextInputConfig{ id: 'playlist_name_input' frame: ui2.rect(12, 34, 296, 28) text: p.playlist_name_text multiline: false submit_id: 'playlist_name_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, ui2.button('playlist_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), ui2.button('playlist_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'playlist_name_dialog' frame: b open: p.playlist_name_open dismiss_action_id: 'playlist_name_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ transparent: true }, playlist_name_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Save-preset dialog: names the current options, saved under // ~/.config/vendetta/presets/.json. Same panel style as the queue // name dialog it mirrors; the input is a black inset on the dark card. preset_name_body := [ ui2.label('', 'Save options preset', ui2.rect(12, 10, 296, 14), queue_header), ui2.text_input(ui2.TextInputConfig{ id: 'preset_name_input' frame: ui2.rect(12, 34, 296, 28) text: p.preset_name_text multiline: false submit_id: 'preset_name_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, ui2.button('preset_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), ui2.button('preset_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'preset_name_dialog' frame: b open: p.preset_name_open dismiss_action_id: 'preset_name_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ transparent: true }, preset_name_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Mpv option dialog: takes any mpv option name and value and applies it // live through the property interface. Options set here merge into the // saved settings; an empty value unsets the option, which also stops it // from coming back on the next start. mpv_option_body := [ ui2.label('', 'Set mpv option', ui2.rect(12, 10, 296, 14), queue_header), ui2.label('', 'Option name', ui2.rect(12, 26, 296, 14), queue_body_text), ui2.text_input(ui2.TextInputConfig{ id: 'mpv_opt_name_input' frame: ui2.rect(12, 42, 296, 26) text: p.mpv_option_name_text multiline: false box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 42, 296, 26), queue_body_text) }, ui2.label('', 'Value (empty unsets the option)', ui2.rect(12, 76, 296, 14), queue_body_text), ui2.text_input(ui2.TextInputConfig{ id: 'mpv_opt_value_input' frame: ui2.rect(12, 92, 296, 26) text: p.mpv_option_value_text multiline: false submit_id: 'mpv_option_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 92, 296, 26), queue_body_text) }, ui2.button('mpv_option_apply', 'Apply', ui2.rect(12, 126, 86, 22), dialog_button, dialog_button_text), ui2.button('mpv_option_cancel', 'Cancel', ui2.rect(106, 126, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'mpv_option_dialog' frame: b open: p.mpv_option_open dismiss_action_id: 'mpv_option_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 158 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 158), ui2.BoxStyle{ transparent: true }, mpv_option_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Open URL dialog: a typed link takes the same open path as the picker's // files, so Default open — ask, play now, add to queue — rules here too. // Explicitly a link: apply refuses an entry without a protocol prefix // instead of betting on mpv reaching it some other way. url_body := [ ui2.label('', 'Open URL', ui2.rect(12, 10, 296, 14), queue_header), ui2.text_input(ui2.TextInputConfig{ id: 'url_input' frame: ui2.rect(12, 34, 296, 28) text: p.url_text hint_text: 'https://...' multiline: false submit_id: 'url_apply' box: ui2.BoxStyle{ bg: p.theme.field_bg radius: 6 } text_style: ui2.TextStyle{ color: p.theme.text_main } }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, ui2.button('url_apply', 'Open', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), ui2.button('url_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'url_dialog' frame: b open: p.url_open dismiss_action_id: 'url_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ transparent: true }, url_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Queue open choice dialog: Play now or Add to queue. first := if p.queue_paths.len > 0 { display_name(p.queue_paths[0], libvendetta.source_kind(p.queue_paths[0])) } else { '' } more := if p.queue_paths.len > 1 { ' and ${p.queue_paths.len - 1} more' } else { '' } open_dialog_body := [ ui2.label('queue_dialog_title', 'Open video', ui2.rect(12, 10, 296, 14), queue_header), ui2.label('queue_dialog_file', '${first}${more}', ui2.rect(12, 36, 296, 14), queue_body_text), ui2.button('queue_play_now', 'Play now', ui2.rect(12, 62, 86, 22), dialog_button, dialog_button_text), ui2.button('queue_add', 'Add to queue', ui2.rect(106, 62, 104, 22), dialog_button, dialog_button_text), ui2.button('queue_cancel', 'Cancel', ui2.rect(218, 62, 62, 22), dialog_button, dialog_button_text), ] children << ui2.modal_view(ui2.ModalViewConfig{ id: 'queue_dialog' frame: b open: p.queue_open dismiss_action_id: 'queue_cancel' overlay_box: ui2.BoxStyle{ bg: p.theme.overlay_bg opacity: 0.45 } content_width: 320 content_height: 100 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 100), ui2.BoxStyle{ transparent: true }, open_dialog_body) }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Seek preview popup: the frame at the hovered seek position, taken by the // hidden thumbnail instance so playback is never moved. if p.preview_visible && p.preview_show_path.len > 0 && p.preview_show_w > 0 { preview_text := ui2.TextStyle{ color: p.theme.text_muted size: 11 } mut thumb_w := 160.0 mut thumb_h := 90.0 thumb_h = thumb_w * p.preview_show_h / p.preview_show_w if thumb_h > 90 { thumb_h = 90 thumb_w = 90 * p.preview_show_w / p.preview_show_h } // The popup stays inside the player's area, clear of the side panels. mut x := p.pointer_x - thumb_w / 2 if x < main_b.x { x = main_b.x } if x + thumb_w > main_b.x + main_b.width { x = main_b.x + main_b.width - thumb_w } // The popup sits just above the control line, centred on the pointer. y := bar.seek.y - thumb_h - 24 children << ui2.view('seek_preview_box', ui2.rect(x - 3, y - 3, thumb_w + 6, thumb_h + 24), ui2.BoxStyle{ bg: p.theme.bg_dark opacity: 0.8 radius: 4 }, []) children << ui2.image('seek_preview', p.preview_show_path, ui2.rect(x, y, thumb_w, thumb_h)) children << ui2.label('seek_preview_time', libvendetta.fmt_time(p.preview_show_time), ui2.rect(x, y + thumb_h + 2, thumb_w, 16), preview_text) } $if render_stats_probe ? { build_ms := f64(time.sys_mono_now() - build_t0) / 1e6 eprintln('probe view_build ${build_ms:.1f}ms') } return ui2.screen(p.theme.bg_surface, children) } // queue_config is the queue sidebar's reorder container description. The view // builds the tree from it (recording the frame on the player), and the pointer // and key handlers feed ui2.reorder_update / ui2.reorder_key the same shape, // so an event is answered against exactly the rows the screen shows. fn (p &Player) queue_config() ui2.ReorderConfig { mut items := []ui2.Element{cap: p.queue_keys.len} for i, key in p.queue_keys { if i >= p.queue.len { // The row keys and the queue are bound together everywhere; this // only keeps a desync from reaching the container. break } items << p.queue_row(i, key) } return ui2.ReorderConfig{ id: queue_list_id frame: p.queue_frame items: items state: p.queue_state // A hair between the tiles, and enough padding that the lifted row's // shadow does not clip at the sidebar's edge. gap: 2 padding: 4 // The scroll offset the reveal computations start from; the on_scroll // handler feeds it back. offset: p.queue_scroll // Only the grip leads a drag, so the row's own remove button keeps // its press. handle: true size: .small theme: ui2.ComponentTheme{ background: p.theme.bg_dark foreground: p.theme.text_muted muted: p.theme.bg_surface muted_foreground: p.theme.menu_disabled border: p.theme.menu_border primary: p.theme.btn_primary primary_foreground: p.theme.bg_dark } accessibility_label: 'Playback queue' } } // queue_row builds one entry the container wraps: the grip it draws ahead of // the row carries the drag, and the row itself holds the name and the remove // button. Only the row's height matters in its frame — the container // stretches it across the panel and places it on its own. fn (p &Player) queue_row(index int, key string) ui2.Element { file := p.queue[index] // The name reads through the entry's shape: a file is its basename, a // link its URL name. name := display_name(file, libvendetta.source_kind(file)) // The playing row says so: without the marker a reorder around the // playing entry is unreadable — the user cannot tell which row the next // track change follows. The marker stays in the text: the row's leading // edge belongs to the drag grip. playing := index == p.playlist_index && p.has_file display := if playing { '▶ ' + name } else { name } text := if playing { ui2.TextStyle{ color: p.theme.btn_primary size: 11 valign: .middle } } else { ui2.TextStyle{ color: p.theme.text_muted size: 11 valign: .middle } } row := ui2.view('queue_row_${key}', ui2.rect(0, 0, 0, queue_row_h), ui2.BoxStyle{ bg: p.theme.bg_surface radius: 5 }, [ ui2.label('', display, ui2.rect(6, 0, 280, queue_row_h), text), ui2.button('queue_rm_${key}', '✕', ui2.rect(290, 3, 18, 18), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 4 }, ui2.TextStyle{ color: p.theme.text_main size: 10 valign: .middle }), ]) return ui2.Element{ ...row key: key } }