mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42: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
|
import gg
|
||||||
|
|
||||||
fn main() {
|
gg.start(
|
||||||
mut ctx := gg.new_context(
|
window_title: 'Hello'
|
||||||
window_title: 'Hello'
|
bg_color: gg.Color{240, 240, 128, 255}
|
||||||
bg_color: gg.Color{240, 240, 128, 255}
|
width: 320
|
||||||
width: 320
|
height: 240
|
||||||
height: 240
|
frame_fn: fn (ctx &gg.Context) {
|
||||||
frame_fn: on_frame
|
ctx.begin()
|
||||||
)
|
ctx.draw_text(40, 100, 'GG frame: ${ctx.frame:06}',
|
||||||
ctx.run()
|
size: 30
|
||||||
}
|
color: gg.Color{50, 50, 255, 255}
|
||||||
|
)
|
||||||
fn on_frame(ctx &gg.Context) {
|
ctx.show_fps()
|
||||||
ctx.begin()
|
ctx.end()
|
||||||
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
|
//---- 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.
|
// new_context returns an initialized `Context` allocated on the heap.
|
||||||
pub fn new_context(cfg Config) &Context {
|
pub fn new_context(cfg Config) &Context {
|
||||||
mut ctx := &Context{
|
mut ctx := &Context{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue