vendetta / examples / embed_host / main.v
37 lines · 33 sloc · 1.26 KB · e566477c350a80f9666b93ab0d991ad14f06df91
Raw
1import libvendetta
2import os
3import ui2
4
5// A browser-style <video> element: the whole host is one window with
6// vendetta's player filling it. Hover shows the controls, and the buttons and
7// sliders are vendetta's own elements — their clicks arrive here as vd_ events.
8fn main() {
9 // The repository ships no clip. Without one the window would stay empty, so
10 // say what to provide and stop.
11 if !os.exists('assets/video/test.mp4') {
12 eprintln('no test video found (expected assets/video/test.mp4 in the working directory)')
13 exit(1)
14 }
15 mut p := libvendetta.new(libvendetta.Config{})
16 p.load('assets/video/test.mp4')
17
18 // The only wiring a host owes the widget: hand it its GL surface, keep the
19 // hover timer fed, and forward the events it owns. handle() drops ids it
20 // does not know, so blind forwarding is safe.
21 ui2.set_gl_surface_renderer(fn [mut p] (id string, frame ui2.Rect, scale f64, height f64) {
22 p.render(id, frame, scale, height)
23 })
24 ui2.on_pointer_move(fn [mut p] (x f64, y f64) {
25 p.pointer_moved(x, y)
26 })
27
28 // The window: vendetta's element is the whole screen.
29 ui2.run_window('video', 960, 540, fn [mut p] () ui2.Element {
30 return p.build(ui2.bounds())
31 }, fn [mut p] (event string) {
32 p.handle(event)
33 })
34
35 // Window closed; free mpv.
36 p.destroy()
37}
38