| 1 | module main |
| 2 | |
| 3 | import vx11 |
| 4 | |
| 5 | // A bound method can be passed directly to Connection.run. |
| 6 | @[heap] |
| 7 | struct App { |
| 8 | window &vx11.WindowHandle |
| 9 | } |
| 10 | |
| 11 | fn (app &App) on_event(event vx11.Event) bool { |
| 12 | if app.window.should_close(event) { return false } |
| 13 | if key := event.key() { |
| 14 | println('key ${key.code}, modifiers ${key.state}, position ${key.x},${key.y}') |
| 15 | return false |
| 16 | } |
| 17 | if size := event.configure() { println('resized to ${size.width} x ${size.height}') } |
| 18 | return true |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | mut display := vx11.connect('')! |
| 23 | defer { display.close() } |
| 24 | mut window := display.new_window(title: 'V method callbacks')! |
| 25 | defer { window.destroy() } |
| 26 | window.show()! |
| 27 | app := App{window} |
| 28 | display.run(app.on_event)! |
| 29 | } |
| 30 | |