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