examples: shrink examples/gg/minimal.v even more

This commit is contained in:
Delyan Angelov 2023-12-29 16:46:18 +02:00
parent 0b4a93c1c1
commit c4180d4b06
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 25 additions and 17 deletions

View file

@ -1,19 +1,17 @@
import gg
fn main() {
mut ctx := gg.new_context(
window_title: 'Hello'
bg_color: gg.Color{240, 240, 128, 255}
width: 320
height: 240
frame_fn: on_frame
)
ctx.run()
}
fn on_frame(ctx &gg.Context) {
ctx.begin()
ctx.draw_text(40, 100, 'GG frame: ${ctx.frame:06}', size: 30, color: gg.Color{50, 50, 255, 255})
ctx.show_fps()
ctx.end()
}
gg.start(
window_title: 'Hello'
bg_color: gg.Color{240, 240, 128, 255}
width: 320
height: 240
frame_fn: fn (ctx &gg.Context) {
ctx.begin()
ctx.draw_text(40, 100, 'GG frame: ${ctx.frame:06}',
size: 30
color: gg.Color{50, 50, 255, 255}
)
ctx.show_fps()
ctx.end()
}
)

View file

@ -441,6 +441,16 @@ fn gg_fail_fn(msg &char, user_data voidptr) {
//---- public methods
// start creates a new context and runs it right away.
// It is a convenient way to start short/throwaway gg based prototypes,
// that do not need to keep and update their own state, like simple
// animations/visualisations that depend only on the time, or the ctx.frame counter.
// Use gg.new_context() for more complex ones.
pub fn start(cfg Config) {
mut ctx := new_context(cfg)
ctx.run()
}
// new_context returns an initialized `Context` allocated on the heap.
pub fn new_context(cfg Config) &Context {
mut ctx := &Context{