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