examples: fix compilation of the graph.v example
parent
93294d4a97
commit
2b545f6b90
|
@ -12,29 +12,33 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
|
mut:
|
||||||
gg &gg.Context
|
gg &gg.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gconfig := gg.Cfg {
|
mut context := &Context{
|
||||||
|
gg: 0
|
||||||
|
}
|
||||||
|
context.gg = gg.new_context({
|
||||||
width: size
|
width: size
|
||||||
height: size
|
height: size
|
||||||
|
font_size: 20
|
||||||
use_ortho: true
|
use_ortho: true
|
||||||
create_window: true
|
user_data: context
|
||||||
window_title: 'Graph builder'
|
window_title: 'Graph builder'
|
||||||
always_on_top: true
|
create_window: true
|
||||||
|
frame_fn: frame
|
||||||
|
bg_color: gx.white
|
||||||
|
font_path: gg.system_font_path()
|
||||||
|
})
|
||||||
|
context.gg.run()
|
||||||
}
|
}
|
||||||
ctx := &Context{ gg: gg.new_context(gconfig) }
|
|
||||||
ctx.gg.window.set_user_ptr( ctx )
|
fn frame(mut ctx Context) {
|
||||||
go update() // update the scene in the background in case the window isn't focused
|
ctx.gg.begin()
|
||||||
for {
|
|
||||||
if ctx.gg.window.should_close() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
gg.clear(gx.white)
|
|
||||||
ctx.draw()
|
ctx.draw()
|
||||||
ctx.gg.render()
|
ctx.gg.end()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[live]
|
[live]
|
||||||
|
@ -60,10 +64,3 @@ fn (ctx &Context) draw() {
|
||||||
ctx.gg.draw_rect(f32(center + x * scale), f32(center + y * scale), 1, 1, gx.red)
|
ctx.gg.draw_rect(f32(center + x * scale), f32(center + y * scale), 1, 1, gx.red)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update() {
|
|
||||||
for {
|
|
||||||
gg.post_empty_event()
|
|
||||||
time.sleep_ms(16) // 60 fps
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue