v2 / vlib / gg / testdata / tweak_circles.vv
48 lines · 43 sloc · 757 bytes · 2332ecff4811b8c97dfda8e825170e9397962519
Raw
1module main
2
3import gg
4
5struct App {
6mut:
7 gg &gg.Context = unsafe { nil }
8 radius f64 = 10.0
9}
10
11fn main() {
12 mut app := &App{}
13 app.gg = gg.new_context(
14 bg_color: gg.white
15 width: 300
16 height: 300
17 window_title: 'Circles'
18 frame_fn: frame
19 event_fn: on_event
20 user_data: app
21 )
22 app.gg.run()
23}
24
25fn on_event(e &gg.Event, mut app App) {
26 match e.typ {
27 .key_down {
28 match e.key_code {
29 .up {
30 app.radius += 1
31 }
32 .down {
33 app.radius -= 1
34 }
35 else {}
36 }
37 }
38 else {}
39 }
40}
41
42fn frame(mut app App) {
43 app.gg.begin()
44 app.gg.draw_circle_empty(150, 150, f32(app.radius), gg.blue)
45 app.gg.draw_text(20, 20, 'radius: ${app.radius}')
46 // app.gg.draw_text(20, 50, 'circle_segment_size: ${circle_segment_size}')
47 app.gg.end()
48}
49