vendetta / src / view.v
754 lines · 744 sloc · 27.58 KB · 77754ad9e6dc749afefba326ff89abc5ddd8c9c9
Raw
1import ui2
2import math
3import libvendetta
4import time
5
6// queue_sidebar_w is the queue sidebar's full height panel width; the wheel
7// and the video hit test read the same width.
8const queue_sidebar_w = 348.0
9
10// queue_list_id names the sidebar's reorder container: the view builds the
11// tree with it, and the pointer / key handlers and the on_scroll feedback
12// find the same one through it.
13const queue_list_id = 'queue_list'
14
15// queue_row_h is one queue row's height inside the reorder container.
16const queue_row_h = 24.0
17
18// stats_body turns the observed playback statistics into the popup's text.
19// A value of 0 means mpv reports nothing (no file, or the property is not
20// tracked), which is shown as a dash.
21fn (p &Player) stats_lines() []string {
22 if !p.has_file {
23 // The frame scheduler's counters matter most with no file open: the idle
24 // window should report a callback per vsync and no builds between the
25 // keep-alive repaints.
26 return ['No file playing.', p.renderer_line()]
27 }
28 mut lines := []string{}
29 lines << 'File: ${display_name(p.current_path, p.current_kind)}'
30 lines << 'Position: ${libvendetta.fmt_time(p.pos)} / ${libvendetta.fmt_time(p.duration)}'
31 lines << 'Speed: ${p.speed:.2f}x Volume: ${p.volume:.0f}'
32 size := if p.video_w > 0 { '${p.video_w:.0f}x${p.video_h:.0f}' } else { '-' }
33 fps := if p.container_fps > 0 { '${p.container_fps:.2f}' } else { '-' }
34 vf := if p.vf_fps > 0 { '${p.vf_fps:.2f}' } else { '-' }
35 dfs := if p.display_fps > 0 { '${p.display_fps:.2f}' } else { '-' }
36 lines << 'Video: ${size} @ ${vf} fps (container ${fps}, display ${dfs})'
37 lines << 'Hardware decoding: ${p.hwdec_current}'
38 vbr := if p.video_bitrate > 0 { '${p.video_bitrate:.0f} kbps' } else { '-' }
39 abr := if p.audio_bitrate > 0 { '${p.audio_bitrate:.0f} kbps' } else { '-' }
40 lines << 'Bitrate: video ${vbr} / audio ${abr}'
41 lines << 'Dropped: ${p.decoder_dropped:.0f} decoded / ${p.display_dropped:.0f} displayed'
42 lines << 'Vo: ${p.vo_delayed:.0f} delayed / ${p.mistimed:.0f} mistimed'
43 lines << 'A/V sync: ${p.avsync:.3f} (total ${p.avsync_change:.3f})'
44 lines << 'Display sync: video ${p.video_speed_corr:.2f}x / audio ${p.audio_speed_corr:.2f}x'
45 lines << 'VSync: ratio ${p.vsync_ratio:.2f} / jitter ${p.vsync_jitter:.2f}'
46 lines << 'Cache: ${p.cache_duration:.0f} s buffered / ${p.cache_buffering:.0f}% used'
47 // The frame scheduler's counters prove whether on_demand is actually
48 // sleeping: an idle window reports a callback per vsync and no builds
49 // between the keep-alive repaints, and playback should build near the
50 // video's frame rate, not multiples of it.
51 lines << p.renderer_line()
52 // Boehm-GC holds whatever it grew, so the heap line ties the RSS the user
53 // sees to what the allocator has reserved versus what it gave back.
54 lines << p.gc_line()
55 return lines
56}
57
58// renderer_line reports one second of frame scheduler work: builds, draws,
59// coalesced asks and frame callbacks.
60fn (p &Player) renderer_line() string {
61 return 'Renderer: ${p.stats_builds} builds / ${p.stats_draws} draws / ${p.stats_coalesced} coalesced / ${p.stats_callbacks} callbacks per s'
62}
63
64// gc_line ties the RSS the user sees to what the Boehm allocator reserved
65// versus what it gave back to the operating system.
66fn (p &Player) gc_line() string {
67 return 'V GC: heap ${p.stats_heap / 1048576.0:.0f} MiB / unmapped ${p.stats_unmapped / 1048576.0:.0f} MiB'
68}
69
70// view lays the window out from its current bounds. The widget builds the video
71// and its control strip; the app's panels, popups and dialogs sit on top of it.
72fn (mut p Player) view() ui2.Element {
73 // Under the render-stats probe, time the tree build: the probe prints the
74 // build duration per frame so a slow frame can be told apart from a slow
75 // present.
76 mut build_t0 := u64(0)
77 $if render_stats_probe ? {
78 build_t0 = time.sys_mono_now()
79 }
80 b := ui2.bounds()
81 // Both side panels shrink the player: the theme editor from the left, the
82 // queue from the right.
83 editor_w := if p.theme_editor_open { 348.0 } else { 0.0 }
84 queue_w := if p.show_queue { 348.0 } else { 0.0 }
85 main_b := ui2.rect(editor_w, 0, b.width - editor_w - queue_w, b.height)
86 bar := libvendetta.control_bar(main_b, p.duration)
87 button_box := ui2.BoxStyle{
88 bg: p.theme.btn_primary
89 radius: 6
90 }
91 button_text := ui2.TextStyle{
92 color: p.theme.text_main
93 size: 16
94 valign: .middle
95 }
96 label_text := ui2.TextStyle{
97 color: p.theme.text_muted
98 size: 13
99 }
100 mut children := []ui2.Element{}
101 children << p.build(main_b)
102 // Statistics popup: a small panel of the mpv playback properties observed
103 // under obs_. Toggled from View > Statistics or the i key, hidden by default.
104 if p.show_stats {
105 stats_header := ui2.TextStyle{
106 color: p.theme.btn_primary
107 size: 11
108 }
109 stats_body := ui2.TextStyle{
110 color: p.theme.text_muted
111 size: 11
112 }
113 mut stat_items := []ui2.Element{}
114 stat_items << ui2.label('stats_title', 'Playback statistics', ui2.rect(12, 10, 324, 14), stats_header)
115 for i, line in p.stats_lines() {
116 stat_items << ui2.label('stats_line_${i}', line, ui2.rect(12, 36 + i * 18, 324, 14), stats_body)
117 }
118 children << ui2.view('stats_popup', ui2.rect(16, 16, 348, 36 + p.stats_lines().len * 18 + 8), ui2.BoxStyle{
119 bg: p.theme.bg_dark
120 opacity: 0.8
121 radius: 8
122 }, stat_items)
123 }
124 // Queue manager sidebar: shown when toggled from View -> Queue. Its list
125 // is a ui2 reorder container — a row drags to a new place (the move
126 // mirrors into mpv's playlist) and the keyboard cursor moves with Alt and
127 // the arrows — so the per-row up/down buttons are gone.
128 if p.show_queue {
129 queue_title := ui2.TextStyle{
130 color: p.theme.btn_primary
131 size: 11
132 }
133 queue_text := ui2.TextStyle{
134 color: p.theme.text_muted
135 size: 11
136 }
137 mut queue_items := []ui2.Element{}
138 queue_items << ui2.label('queue_title', 'Queue', ui2.rect(12, 10, 324, 14), queue_title)
139 if p.queue.len == 0 {
140 queue_items << ui2.label('queue_empty', 'Empty', ui2.rect(12, 36, 324, 14), queue_text)
141 } else {
142 // The container is built from this same frame on every event that
143 // reaches it (see queue_config), so keep it on the player.
144 p.queue_frame = ui2.rect(4, 28, queue_sidebar_w - 8, b.height - 28 - 46)
145 if container := ui2.reorder_container(p.queue_config()) {
146 queue_items << container
147 } else {
148 // A bad frame or a malformed row is a developer mistake; keep
149 // the sidebar's chrome up and say so on stderr.
150 eprintln('vendetta: queue reorder container: ${err}')
151 }
152 }
153 // Proper right-aligned full-height sidebar.
154 queue_items << ui2.button('queue_save', 'Save...', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{
155 bg: p.theme.btn_secondary
156 radius: 6
157 }, ui2.TextStyle{
158 color: p.theme.text_main
159 size: 11
160 valign: .middle
161 })
162 queue_items << ui2.button('queue_clear', 'Clear', ui2.rect(178, b.height - 40, 158, 28), ui2.BoxStyle{
163 bg: p.theme.btn_secondary
164 radius: 6
165 }, ui2.TextStyle{
166 color: p.theme.text_main
167 size: 11
168 valign: .middle
169 })
170 children << ui2.view('queue_sidebar', ui2.rect(b.width - queue_sidebar_w, 0, queue_sidebar_w, b.height), ui2.BoxStyle{
171 bg: p.theme.bg_dark
172 radius: 0
173 }, queue_items)
174 }
175 // Theme editor sidebar: the theme's name, one row per colour with a hex
176 // field and a swatch that opens the RGB picker below, and Save. It mirrors
177 // the queue sidebar and excludes it — the two right-side panels swap.
178 if p.theme_editor_open {
179 editor_text := ui2.TextStyle{
180 color: p.theme.text_main
181 size: 11
182 }
183 section_text := ui2.TextStyle{
184 color: p.theme.btn_primary
185 size: 11
186 }
187 field_box := ui2.BoxStyle{
188 bg: p.theme.field_bg
189 radius: 6
190 }
191 mut editor_items := []ui2.Element{}
192 editor_items << ui2.label('theme_editor_title', 'Theme editor', ui2.rect(12, 10, 324, 14), section_text)
193 editor_items << ui2.label('theme_name_label', 'Name:', ui2.rect(12, 40, 44, 24), editor_text)
194 editor_items << ui2.text_input(ui2.TextInputConfig{
195 id: 'theme_name_input'
196 action_id: 'theme_name_input'
197 frame: ui2.rect(60, 38, 276, 26)
198 text: p.theme_edit_name
199 multiline: false
200 box: field_box
201 text_style: editor_text
202 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) }
203 editor_items << ui2.label('theme_colors_label', 'Colors:', ui2.rect(12, 72, 200, 14), editor_text)
204 // The colour rows scroll in a pane; Save stays pinned at the bottom.
205 mut rows := []ui2.Element{}
206 for _, key in color_keys {
207 mut row := []ui2.Element{}
208 row << ui2.label('theme_color_label_${key}', color_label(key), ui2.rect(12, 3, 104, 24), ui2.TextStyle{
209 ...editor_text
210 valign: .middle
211 })
212 row << ui2.text_input(ui2.TextInputConfig{
213 id: 'theme_color_input_${key}'
214 action_id: 'theme_color_input_${key}'
215 frame: ui2.rect(120, 3, 130, 24)
216 text: p.theme_edit_texts[key]
217 multiline: false
218 box: field_box
219 text_style: editor_text
220 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) }
221 // The row's colour chooser: a swatch that opens the spectrum panel
222 // (saturation and brightness area, hue slider) as a popover.
223 row << ui2.color_picker(p.theme_picker_trigger_config(key)) or {
224 ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text)
225 }
226 rows << ui2.view('theme_row_${key}', ui2.rect(0, 0, 348, 30), ui2.BoxStyle{
227 transparent: true
228 }, row)
229 }
230 editor_items << ui2.scrollable(ui2.ScrollableConfig{
231 id: 'theme_rows'
232 frame: ui2.rect(0, 92, 348, b.height - 140)
233 stack: .column
234 children: rows
235 background: p.theme.bg_dark
236 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) }
237 editor_items << ui2.button('theme_save', 'Save', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{
238 bg: p.theme.btn_secondary
239 radius: 6
240 }, ui2.TextStyle{
241 color: p.theme.text_main
242 size: 11
243 valign: .middle
244 })
245 children << ui2.view('theme_editor_sidebar', ui2.rect(0, 0, 348, b.height), ui2.BoxStyle{
246 bg: p.theme.bg_dark
247 radius: 0
248 }, editor_items)
249 // The choosers' popovers go last, so they cover everything above.
250 for i, key in color_keys {
251 children << ui2.color_picker_popover(p.theme_picker_config(key, i, b)) or {
252 ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text)
253 }
254 }
255 }
256 if p.notices.len > 0 {
257 // The notice stack rides toasts in the theme's colour, sized to
258 // roughly fit each text. One element per notice, keyed by its
259 // serial, so the stack reads top down as messages arrive.
260 for i, notice in p.notices {
261 w := math.min(f64(notice.text.len) * 7.5 + 28, b.width - 40)
262 children << ui2.view('notice_${notice.serial}', ui2.rect(20, 14 + i * 30, w, 26), ui2.BoxStyle{
263 bg: p.theme.notice_bg
264 radius: 6
265 }, [ui2.label('', notice.text, ui2.rect(14, 5, w - 28, 16), label_text)])
266 }
267 }
268 dialog_body := [
269 ui2.label('', 'Playback speed (0.01 to 100)', ui2.rect(16, 16, 288, 22), label_text),
270 ui2.text_input(ui2.TextInputConfig{
271 id: 'speed_input'
272 frame: ui2.rect(16, 48, 288, 36)
273 text: p.speed_text
274 multiline: false
275 submit_id: 'speed_apply'
276 box: ui2.BoxStyle{
277 bg: p.theme.bg_dark
278 radius: 6
279 }
280 text_style: ui2.TextStyle{
281 color: p.theme.text_main
282 }
283 }) or { ui2.label('', '', ui2.rect(16, 48, 288, 36), label_text) },
284 ui2.button('speed_apply', 'Apply', ui2.rect(16, 110, 130, 36), button_box, button_text),
285 ui2.button('speed_cancel', 'Cancel', ui2.rect(174, 110, 130, 36), button_box, button_text),
286 ]
287 children << ui2.modal_view(ui2.ModalViewConfig{
288 id: 'speed_dialog'
289 frame: b
290 open: p.custom_open
291 dismiss_action_id: 'speed_cancel'
292 overlay_box: ui2.BoxStyle{
293 bg: p.theme.overlay_bg
294 opacity: 0.45
295 }
296 content_width: 320
297 content_height: 170
298 content_box: ui2.BoxStyle{
299 bg: p.theme.btn_secondary
300 radius: 10
301 }
302 content: ui2.view('', ui2.rect(0, 0, 320, 170), ui2.BoxStyle{
303 transparent: true
304 }, dialog_body)
305 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
306
307 queue_header := ui2.TextStyle{
308 color: p.theme.btn_primary
309 size: 11
310 }
311 queue_body_text := ui2.TextStyle{
312 color: p.theme.text_muted
313 size: 11
314 }
315 dialog_button := ui2.BoxStyle{
316 bg: p.theme.btn_secondary
317 radius: 6
318 }
319 dialog_button_text := ui2.TextStyle{
320 color: p.theme.text_main
321 size: 11
322 valign: .middle
323 }
324 // Max volume dialog: sets the upper bound of the volume slider.
325 max_volume_body := [
326 ui2.label('', 'Max volume (1 to 1000)', ui2.rect(12, 10, 296, 14), queue_header),
327 ui2.text_input(ui2.TextInputConfig{
328 id: 'max_volume_input'
329 frame: ui2.rect(12, 34, 296, 28)
330 text: p.max_volume_text
331 multiline: false
332 submit_id: 'max_volume_apply'
333 box: ui2.BoxStyle{
334 bg: p.theme.field_bg
335 radius: 6
336 }
337 text_style: ui2.TextStyle{
338 color: p.theme.text_main
339 }
340 }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },
341 ui2.button('max_volume_apply', 'Apply', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),
342 ui2.button('max_volume_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),
343 ]
344 children << ui2.modal_view(ui2.ModalViewConfig{
345 id: 'max_volume_dialog'
346 frame: b
347 open: p.max_volume_open
348 dismiss_action_id: 'max_volume_cancel'
349 overlay_box: ui2.BoxStyle{
350 bg: p.theme.overlay_bg
351 opacity: 0.45
352 }
353 content_width: 320
354 content_height: 106
355 content_box: ui2.BoxStyle{
356 bg: p.theme.bg_dark
357 opacity: 0.8
358 radius: 8
359 }
360 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{
361 transparent: true
362 }, max_volume_body)
363 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
364 // Save-queue dialog: names the current queue, saved under
365 // ~/.config/vendetta/queues/<name>.json. Same panel style; the input is a
366 // black inset on the dark card.
367 queue_name_body := [
368 ui2.label('', 'Save queue', ui2.rect(12, 10, 296, 14), queue_header),
369 ui2.text_input(ui2.TextInputConfig{
370 id: 'queue_name_input'
371 frame: ui2.rect(12, 34, 296, 28)
372 text: p.queue_name_text
373 multiline: false
374 submit_id: 'queue_name_apply'
375 box: ui2.BoxStyle{
376 bg: p.theme.field_bg
377 radius: 6
378 }
379 text_style: ui2.TextStyle{
380 color: p.theme.text_main
381 }
382 }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },
383 ui2.button('queue_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),
384 ui2.button('queue_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),
385 ]
386 children << ui2.modal_view(ui2.ModalViewConfig{
387 id: 'queue_name_dialog'
388 frame: b
389 open: p.queue_name_open
390 dismiss_action_id: 'queue_name_cancel'
391 overlay_box: ui2.BoxStyle{
392 bg: p.theme.overlay_bg
393 opacity: 0.45
394 }
395 content_width: 320
396 content_height: 106
397 content_box: ui2.BoxStyle{
398 bg: p.theme.bg_dark
399 opacity: 0.8
400 radius: 8
401 }
402 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{
403 transparent: true
404 }, queue_name_body)
405 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
406 // Save-playlist dialog: names the current queue, saved as an mpv-format
407 // playlist under ~/.config/vendetta/playlists/<name>.m3u. Mirrors the
408 // queue name dialog it sits beside; the same mpv demuxer-plus-editors
409 // read the file, so the slot is not vendetta's private state.
410 playlist_name_body := [
411 ui2.label('', 'Save playlist', ui2.rect(12, 10, 296, 14), queue_header),
412 ui2.text_input(ui2.TextInputConfig{
413 id: 'playlist_name_input'
414 frame: ui2.rect(12, 34, 296, 28)
415 text: p.playlist_name_text
416 multiline: false
417 submit_id: 'playlist_name_apply'
418 box: ui2.BoxStyle{
419 bg: p.theme.field_bg
420 radius: 6
421 }
422 text_style: ui2.TextStyle{
423 color: p.theme.text_main
424 }
425 }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },
426 ui2.button('playlist_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),
427 ui2.button('playlist_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),
428 ]
429 children << ui2.modal_view(ui2.ModalViewConfig{
430 id: 'playlist_name_dialog'
431 frame: b
432 open: p.playlist_name_open
433 dismiss_action_id: 'playlist_name_cancel'
434 overlay_box: ui2.BoxStyle{
435 bg: p.theme.overlay_bg
436 opacity: 0.45
437 }
438 content_width: 320
439 content_height: 106
440 content_box: ui2.BoxStyle{
441 bg: p.theme.bg_dark
442 opacity: 0.8
443 radius: 8
444 }
445 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{
446 transparent: true
447 }, playlist_name_body)
448 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
449 // Save-preset dialog: names the current options, saved under
450 // ~/.config/vendetta/presets/<name>.json. Same panel style as the queue
451 // name dialog it mirrors; the input is a black inset on the dark card.
452 preset_name_body := [
453 ui2.label('', 'Save options preset', ui2.rect(12, 10, 296, 14), queue_header),
454 ui2.text_input(ui2.TextInputConfig{
455 id: 'preset_name_input'
456 frame: ui2.rect(12, 34, 296, 28)
457 text: p.preset_name_text
458 multiline: false
459 submit_id: 'preset_name_apply'
460 box: ui2.BoxStyle{
461 bg: p.theme.field_bg
462 radius: 6
463 }
464 text_style: ui2.TextStyle{
465 color: p.theme.text_main
466 }
467 }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },
468 ui2.button('preset_name_apply', 'Save', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),
469 ui2.button('preset_name_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),
470 ]
471 children << ui2.modal_view(ui2.ModalViewConfig{
472 id: 'preset_name_dialog'
473 frame: b
474 open: p.preset_name_open
475 dismiss_action_id: 'preset_name_cancel'
476 overlay_box: ui2.BoxStyle{
477 bg: p.theme.overlay_bg
478 opacity: 0.45
479 }
480 content_width: 320
481 content_height: 106
482 content_box: ui2.BoxStyle{
483 bg: p.theme.bg_dark
484 opacity: 0.8
485 radius: 8
486 }
487 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{
488 transparent: true
489 }, preset_name_body)
490 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
491 // Mpv option dialog: takes any mpv option name and value and applies it
492 // live through the property interface. Options set here merge into the
493 // saved settings; an empty value unsets the option, which also stops it
494 // from coming back on the next start.
495 mpv_option_body := [
496 ui2.label('', 'Set mpv option', ui2.rect(12, 10, 296, 14), queue_header),
497 ui2.label('', 'Option name', ui2.rect(12, 26, 296, 14), queue_body_text),
498 ui2.text_input(ui2.TextInputConfig{
499 id: 'mpv_opt_name_input'
500 frame: ui2.rect(12, 42, 296, 26)
501 text: p.mpv_option_name_text
502 multiline: false
503 box: ui2.BoxStyle{
504 bg: p.theme.field_bg
505 radius: 6
506 }
507 text_style: ui2.TextStyle{
508 color: p.theme.text_main
509 }
510 }) or { ui2.label('', '', ui2.rect(12, 42, 296, 26), queue_body_text) },
511 ui2.label('', 'Value (empty unsets the option)', ui2.rect(12, 76, 296, 14), queue_body_text),
512 ui2.text_input(ui2.TextInputConfig{
513 id: 'mpv_opt_value_input'
514 frame: ui2.rect(12, 92, 296, 26)
515 text: p.mpv_option_value_text
516 multiline: false
517 submit_id: 'mpv_option_apply'
518 box: ui2.BoxStyle{
519 bg: p.theme.field_bg
520 radius: 6
521 }
522 text_style: ui2.TextStyle{
523 color: p.theme.text_main
524 }
525 }) or { ui2.label('', '', ui2.rect(12, 92, 296, 26), queue_body_text) },
526 ui2.button('mpv_option_apply', 'Apply', ui2.rect(12, 126, 86, 22), dialog_button, dialog_button_text),
527 ui2.button('mpv_option_cancel', 'Cancel', ui2.rect(106, 126, 86, 22), dialog_button, dialog_button_text),
528 ]
529 children << ui2.modal_view(ui2.ModalViewConfig{
530 id: 'mpv_option_dialog'
531 frame: b
532 open: p.mpv_option_open
533 dismiss_action_id: 'mpv_option_cancel'
534 overlay_box: ui2.BoxStyle{
535 bg: p.theme.overlay_bg
536 opacity: 0.45
537 }
538 content_width: 320
539 content_height: 158
540 content_box: ui2.BoxStyle{
541 bg: p.theme.bg_dark
542 opacity: 0.8
543 radius: 8
544 }
545 content: ui2.view('', ui2.rect(0, 0, 320, 158), ui2.BoxStyle{
546 transparent: true
547 }, mpv_option_body)
548 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
549 // Open URL dialog: a typed link takes the same open path as the picker's
550 // files, so Default open — ask, play now, add to queue — rules here too.
551 // Explicitly a link: apply refuses an entry without a protocol prefix
552 // instead of betting on mpv reaching it some other way.
553 url_body := [
554 ui2.label('', 'Open URL', ui2.rect(12, 10, 296, 14), queue_header),
555 ui2.text_input(ui2.TextInputConfig{
556 id: 'url_input'
557 frame: ui2.rect(12, 34, 296, 28)
558 text: p.url_text
559 hint_text: 'https://...'
560 multiline: false
561 submit_id: 'url_apply'
562 box: ui2.BoxStyle{
563 bg: p.theme.field_bg
564 radius: 6
565 }
566 text_style: ui2.TextStyle{
567 color: p.theme.text_main
568 }
569 }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },
570 ui2.button('url_apply', 'Open', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),
571 ui2.button('url_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),
572 ]
573 children << ui2.modal_view(ui2.ModalViewConfig{
574 id: 'url_dialog'
575 frame: b
576 open: p.url_open
577 dismiss_action_id: 'url_cancel'
578 overlay_box: ui2.BoxStyle{
579 bg: p.theme.overlay_bg
580 opacity: 0.45
581 }
582 content_width: 320
583 content_height: 106
584 content_box: ui2.BoxStyle{
585 bg: p.theme.bg_dark
586 opacity: 0.8
587 radius: 8
588 }
589 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{
590 transparent: true
591 }, url_body)
592 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
593 // Queue open choice dialog: Play now or Add to queue.
594 first := if p.queue_paths.len > 0 {
595 display_name(p.queue_paths[0], libvendetta.source_kind(p.queue_paths[0]))
596 } else {
597 ''
598 }
599 more := if p.queue_paths.len > 1 { ' and ${p.queue_paths.len - 1} more' } else { '' }
600 open_dialog_body := [
601 ui2.label('queue_dialog_title', 'Open video', ui2.rect(12, 10, 296, 14), queue_header),
602 ui2.label('queue_dialog_file', '${first}${more}', ui2.rect(12, 36, 296, 14), queue_body_text),
603 ui2.button('queue_play_now', 'Play now', ui2.rect(12, 62, 86, 22), dialog_button, dialog_button_text),
604 ui2.button('queue_add', 'Add to queue', ui2.rect(106, 62, 104, 22), dialog_button, dialog_button_text),
605 ui2.button('queue_cancel', 'Cancel', ui2.rect(218, 62, 62, 22), dialog_button, dialog_button_text),
606 ]
607 children << ui2.modal_view(ui2.ModalViewConfig{
608 id: 'queue_dialog'
609 frame: b
610 open: p.queue_open
611 dismiss_action_id: 'queue_cancel'
612 overlay_box: ui2.BoxStyle{
613 bg: p.theme.overlay_bg
614 opacity: 0.45
615 }
616 content_width: 320
617 content_height: 100
618 content_box: ui2.BoxStyle{
619 bg: p.theme.bg_dark
620 opacity: 0.8
621 radius: 8
622 }
623 content: ui2.view('', ui2.rect(0, 0, 320, 100), ui2.BoxStyle{
624 transparent: true
625 }, open_dialog_body)
626 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }
627 // Seek preview popup: the frame at the hovered seek position, taken by the
628 // hidden thumbnail instance so playback is never moved.
629 if p.preview_visible && p.preview_show_path.len > 0 && p.preview_show_w > 0 {
630 preview_text := ui2.TextStyle{
631 color: p.theme.text_muted
632 size: 11
633 }
634 mut thumb_w := 160.0
635 mut thumb_h := 90.0
636 thumb_h = thumb_w * p.preview_show_h / p.preview_show_w
637 if thumb_h > 90 {
638 thumb_h = 90
639 thumb_w = 90 * p.preview_show_w / p.preview_show_h
640 }
641 mut x := p.pointer_x - thumb_w / 2
642 if x < 0 {
643 x = 0
644 }
645 if x + thumb_w > b.width {
646 x = b.width - thumb_w
647 }
648 // The popup sits just above the control line, centred on the pointer.
649 y := bar.seek.y - thumb_h - 24
650 children << ui2.view('seek_preview_box', ui2.rect(x - 3, y - 3, thumb_w + 6, thumb_h + 24), ui2.BoxStyle{
651 bg: p.theme.bg_dark
652 opacity: 0.8
653 radius: 4
654 }, [])
655 children << ui2.image('seek_preview', p.preview_show_path, ui2.rect(x, y, thumb_w, thumb_h))
656 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)
657 }
658 $if render_stats_probe ? {
659 build_ms := f64(time.sys_mono_now() - build_t0) / 1e6
660 eprintln('probe view_build ${build_ms:.1f}ms')
661 }
662 return ui2.screen(p.theme.bg_surface, children)
663}
664
665// queue_config is the queue sidebar's reorder container description. The view
666// builds the tree from it (recording the frame on the player), and the pointer
667// and key handlers feed ui2.reorder_update / ui2.reorder_key the same shape,
668// so an event is answered against exactly the rows the screen shows.
669fn (p &Player) queue_config() ui2.ReorderConfig {
670 mut items := []ui2.Element{cap: p.queue_keys.len}
671 for i, key in p.queue_keys {
672 if i >= p.queue.len {
673 // The row keys and the queue are bound together everywhere; this
674 // only keeps a desync from reaching the container.
675 break
676 }
677 items << p.queue_row(i, key)
678 }
679 return ui2.ReorderConfig{
680 id: queue_list_id
681 frame: p.queue_frame
682 items: items
683 state: p.queue_state
684 // A hair between the tiles, and enough padding that the lifted row's
685 // shadow does not clip at the sidebar's edge.
686 gap: 2
687 padding: 4
688 // The scroll offset the reveal computations start from; the on_scroll
689 // handler feeds it back.
690 offset: p.queue_scroll
691 // Only the grip leads a drag, so the row's own remove button keeps
692 // its press.
693 handle: true
694 size: .small
695 theme: ui2.ComponentTheme{
696 background: p.theme.bg_dark
697 foreground: p.theme.text_muted
698 muted: p.theme.bg_surface
699 muted_foreground: p.theme.menu_disabled
700 border: p.theme.menu_border
701 primary: p.theme.btn_primary
702 primary_foreground: p.theme.bg_dark
703 }
704 accessibility_label: 'Playback queue'
705 }
706}
707
708// queue_row builds one entry the container wraps: the grip it draws ahead of
709// the row carries the drag, and the row itself holds the name and the remove
710// button. Only the row's height matters in its frame — the container
711// stretches it across the panel and places it on its own.
712fn (p &Player) queue_row(index int, key string) ui2.Element {
713 file := p.queue[index]
714 // The name reads through the entry's shape: a file is its basename, a
715 // link its URL name.
716 name := display_name(file, libvendetta.source_kind(file))
717 // The playing row says so: without the marker a reorder around the
718 // playing entry is unreadable — the user cannot tell which row the next
719 // track change follows. The marker stays in the text: the row's leading
720 // edge belongs to the drag grip.
721 playing := index == p.playlist_index && p.has_file
722 display := if playing { '▶ ' + name } else { name }
723 text := if playing {
724 ui2.TextStyle{
725 color: p.theme.btn_primary
726 size: 11
727 valign: .middle
728 }
729 } else {
730 ui2.TextStyle{
731 color: p.theme.text_muted
732 size: 11
733 valign: .middle
734 }
735 }
736 row := ui2.view('queue_row_${key}', ui2.rect(0, 0, 0, queue_row_h), ui2.BoxStyle{
737 bg: p.theme.bg_surface
738 radius: 5
739 }, [
740 ui2.label('', display, ui2.rect(6, 0, 280, queue_row_h), text),
741 ui2.button('queue_rm_${key}', '✕', ui2.rect(290, 3, 18, 18), ui2.BoxStyle{
742 bg: p.theme.btn_secondary
743 radius: 4
744 }, ui2.TextStyle{
745 color: p.theme.text_main
746 size: 10
747 valign: .middle
748 }),
749 ])
750 return ui2.Element{
751 ...row
752 key: key
753 }
754}
755