// host_proto is a dummy host app: its own header and sidebar, with the Vendetta // widget in a frame inside the window. The sidebar checkbox switches the // widget's input scope between its frame and the whole window. // // v examples/host_proto/main.v [docked] // // It plays assets/video/test.mp4 from the working directory. The repository // ships no clip, so put one there first. import libvendetta import os import ui2 const header_h = 40.0 const sidebar_w = 220.0 struct Host { mut: player &libvendetta.Player localised bool = true } fn (mut h Host) view() ui2.Element { b := ui2.bounds() widget := h.player.build(ui2.rect(sidebar_w, header_h, b.width - sidebar_w, b.height - header_h)) text := ui2.TextStyle{ color: 0xe5e7eb size: 13 valign: .middle } scope := if h.localised { 'frame' } else { 'window' } mut children := []ui2.Element{} children << ui2.view('host_header', ui2.rect(0, 0, b.width, header_h), ui2.BoxStyle{ bg: 0x1f2937 }, []) children << ui2.label('host_title', 'dummy host app', ui2.rect(12, 0, 300, header_h), ui2.TextStyle{ color: 0xf9fafb size: 15 valign: .middle }) children << ui2.view('host_sidebar', ui2.rect(0, header_h, sidebar_w, b.height - header_h), ui2.BoxStyle{ bg: 0x111827 }, []) children << ui2.label('host_input', 'input scope: ${scope}', ui2.rect(12, header_h + 12, sidebar_w - 24, 18), text) children << ui2.checkbox('host_scope', 'localise input', h.localised, ui2.rect(12, header_h + 40, sidebar_w - 24, 24), text) children << ui2.button('host_pause', 'pause (host)', ui2.rect(12, header_h + 76, sidebar_w - 24, 28), ui2.BoxStyle{ bg: 0x3b82f6 radius: 6 }, ui2.TextStyle{ color: 0xffffff size: 13 align: .center valign: .middle }) children << ui2.checkbox('host_overlay', 'floating controls', h.player.cfg.overlay, ui2.rect(12, header_h + 116, sidebar_w - 24, 24), text) children << widget return ui2.screen(0x0b1120, children) } fn (mut h Host) handle(event string) { match event { 'host_scope' { h.localised = !h.localised h.player.set_input_scope(if h.localised { libvendetta.InputScope.frame } else { libvendetta.InputScope.window }) } 'host_overlay' { h.player.set_overlay(!h.player.cfg.overlay) } 'host_pause' { h.player.toggle_play() } else { h.player.handle(event) } } } fn main() { if !os.exists('assets/video/test.mp4') { eprintln('no test video found (expected assets/video/test.mp4 in the working directory)') exit(1) } mut player := libvendetta.new(libvendetta.Config{}) player.load('assets/video/test.mp4') if os.args.contains('docked') { player.set_overlay(false) } // Every forwarded event goes to the player. It decides, per its input // scope, whether the event is for the widget. ui2.set_gl_surface_renderer(fn [mut player] (id string, frame ui2.Rect, scale f64, height f64) { player.render(id, frame, scale, height) }) ui2.on_pointer_move(fn [mut player] (x f64, y f64) { player.pointer_moved(x, y) }) ui2.on_mouse_button(fn [mut player] (button int, down bool, x f64, y f64) { player.mouse_button(button, down, x, y) }) ui2.on_wheel(fn [mut player] (dx f64, dy f64) { player.wheel(dx, dy) }) ui2.on_key(fn [mut player] (key string) { player.key(key) }) mut host := &Host{ player: player } ui2.run_window('vendetta in a dummy host', 960, 600, fn [mut host] () ui2.Element { return host.view() }, fn [mut host] (event string) { host.handle(event) }) player.destroy() }