mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
examples: shrink examples/gg/minimal.v even more
This commit is contained in:
parent
0b4a93c1c1
commit
c4180d4b06
2 changed files with 25 additions and 17 deletions
|
@ -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()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue