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