fmt: fix alignment of struct init fields (#22025)

This commit is contained in:
yuyi 2024-08-11 14:11:24 +08:00 committed by GitHub
parent 99da5726db
commit c51d30bf53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
671 changed files with 18817 additions and 18787 deletions

View file

@ -48,12 +48,12 @@ struct Theme {
const themes = [
&Theme{
bg_color: gx.rgb(250, 248, 239)
padding_color: gx.rgb(143, 130, 119)
victory_color: gx.rgb(100, 160, 100)
bg_color: gx.rgb(250, 248, 239)
padding_color: gx.rgb(143, 130, 119)
victory_color: gx.rgb(100, 160, 100)
game_over_color: gx.rgb(190, 50, 50)
text_color: gx.black
tile_colors: [
text_color: gx.black
tile_colors: [
gx.rgb(205, 193, 180), // Empty / 0 tile
gx.rgb(238, 228, 218), // 2
gx.rgb(237, 224, 200), // 4
@ -69,12 +69,12 @@ const themes = [
]
},
&Theme{
bg_color: gx.rgb(55, 55, 55)
padding_color: gx.rgb(68, 60, 59)
victory_color: gx.rgb(100, 160, 100)
bg_color: gx.rgb(55, 55, 55)
padding_color: gx.rgb(68, 60, 59)
victory_color: gx.rgb(100, 160, 100)
game_over_color: gx.rgb(190, 50, 50)
text_color: gx.white
tile_colors: [
text_color: gx.white
tile_colors: [
gx.rgb(123, 115, 108),
gx.rgb(142, 136, 130),
gx.rgb(142, 134, 120),
@ -90,12 +90,12 @@ const themes = [
]
},
&Theme{
bg_color: gx.rgb(38, 38, 66)
padding_color: gx.rgb(58, 50, 74)
victory_color: gx.rgb(100, 160, 100)
bg_color: gx.rgb(38, 38, 66)
padding_color: gx.rgb(58, 50, 74)
victory_color: gx.rgb(100, 160, 100)
game_over_color: gx.rgb(190, 50, 50)
text_color: gx.white
tile_colors: [
text_color: gx.white
tile_colors: [
gx.rgb(92, 86, 140),
gx.rgb(106, 99, 169),
gx.rgb(106, 97, 156),
@ -489,56 +489,56 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
match kind {
.keys {
return gx.TextCfg{
color: gx.Color{150, 150, 255, 200}
align: .center
color: gx.Color{150, 150, 255, 200}
align: .center
vertical_align: .bottom
size: app.ui.font_size / 4
size: app.ui.font_size / 4
}
}
.points {
return gx.TextCfg{
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
align: .left
size: app.ui.font_size / 2
size: app.ui.font_size / 2
}
}
.moves {
return gx.TextCfg{
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
align: .right
size: app.ui.font_size / 2
size: app.ui.font_size / 2
}
}
.tile {
return gx.TextCfg{
color: app.theme.text_color
align: .center
color: app.theme.text_color
align: .center
vertical_align: .middle
size: app.ui.font_size
size: app.ui.font_size
}
}
.victory {
return gx.TextCfg{
color: app.theme.victory_color
align: .center
color: app.theme.victory_color
align: .center
vertical_align: .middle
size: app.ui.font_size * 2
size: app.ui.font_size * 2
}
}
.game_over {
return gx.TextCfg{
color: app.theme.game_over_color
align: .center
color: app.theme.game_over_color
align: .center
vertical_align: .middle
size: app.ui.font_size * 2
size: app.ui.font_size * 2
}
}
.score_end {
return gx.TextCfg{
color: gx.white
align: .center
color: gx.white
align: .center
vertical_align: .middle
size: app.ui.font_size * 3 / 4
size: app.ui.font_size * 3 / 4
}
}
}
@ -597,7 +597,7 @@ fn (app &App) draw() {
app.gg.draw_text(ww / 2, (m * 6 / 10) + ypad, msg, gx.TextCfg{
...f
color: gx.white
size: f.size * 3 / 4
size: f.size * 3 / 4
})
}
if app.state == .victory {
@ -660,7 +660,7 @@ fn (app &App) draw_tiles() {
app.gg.draw_text(xpos + app.ui.tile_size / 10, ypos - app.ui.tile_size / 8,
'${tidx}', gx.TextCfg{
...fmt
size: fs2
size: fs2
align: gx.HorizontalAlign.left
})
}
@ -900,16 +900,16 @@ fn main() {
font_path = 'fonts/RobotoMono-Regular.ttf'
}
app.gg = gg.new_context(
bg_color: app.theme.bg_color
width: default_window_width
height: default_window_height
bg_color: app.theme.bg_color
width: default_window_width
height: default_window_height
sample_count: 2 // higher quality curves
window_title: 'V 2048'
frame_fn: frame
event_fn: on_event
init_fn: init
user_data: app
font_path: font_path
frame_fn: frame
event_fn: on_event
init_fn: init
user_data: app
font_path: font_path
)
app.gg.run()
}

View file

@ -5,35 +5,35 @@ import os
fn main() {
mut cmd := Command{
name: 'cli'
name: 'cli'
description: 'An example of the cli library.'
version: '1.0.0'
version: '1.0.0'
}
mut greet_cmd := Command{
name: 'greet'
description: 'Prints greeting in different languages.'
usage: '<name>'
name: 'greet'
description: 'Prints greeting in different languages.'
usage: '<name>'
required_args: 1
pre_execute: greet_pre_func
execute: greet_func
post_execute: greet_post_func
pre_execute: greet_pre_func
execute: greet_func
post_execute: greet_post_func
}
greet_cmd.add_flag(Flag{
flag: .string
required: true
name: 'language'
abbrev: 'l'
flag: .string
required: true
name: 'language'
abbrev: 'l'
description: 'Language of the message.'
})
greet_cmd.add_flag(Flag{
flag: .int
name: 'times'
flag: .int
name: 'times'
default_value: ['3']
description: 'Number of times the message gets printed.'
description: 'Number of times the message gets printed.'
})
greet_cmd.add_flag(Flag{
flag: .string_array
name: 'fun'
flag: .string_array
name: 'fun'
description: 'Just a dumby flags to show multiple.'
})
cmd.add_command(greet_cmd)

View file

@ -155,15 +155,15 @@ fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: design_size
height: design_size
width: design_size
height: design_size
window_title: 'Clock!'
bg_color: gx.white
user_data: app
frame_fn: on_frame
event_fn: on_event
init_fn: on_init
font_path: font_path
bg_color: gx.white
user_data: app
frame_fn: on_frame
event_fn: on_event
init_fn: on_init
font_path: font_path
)
app.gg.run()

View file

@ -2,11 +2,11 @@ import db.mysql
fn main() {
mut conn := mysql.connect(
host: 'localhost'
port: 3306
host: 'localhost'
port: 3306
username: 'root'
password: ''
dbname: 'mysql'
dbname: 'mysql'
)!
res := conn.query('show tables')!
for row in res.rows() {

View file

@ -77,7 +77,7 @@ fn sqlite3_array() ! {
create table Child
}!
par := Parent{
name: 'test'
name: 'test'
children: [
Child{
name: 'abc'
@ -99,11 +99,11 @@ fn sqlite3_array() ! {
fn msql_array() ! {
eprintln('------------ ${@METHOD} -----------------')
mut db := mysql.connect(
host: mysql_host
port: mysql_port
host: mysql_host
port: mysql_port
username: mysql_user
password: mysql_pass
dbname: mysql_db
dbname: mysql_db
)!
defer {
sql db {
@ -119,7 +119,7 @@ fn msql_array() ! {
create table Child
}!
par := Parent{
name: 'test'
name: 'test'
children: [
Child{
name: 'abc'
@ -152,7 +152,7 @@ fn psql_array() ! {
create table Child
}!
par := Parent{
name: 'test'
name: 'test'
children: [
Child{
name: 'abc'
@ -189,11 +189,11 @@ fn sqlite3() ! {
create table User
}!
mod := Module{
name: 'test'
name: 'test'
nr_downloads: 10
creator: User{
age: 21
name: 'VUser'
creator: User{
age: 21
name: 'VUser'
is_customer: true
}
}
@ -209,11 +209,11 @@ fn sqlite3() ! {
fn msql() ! {
eprintln('------------ ${@METHOD} -----------------')
mut conn := mysql.connect(
host: mysql_host
port: mysql_port
host: mysql_host
port: mysql_port
username: mysql_user
password: mysql_pass
dbname: mysql_db
dbname: mysql_db
)!
defer {
conn.query('DROP TABLE IF EXISTS Module') or { eprintln(err) }
@ -230,11 +230,11 @@ fn msql() ! {
create table User
}!
mod := Module{
name: 'test'
name: 'test'
nr_downloads: 10
creator: User{
age: 21
name: 'VUser'
creator: User{
age: 21
name: 'VUser'
is_customer: true
}
}
@ -260,11 +260,11 @@ fn psql() ! {
create table User
}!
mod := Module{
name: 'test'
name: 'test'
nr_downloads: 10
creator: User{
age: 21
name: 'VUser'
creator: User{
age: 21
name: 'VUser'
is_customer: true
}
}

View file

@ -19,7 +19,7 @@ const default_paths = [
fn main() {
mut dl_loader := loader.get_or_create_dynamic_lib_loader(
key: cfolder + '/library'
key: cfolder + '/library'
paths: default_paths
)!
defer {

View file

@ -28,7 +28,7 @@ struct UserAgent {
url := 'http://ifconfig.co/json'
resp := http.fetch(
url: url
url: url
user_agent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0'
) or {
eprintln('failed to fetch data from the server, error: ${err}')

View file

@ -103,14 +103,14 @@ fn main() {
app.ui = objects.get_params()
app.gg = gg.new_context(
width: app.ui.width
height: app.ui.height
width: app.ui.width
height: app.ui.height
window_title: 'Fireworks!'
bg_color: gx.black
user_data: app
frame_fn: on_frame
event_fn: on_event
font_path: font_path
bg_color: gx.black
user_data: app
frame_fn: on_frame
event_fn: on_event
font_path: font_path
)
app.gg.run()

View file

@ -50,7 +50,7 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
pub fn new_rocket() Rocket {
return Rocket{
color: random_color()
pos: Vector{
pos: Vector{
x: rand.f32_in_range(50, get_params().width - 50) or { 50 }
}
vel: Vector{
@ -63,7 +63,7 @@ pub fn new_rocket() Rocket {
pub fn (mut rocket Rocket) spawn_particle() {
rocket.particles << Particle{
color: rocket.color
pos: rocket.pos
pos: rocket.pos
accel: random_vector_in_circle().mult(2)
}
}

View file

@ -53,7 +53,7 @@ fn frame(mut app App) {
}
help_text := flag.to_doc[DocTest](
version: '1.0'
version: '1.0'
description: 'Hello! This should show an *animated* example application description.
We are at frame ${app.frame}.
Press ESCAPE or Ctrl+C to exit'
@ -82,11 +82,11 @@ type FrameFn = fn (voidptr)
fn main() {
mut app := &App{}
app.tui = tui.init(
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
hide_cursor: true
frame_rate: 60
frame_rate: 60
)
app.tui.run()!
}

View file

@ -211,8 +211,8 @@ Editing property: ${app.edit}, value: ${value}')
Press ESCAPE or Ctrl+C to exit and print layout code'
footer: '
Press ESCAPE or Ctrl+C to exit and print layout code'
fields: unsafe { field_docs }
layout: app.layout
fields: unsafe { field_docs }
layout: app.layout
options: app.options
) or { '' }
@ -233,11 +233,11 @@ fn main() {
println('${app.options}')
}) or {}
app.tui = tui.init(
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
hide_cursor: true
frame_rate: 60
frame_rate: 60
)
app.tui.run()!
}

View file

@ -153,13 +153,13 @@ fn (mut app App) update() {
holl_position := math.round(rand.f64() * (app.height - delta_bord * 2.0 - pipe_holl)) +
delta_bord
app.pipes << Pipe{
x: app.width
y: 0
x: app.width
y: 0
height: holl_position
}
app.pipes << Pipe{
x: app.width
y: holl_position + pipe_holl
x: app.width
y: holl_position + pipe_holl
height: app.height
}
}
@ -178,20 +178,20 @@ fn main() {
font_path = 'fonts/RobotoMono-Regular.ttf'
}
app.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'flappylearning-v'
frame_fn: frame
event_fn: on_event
user_data: app
init_fn: app.init_images_wrapper
font_path: font_path
window_title: 'flappylearning-v'
frame_fn: frame
event_fn: on_event
user_data: app
init_fn: app.init_images_wrapper
font_path: font_path
)
app.nv = neuroevolution.Generations{
population: 50
network: [2, 2, 1]
network: [2, 2, 1]
}
app.start()
spawn app.run()

View file

@ -281,7 +281,7 @@ pub fn (mut gs Generations) generate() []Network {
pub fn (mut gs Generations) network_score(network Network, score int) {
gs.add_genome(Genome{
score: score
score: score
network: network.get_save()
})
}

View file

@ -40,14 +40,14 @@ fn main() {
a: automaton.gun()
}
app.gg = gg.new_context(
bg_color: gx.white
frame_fn: frame
user_data: &app
width: screen_width
height: screen_height
bg_color: gx.white
frame_fn: frame
user_data: &app
width: screen_width
height: screen_height
create_window: true
resizable: false
window_title: 'v life (with gg, gx)'
resizable: false
window_title: 'v life (with gg, gx)'
)
app.gg.run()
}

View file

@ -70,7 +70,7 @@ fn new_automaton(ftext string) Automaton {
}
}
return Automaton{
field: field
field: field
new_field: new_field
}
}

View file

@ -21,12 +21,12 @@ pub fn (mut window Window) draw(_ voidptr) {
window.ctx.begin()
myconfig := gg.DrawImageConfig{
img: &window.image
img_id: window.image.id
img: &window.image
img_id: window.image.id
img_rect: gg.Rect{
x: 400 - window.image.width / 2
y: 300 - window.image.height / 2
width: window.image.width
x: 400 - window.image.width / 2
y: 300 - window.image.height / 2
width: window.image.width
height: window.image.height
}
rotation: f32(window.ctx.frame)
@ -42,7 +42,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 60)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 60)
}
color: gx.Color{255, 0, 0, 255}
color: gx.Color{255, 0, 0, 255}
effect: .add
})
@ -54,7 +54,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 80)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 80)
}
color: gx.Color{0, 255, 0, 255}
color: gx.Color{0, 255, 0, 255}
effect: .add
})
@ -66,7 +66,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 100)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 100)
}
color: gx.Color{0, 0, 255, 255}
color: gx.Color{0, 0, 255, 255}
effect: .add
})
@ -78,7 +78,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 0
}
color: gx.Color{255, 0, 0, 255}
color: gx.Color{255, 0, 0, 255}
effect: .add
})
@ -89,7 +89,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 50
}
color: gx.Color{0, 255, 0, 255}
color: gx.Color{0, 255, 0, 255}
effect: .add
})
@ -100,7 +100,7 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 100
}
color: gx.Color{0, 0, 255, 255}
color: gx.Color{0, 0, 255, 255}
effect: .add
})
@ -112,12 +112,12 @@ fn main() {
window.ctx = gg.new_context(
window_title: 'Additive colors & image rotation'
width: 800
height: 600
user_data: window
bg_color: gx.gray
width: 800
height: 600
user_data: window
bg_color: gx.gray
// FNs
init_fn: window.init
init_fn: window.init
frame_fn: window.draw
)

View file

@ -33,14 +33,14 @@ mut:
fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: 'Arcs and Slices'
user_data: app
bg_color: bg_color
frame_fn: on_frame
event_fn: on_event
window_title: 'Arcs and Slices'
user_data: app
bg_color: bg_color
frame_fn: on_frame
event_fn: on_event
)
app.gg.run()
}

View file

@ -14,12 +14,12 @@ mut:
fn main() {
mut app := &App{}
app.gg = gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
window_title: 'Cubic Bézier curve'
frame_fn: frame
user_data: app
frame_fn: frame
user_data: app
)
app.gg.run()
}

View file

@ -34,12 +34,12 @@ fn main() {
anim: &Anim{}
}
app.gg = gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
window_title: 'Animated cubic Bézier curve'
frame_fn: frame
user_data: app
frame_fn: frame
user_data: app
)
app.gg.run()
}

View file

@ -6,10 +6,10 @@ import sokol.sapp
fn main() {
mut ctx := gg.new_context(
bg_color: gx.white
bg_color: gx.white
window_title: 'Cursor'
frame_fn: frame
init_fn: init
frame_fn: frame
init_fn: init
)
ctx.run()
}

View file

@ -37,12 +37,12 @@ fn main() {
fn rain(mut app App) {
app.ctx = gg.new_context(
bg_color: gx.rgb(0, 0, 0)
width: app.screen_size.width
height: app.screen_size.height
user_data: app
bg_color: gx.rgb(0, 0, 0)
width: app.screen_size.width
height: app.screen_size.height
user_data: app
window_title: 'Digital Rain'
init_fn: fn (mut app App) {
init_fn: fn (mut app App) {
gg.toggle_fullscreen()
}
event_fn: fn (event &gg.Event, mut app App) {
@ -99,9 +99,9 @@ fn vprintln(msg string) {
fn calc_sizes(mut app App) {
app.screen_size = gg.window_size()
app.ctx.set_text_cfg(gx.TextCfg{
size: font_size
size: font_size
color: gx.green
mono: true
mono: true
})
// figure out how big character is in pixels
// Pad it or it looks too squashed
@ -139,7 +139,7 @@ fn draw_rain_column(rc RainColumn, app App) {
}
at_head := i == rc.head - 1
cfg := gx.TextCfg{
size: font_size
size: font_size
color: gg.Color{
r: if at_head { u8(255) } else { 0 }
g: 255
@ -163,8 +163,8 @@ fn draw_rain_column(rc RainColumn, app App) {
fn random_rain_column(max_col int, max_height int) RainColumn {
min_len := 6
mut rc := RainColumn{
col: rand.int_in_range(0, max_col) or { 0 }
len: rand.int_in_range(min_len, max_height / 4 * 3) or { min_len }
col: rand.int_in_range(0, max_col) or { 0 }
len: rand.int_in_range(min_len, max_height / 4 * 3) or { min_len }
drops: []u8{cap: max_height}
}
for _ in 0 .. max_height {

View file

@ -19,17 +19,17 @@ fn main() {
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
mut app := &App{}
app.gg = gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
window_title: 'Drag and drop'
frame_fn: frame
font_path: font_path
user_data: app
event_fn: my_event_manager
frame_fn: frame
font_path: font_path
user_data: app
event_fn: my_event_manager
// drag & drop
enable_dragndrop: true
max_dropped_files: max_files
enable_dragndrop: true
max_dropped_files: max_files
max_dropped_file_path_length: 2048
)
app.gg.run()
@ -52,7 +52,7 @@ fn frame(mut app App) {
mut txt_conf := gx.TextCfg{
color: gx.black
align: .left
size: int(text_size * app.gg.scale + 0.5)
size: int(text_size * app.gg.scale + 0.5)
}
app.gg.draw_text(12, 12, text, txt_conf)

View file

@ -28,12 +28,12 @@ fn main() {
pixels: pixels
}
app.gg = gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 100
height: 100
bg_color: gx.rgb(174, 198, 255)
width: 100
height: 100
window_title: 'Set Pixels'
frame_fn: frame
user_data: app
frame_fn: frame
user_data: app
)
app.gg.run()
}

View file

@ -63,14 +63,14 @@ fn main() {
app.buf << []int{len: width, init: 36} // white fire base
app.gg = gg.new_context(
event_fn: event
frame_fn: frame
init_fn: retile
event_fn: event
frame_fn: frame
init_fn: retile
window_title: 'Fire Animation'
user_data: app
bg_color: palette[0]
width: win_width
height: win_height
user_data: app
bg_color: palette[0]
width: win_width
height: win_height
)
app.gg.run()
}

View file

@ -75,8 +75,8 @@ fn (mut state AppState) update() {
for start := 0; start < pheight; start += chunk_height {
chunk_channel <- MandelChunk{
cview: cview
ymin: start
ymax: start + chunk_height
ymin: start
ymax: start + chunk_height
}
nchunks++
}
@ -225,17 +225,17 @@ fn graphics_keydown(code gg.KeyCode, mod gg.Modifier, mut state AppState) {
fn main() {
mut state := &AppState{}
state.gg = gg.new_context(
width: 800
height: 600
width: 800
height: 600
create_window: true
window_title: 'The Mandelbrot Set'
init_fn: graphics_init
frame_fn: graphics_frame
click_fn: graphics_click
move_fn: graphics_move
keydown_fn: graphics_keydown
scroll_fn: graphics_scroll
user_data: state
window_title: 'The Mandelbrot Set'
init_fn: graphics_init
frame_fn: graphics_frame
click_fn: graphics_click
move_fn: graphics_move
keydown_fn: graphics_keydown
scroll_fn: graphics_scroll
user_data: state
)
spawn state.update()
state.gg.run()

View file

@ -47,10 +47,10 @@ fn frame(mut ctx gg.Context) {
fn main() {
mut ctx := gg.new_context(
window_title: 'Many Thousands of Circles'
bg_color: gx.black
width: 600
height: 400
frame_fn: frame
bg_color: gx.black
width: 600
height: 400
frame_fn: frame
)
ctx.run()
}

View file

@ -2,13 +2,13 @@ import gg
gg.start(
window_title: 'Hello'
bg_color: gg.Color{240, 240, 128, 255}
width: 320
height: 240
frame_fn: fn (ctx &gg.Context) {
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
size: 30
color: gg.Color{50, 50, 255, 255}
)
ctx.show_fps()

View file

@ -76,15 +76,15 @@ fn main() {
// setting values of app
app.gg = gg.new_context(
bg_color: gx.black // background color
width: window_width // window width
height: window_height // window height
bg_color: gx.black // background color
width: window_width // window width
height: window_height // window height
create_window: true // this will create a different window
window_title: 'A* Path finding algorithm visusalizer' // title of the window
frame_fn: frame // this is frame function update the frame
event_fn: on_event // it calls on every event
init_fn: init_images // run at start of application
user_data: app // store user data
window_title: 'A* Path finding algorithm visusalizer' // title of the window
frame_fn: frame // this is frame function update the frame
event_fn: on_event // it calls on every event
init_fn: init_images // run at start of application
user_data: app // store user data
)
mut grid := initialise_grid() // initialize the grid variable and populate the matrix with each cell as empty
app.grid = grid // set grid to app attribute so you can access it by just passing app variable or with method of app
@ -244,15 +244,15 @@ fn initialise_grid() [][]Cell {
for i := 0; i < nrows; i++ {
for j := 0; j < nrows; j++ {
grid[i][j] = &Cell{
row: i
col: j
row: i
col: j
width: gap
pos: &Point{
pos: &Point{
x: j * gap
y: i * gap
}
color: gx.white
flag: 0
flag: 0
}
}
}
@ -331,7 +331,7 @@ fn astar_path_finding(mut app App, mut grid [][]Cell, start Point, end Point) {
f_score[start.x][start.y] = g_score[start.x][start.y] + hf(start, end)
priority_queue.insert(&Node{
f_score: f_score[start.x][start.y]
cell: &Point{
cell: &Point{
x: start.x
y: start.y
}
@ -362,8 +362,8 @@ fn astar_path_finding(mut app App, mut grid [][]Cell, start Point, end Point) {
if !(neighbor.x == start.x && neighbor.y == start.y) {
priority_queue.insert(&Node{
f_score: g_score[neighbor.x][neighbor.y] + hf(neighbor, end)
cell: neighbor
count: curr_node.count + 1
cell: neighbor
count: curr_node.count + 1
})
came_from[neighbor.x][neighbor.y] = curr_pos
set_cell_type(mut grid, neighbor.x, neighbor.y, 'open')

View file

@ -5,11 +5,11 @@ import gx
fn main() {
mut context := gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
bg_color: gx.rgb(174, 198, 255)
width: 600
height: 400
window_title: 'Polygons'
frame_fn: frame
frame_fn: frame
)
context.run()
}

View file

@ -50,13 +50,13 @@ fn graphics_frame(mut state AppState) {
fn main() {
mut state := &AppState{}
state.gg = gg.new_context(
width: 800
height: 600
width: 800
height: 600
create_window: true
window_title: 'Random Static'
init_fn: graphics_init
frame_fn: graphics_frame
user_data: state
window_title: 'Random Static'
init_fn: graphics_init
frame_fn: graphics_frame
user_data: state
)
spawn state.update()
state.gg.run()

View file

@ -67,14 +67,14 @@ fn main() {
font_path = 'fonts/RobotoMono-Regular.ttf'
}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: 'Raven text'
user_data: app
bg_color: bg_color
frame_fn: frame
font_path: font_path // window_user_ptr: ctx
window_title: 'Raven text'
user_data: app
bg_color: bg_color
frame_fn: frame
font_path: font_path // window_user_ptr: ctx
// native_rendering: true
)
app.gg.run()

View file

@ -55,13 +55,13 @@ fn main() {
calc_deltas(mut app)
app.ctx = gg.new_context(
user_data: &app
user_data: &app
window_title: 'Raycaster Demo'
width: 1024
height: 512
bg_color: gx.gray
frame_fn: draw
event_fn: handle_events
width: 1024
height: 512
bg_color: gx.gray
frame_fn: draw
event_fn: handle_events
)
app.ctx.run()
@ -217,7 +217,7 @@ fn draw_rays_and_walls(app App) {
wall_offset := max_wall_height / 2 - wall_height / 2
app.ctx.draw_line_with_config(step * line_thickeness + offset_3d_view, wall_offset,
step * line_thickeness + offset_3d_view, wall_offset + wall_height, gg.PenConfig{
color: color
color: color
thickness: line_thickeness
})
// step to next ray angle

View file

@ -16,14 +16,14 @@ mut:
fn main() {
mut app := &App{}
app.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'Rectangles'
frame_fn: frame
user_data: app
init_fn: init_images
window_title: 'Rectangles'
frame_fn: frame
user_data: app
init_fn: init_images
)
mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
app.image = app.gg.create_image(logo_path)!.id

View file

@ -43,12 +43,12 @@ fn main() {
mut window := &Window{}
window.ctx = gg.new_context(
window_title: 'Rotating V logo'
bg_color: gx.light_green
width: 800
height: 800
user_data: window
init_fn: window.init
frame_fn: window.draw
bg_color: gx.light_green
width: 800
height: 800
user_data: window
init_fn: window.init
frame_fn: window.draw
)
window.ctx.run()
}

View file

@ -8,12 +8,12 @@ fn main() {
scount := os.args[1] or { '2' }.int()
println('> sample count: ${scount}')
mut ctx := gg.new_context(
bg_color: gx.white
bg_color: gx.white
window_title: 'sample_count: ${scount}'
width: 320
height: 240
width: 320
height: 240
sample_count: scount
frame_fn: fn (mut ctx gg.Context) {
frame_fn: fn (mut ctx gg.Context) {
ctx.begin()
ctx.draw_rounded_rect_empty(110, 70, 100, 100, 10, gx.blue)
ctx.draw_circle_empty(160, 120, 100, gx.red)

View file

@ -19,11 +19,11 @@ mut k := 497
mut scale := 200
gg.start(
window_title: 'Spirograph'
bg_color: background
width: 900
height: 950
bg_color: background
width: 900
height: 950
sample_count: 2
frame_fn: fn [mut k, mut scale] (mut ctx gg.Context) {
frame_fn: fn [mut k, mut scale] (mut ctx gg.Context) {
wsize := gg.window_size()
ctx.begin()
ctx.draw_rect_filled(0, 0, wsize.width, wsize.height, gg.Color{10, 1, 30, 60})

View file

@ -43,18 +43,18 @@ mut:
fn main() {
mut app := &App{
stars: []Star{len: max_stars}
stars: []Star{len: max_stars}
v_letters: []VLetter{len: max_v_letters}
}
app.gg = gg.new_context(
bg_color: gx.black
width: win_width
height: win_height
bg_color: gx.black
width: win_width
height: win_height
create_window: true
window_title: 'Star Vield'
frame_fn: frame
init_fn: init_images
user_data: app
window_title: 'Star Vield'
frame_fn: frame
init_fn: init_images
user_data: app
)
for i in 0 .. max_stars {
app.stars[i].x = rand.f32_in_range(-200.0, 200.0) or { -200.0 }

View file

@ -24,14 +24,14 @@ mut:
fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: 'Counter'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: init
window_title: 'Counter'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: init
)
app.gg.run()
}

View file

@ -24,21 +24,21 @@ const width = 50
fn main() {
mut game := &Game{
dx: 2
dy: 2
height: window_height
width: window_width
dx: 2
dy: 2
height: window_height
width: window_width
draw_fn: 0
}
game.gg = gg.new_context(
width: window_width
height: window_height
font_size: 20
user_data: game
window_title: 'Hot code reloading demo'
width: window_width
height: window_height
font_size: 20
user_data: game
window_title: 'Hot code reloading demo'
create_window: true
frame_fn: frame
bg_color: gx.white
frame_fn: frame
bg_color: gx.white
)
// window.onkeydown(key_down)
println('Starting the game loop...')

View file

@ -16,15 +16,15 @@ mut:
fn main() {
mut context := &Context{}
context.gg = gg.new_context(
width: size
height: size
font_size: 20
user_data: context
window_title: 'Graph builder'
width: size
height: size
font_size: 20
user_data: context
window_title: 'Graph builder'
create_window: true
frame_fn: frame
resizable: true
bg_color: gx.white
frame_fn: frame
resizable: true
bg_color: gx.white
)
context.gg.run()
}

View file

@ -162,9 +162,9 @@ fn v_sqlite_file() !FrameworkBenchmarkResponse {
// res := http.get(url) or { panic(err) }
// framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)!
framework_benchmark_response := FrameworkBenchmarkResponse{
insert: []
insert: []
@select: []
update: []
update: []
}
return framework_benchmark_response
}

View file

@ -53,7 +53,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
} or { panic(err) }
task_model := Task{
title: 'a'
title: 'a'
status: 'done'
}
@ -93,9 +93,9 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
} or { panic(err) }
response := Response{
insert: insert_stopwatchs
insert: insert_stopwatchs
@select: select_stopwatchs
update: update_stopwatchs
update: update_stopwatchs
}
return app.json(response)
}
@ -103,9 +103,9 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
@['/sqlite-file/:count']
pub fn (mut app App) sqlite_file(count int) vweb.Result {
response := Response{
insert: []
insert: []
@select: []
update: []
update: []
}
return app.json(response)
}
@ -113,9 +113,9 @@ pub fn (mut app App) sqlite_file(count int) vweb.Result {
@['/postgres/:count']
pub fn (mut app App) postgres(count int) vweb.Result {
response := Response{
insert: []
insert: []
@select: []
update: []
update: []
}
return app.json(response)
}
@ -123,9 +123,9 @@ pub fn (mut app App) postgres(count int) vweb.Result {
@['/mysql/:count']
pub fn (mut app App) mysql(count int) vweb.Result {
response := Response{
insert: []
insert: []
@select: []
update: []
update: []
}
return app.json(response)
}

View file

@ -39,11 +39,11 @@ fn linearrelationship(independent_variable []int, dependent_variable []int) Line
// R2 = n(∑xy) - (∑x)(∑y) / sqrt([n(∑x²)-(∑x)²][n(∑y²)-(∑y)²]
r2_value := f64((independent_variable.len * sum_xy) - (sum_x * sum_y)) / math.sqrt(f64((sum_r2_x * independent_variable.len) - (sum_x * sum_x)) * f64((sum_r2_y * dependent_variable.len) - (sum_y * sum_y)))
return LinearResult{
r2: r2_value
intercept: intercept_value
slope: slope_value
r2: r2_value
intercept: intercept_value
slope: slope_value
independent_variable_means: x_means
dependent_variable_means: y_means
dependent_variable_means: y_means
}
}

View file

@ -52,10 +52,10 @@ fn main() {
my_app.tray_info = C.tray_app_init(TrayParams{
items: [TrayMenuItem{
id: 'hello'
id: 'hello'
text: 'Hello'
}, TrayMenuItem{
id: 'quit'
id: 'quit'
text: 'Quit!'
}]
on_click: my_app.on_menu_item_click

View file

@ -88,9 +88,9 @@ struct Image {
fn new_image(w int, h int) Image {
vecsize := int(sizeof(Vec))
return Image{
width: w
width: w
height: h
data: unsafe { &Vec(vcalloc(vecsize * w * h)) }
data: unsafe { &Vec(vcalloc(vecsize * w * h)) }
}
}
@ -166,154 +166,154 @@ const cen = Vec{50, 40.8, -860} // used by scene 1
const spheres = [
[// scene 0 cornnel box
Sphere{
rad: 1e+5
p: Vec{1e+5 + 1, 40.8, 81.6}
e: Vec{}
c: Vec{.75, .25, .25}
rad: 1e+5
p: Vec{1e+5 + 1, 40.8, 81.6}
e: Vec{}
c: Vec{.75, .25, .25}
refl: .diff
}, // Left
Sphere{
rad: 1e+5
p: Vec{-1e+5 + 99, 40.8, 81.6}
e: Vec{}
c: Vec{.25, .25, .75}
rad: 1e+5
p: Vec{-1e+5 + 99, 40.8, 81.6}
e: Vec{}
c: Vec{.25, .25, .75}
refl: .diff
}, // Rght
Sphere{
rad: 1e+5
p: Vec{50, 40.8, 1e+5}
e: Vec{}
c: Vec{.75, .75, .75}
rad: 1e+5
p: Vec{50, 40.8, 1e+5}
e: Vec{}
c: Vec{.75, .75, .75}
refl: .diff
}, // Back
Sphere{
rad: 1e+5
p: Vec{50, 40.8, -1e+5 + 170}
e: Vec{}
c: Vec{}
rad: 1e+5
p: Vec{50, 40.8, -1e+5 + 170}
e: Vec{}
c: Vec{}
refl: .diff
}, // Frnt
Sphere{
rad: 1e+5
p: Vec{50, 1e+5, 81.6}
e: Vec{}
c: Vec{.75, .75, .75}
rad: 1e+5
p: Vec{50, 1e+5, 81.6}
e: Vec{}
c: Vec{.75, .75, .75}
refl: .diff
}, // Botm
Sphere{
rad: 1e+5
p: Vec{50, -1e+5 + 81.6, 81.6}
e: Vec{}
c: Vec{.75, .75, .75}
rad: 1e+5
p: Vec{50, -1e+5 + 81.6, 81.6}
e: Vec{}
c: Vec{.75, .75, .75}
refl: .diff
}, // Top
Sphere{
rad: 16.5
p: Vec{27, 16.5, 47}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.999)
rad: 16.5
p: Vec{27, 16.5, 47}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.999)
refl: .spec
}, // Mirr
Sphere{
rad: 16.5
p: Vec{73, 16.5, 78}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.999)
rad: 16.5
p: Vec{73, 16.5, 78}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.999)
refl: .refr
}, // Glas
Sphere{
rad: 600
p: Vec{50, 681.6 - .27, 81.6}
e: Vec{12, 12, 12}
c: Vec{}
rad: 600
p: Vec{50, 681.6 - .27, 81.6}
e: Vec{12, 12, 12}
c: Vec{}
refl: .diff
}, // Lite
],
[// scene 1 sunset
Sphere{
rad: 1600
p: Vec{1.0, 0.0, 2.0}.mult_s(3000)
e: Vec{1.0, .9, .8}.mult_s(1.2e+1 * 1.56 * 2)
c: Vec{}
rad: 1600
p: Vec{1.0, 0.0, 2.0}.mult_s(3000)
e: Vec{1.0, .9, .8}.mult_s(1.2e+1 * 1.56 * 2)
c: Vec{}
refl: .diff
}, // sun
Sphere{
rad: 1560
p: Vec{1, 0, 2}.mult_s(3500)
e: Vec{1.0, .5, .05}.mult_s(4.8e+1 * 1.56 * 2)
c: Vec{}
rad: 1560
p: Vec{1, 0, 2}.mult_s(3500)
e: Vec{1.0, .5, .05}.mult_s(4.8e+1 * 1.56 * 2)
c: Vec{}
refl: .diff
}, // horizon sun2
Sphere{
rad: 10000
p: cen + Vec{0, 0, -200}
e: Vec{0.00063842, 0.02001478, 0.28923243}.mult_s(6e-2 * 8)
c: Vec{.7, .7, 1}.mult_s(.25)
rad: 10000
p: cen + Vec{0, 0, -200}
e: Vec{0.00063842, 0.02001478, 0.28923243}.mult_s(6e-2 * 8)
c: Vec{.7, .7, 1}.mult_s(.25)
refl: .diff
}, // sky
Sphere{
rad: 100000
p: Vec{50, -100000, 0}
e: Vec{}
c: Vec{.3, .3, .3}
rad: 100000
p: Vec{50, -100000, 0}
e: Vec{}
c: Vec{.3, .3, .3}
refl: .diff
}, // grnd
Sphere{
rad: 110000
p: Vec{50, -110048.5, 0}
e: Vec{.9, .5, .05}.mult_s(4)
c: Vec{}
rad: 110000
p: Vec{50, -110048.5, 0}
e: Vec{.9, .5, .05}.mult_s(4)
c: Vec{}
refl: .diff
}, // horizon brightener
Sphere{
rad: 4e+4
p: Vec{50, -4e+4 - 30, -3000}
e: Vec{}
c: Vec{.2, .2, .2}
rad: 4e+4
p: Vec{50, -4e+4 - 30, -3000}
e: Vec{}
c: Vec{.2, .2, .2}
refl: .diff
}, // mountains
Sphere{
rad: 26.5
p: Vec{22, 26.5, 42}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.596)
rad: 26.5
p: Vec{22, 26.5, 42}
e: Vec{}
c: Vec{1, 1, 1}.mult_s(.596)
refl: .spec
}, // white Mirr
Sphere{
rad: 13
p: Vec{75, 13, 82}
e: Vec{}
c: Vec{.96, .96, .96}.mult_s(.96)
rad: 13
p: Vec{75, 13, 82}
e: Vec{}
c: Vec{.96, .96, .96}.mult_s(.96)
refl: .refr
}, // Glas
Sphere{
rad: 22
p: Vec{87, 22, 24}
e: Vec{}
c: Vec{.6, .6, .6}.mult_s(.696)
rad: 22
p: Vec{87, 22, 24}
e: Vec{}
c: Vec{.6, .6, .6}.mult_s(.696)
refl: .refr
}, // Glas2
],
[// scene 3 Psychedelic
Sphere{
rad: 150
p: Vec{50 + 75, 28, 62}
e: Vec{1, 1, 1}.mult_s(0e-3)
c: Vec{1, .9, .8}.mult_s(.93)
rad: 150
p: Vec{50 + 75, 28, 62}
e: Vec{1, 1, 1}.mult_s(0e-3)
c: Vec{1, .9, .8}.mult_s(.93)
refl: .refr
},
Sphere{
rad: 28
p: Vec{50 + 5, -28, 62}
e: Vec{1, 1, 1}.mult_s(1e+1)
c: Vec{1, 1, 1}.mult_s(0)
rad: 28
p: Vec{50 + 5, -28, 62}
e: Vec{1, 1, 1}.mult_s(1e+1)
c: Vec{1, 1, 1}.mult_s(0)
refl: .diff
},
Sphere{
rad: 300
p: Vec{50, 28, 62}
e: Vec{1, 1, 1}.mult_s(0e-3)
c: Vec{1, 1, 1}.mult_s(.93)
rad: 300
p: Vec{50, 28, 62}
e: Vec{1, 1, 1}.mult_s(0e-3)
c: Vec{1, 1, 1}.mult_s(.93)
refl: .spec
},
],

View file

@ -50,7 +50,7 @@ fn main() {
spawn app.gg.run()
sim.run(app.args.params,
grid: app.args.grid
grid: app.args.grid
on_request: sim.SimRequestHandler(handle_request)
)
}

View file

@ -28,19 +28,19 @@ pub fn new_app(args simargs.ParallelArgs) &App {
total_pixels := args.grid.height * args.grid.width
mut app := &App{
args: args
pixels: []u32{len: total_pixels}
args: args
pixels: []u32{len: total_pixels}
request_chan: chan &sim.SimRequest{cap: args.grid.width}
}
app.gg = gg.new_context(
width: args.grid.width
height: args.grid.height
width: args.grid.width
height: args.grid.height
create_window: true
window_title: 'V Pendulum Simulation'
user_data: app
bg_color: anim.bg_color
frame_fn: frame
init_fn: init
window_title: 'V Pendulum Simulation'
user_data: app
bg_color: anim.bg_color
frame_fn: frame
init_fn: init
)
return app
}

View file

@ -69,23 +69,23 @@ fn parse_sequential_args() !SequentialArgs {
}
params := sim.sim_params(
rope_length: rope_length
bearing_mass: bearing_mass
magnet_spacing: magnet_spacing
magnet_height: magnet_height
rope_length: rope_length
bearing_mass: bearing_mass
magnet_spacing: magnet_spacing
magnet_height: magnet_height
magnet_strength: magnet_strength
gravity: gravity
gravity: gravity
)
grid := sim.new_grid_settings(
width: width
width: width
height: height
)
args := SequentialArgs{
params: params
params: params
filename: filename
grid: grid
grid: grid
}
sim.log('${args}')
@ -122,24 +122,24 @@ fn parse_parallel_args(extra_workers int) !ParallelArgs {
}
params := sim.sim_params(
rope_length: rope_length
bearing_mass: bearing_mass
magnet_spacing: magnet_spacing
magnet_height: magnet_height
rope_length: rope_length
bearing_mass: bearing_mass
magnet_spacing: magnet_spacing
magnet_height: magnet_height
magnet_strength: magnet_strength
gravity: gravity
gravity: gravity
)
grid := sim.new_grid_settings(
width: width
width: width
height: height
)
args := ParallelArgs{
params: params
params: params
filename: filename
grid: grid
workers: get_workers(workers, extra_workers)
grid: grid
workers: get_workers(workers, extra_workers)
}
sim.log('${args}')

View file

@ -20,14 +20,14 @@ pub fn new_image_settings(settings ImageSettings) ImageSettings {
pub fn image_settings_from_grid(grid sim.GridSettings) ImageSettings {
return ImageSettings{
width: grid.width
width: grid.width
height: grid.height
}
}
pub fn (s ImageSettings) to_grid_settings() sim.GridSettings {
return sim.GridSettings{
width: s.width
width: s.width
height: s.height
}
}
@ -42,7 +42,7 @@ mut:
pub fn ppm_writer_for_fname(fname string, settings ImageSettings) !&PPMWriter {
mut writer := &PPMWriter{
cache_size: settings.cache_size
cache: []u8{cap: settings.cache_size}
cache: []u8{cap: settings.cache_size}
}
writer.start_for_file(fname, settings)!
return writer

View file

@ -23,9 +23,9 @@ pub fn new_image_writer(mut writer PPMWriter, settings ImageSettings) &ImageWrit
valid: false
}}
return &ImageWriter{
writer: writer
writer: writer
settings: settings
buffer: buffer
buffer: buffer
}
}

View file

@ -3,12 +3,12 @@ module sim
import math
const params_test_mock_params = SimParams{
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
magnet_strength: 10
gravity: 4.9
gravity: 4.9
}
const params_test_mock_state = SimState{
position: vector(

View file

@ -70,8 +70,8 @@ pub fn run(params SimParams, settings RunnerSettings) {
state.satisfy_rope_constraint(params)
request := &SimRequest{
id: index
state: state
id: index
state: state
params: params
}
settings.on_request(request) or {

View file

@ -1,12 +1,12 @@
module sim
const sim_test_mock_params = SimParams{
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
magnet_strength: 10
gravity: 4.9
gravity: 4.9
}
const sim_test_mock_state = SimState{
position: vector(

View file

@ -56,8 +56,8 @@ pub fn compute_result(request SimRequest) &SimResult {
id := request.id
return &SimResult{
id: id
state: state
id: id
state: state
magnet1_distance: m1_dist
magnet2_distance: m2_dist
magnet3_distance: m3_dist

View file

@ -1,12 +1,12 @@
module sim
const worker_test_mock_params = SimParams{
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
rope_length: 0.25
bearing_mass: 0.03
magnet_spacing: 0.05
magnet_height: 0.03
magnet_strength: 10
gravity: 4.9
gravity: 4.9
}
const worker_test_mock_state = SimState{
position: vector(
@ -28,9 +28,9 @@ const worker_test_mock_state = SimState{
fn test_compute_result() {
request := SimRequest{
id: 0
id: 0
params: sim.worker_test_mock_params
state: sim.worker_test_mock_state
state: sim.worker_test_mock_state
}
expected_state := SimState{
position: vector(
@ -50,8 +50,8 @@ fn test_compute_result() {
)
}
expected := &SimResult{
state: expected_state
id: 0
state: expected_state
id: 0
magnet1_distance: 0.07993696666249225
magnet2_distance: 0.07993696666249224
magnet3_distance: 0.03609361938278008

View file

@ -58,8 +58,8 @@ fn main() {
state.satisfy_rope_constraint(args.params)
request := &sim.SimRequest{
id: request_index
state: state
id: request_index
state: state
params: args.params
}
select {

View file

@ -44,7 +44,7 @@ fn main() {
}
sim.run(args.params,
grid: args.grid
grid: args.grid
on_request: sim.SimRequestHandler(handle_request)
)
}

View file

@ -10,7 +10,7 @@ const http_response = 'HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-len
fn main() {
println('Starting webserver on http://localhost:${port}/ ...')
mut pico := picoev.new(
port: port
port: port
raw_cb: handle_conn
)!
pico.serve()
@ -19,8 +19,8 @@ fn main() {
fn handle_conn(mut pv picoev.Picoev, fd int, events int) {
// setup a nonblocking tcp connection
mut conn := &net.TcpConn{
sock: net.tcp_socket_from_handle_raw(fd)
handle: fd
sock: net.tcp_socket_from_handle_raw(fd)
handle: fd
is_blocking: false
}

View file

@ -14,11 +14,11 @@ const timer_period = 40 * time.millisecond // defaulted at 25 fps
const font_small = gx.TextCfg{
color: gx.black
size: 20
size: 20
}
const font_large = gx.TextCfg{
color: gx.black
size: 40
size: 40
}
struct App {
@ -96,9 +96,9 @@ fn (mut app App) insert_particles() {
mut x := rand_minmax(0, gridh) * grid
mut y := rand_minmax(0, gridv) * grid
mut random_particle := datatypes.AABB{
x: x
y: y
width: rand_minmax(1, 4) * grid
x: x
y: y
width: rand_minmax(1, 4) * grid
height: rand_minmax(1, 4) * grid
}
app.particles << Particle{random_particle, 0.0, 0.0}
@ -115,15 +115,15 @@ fn main() {
gg: unsafe { nil }
}
app.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'Quadtree Demo'
frame_fn: frame
event_fn: on_event
user_data: app
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
window_title: 'Quadtree Demo'
frame_fn: frame
event_fn: on_event
user_data: app
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
)
app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0)
app.start()

View file

@ -19,17 +19,17 @@ fn main() {
subject := os.input('Subject: ')
body := os.input('Body: ')
client_cfg := smtp.Client{
server: mailserver
from: from
port: mailport
server: mailserver
from: from
port: mailport
username: username
password: password
}
send_cfg := smtp.Mail{
to: to
subject: subject
to: to
subject: subject
body_type: .html
body: body
body: body
}
mut client := smtp.new_client(client_cfg) or { panic('Error with configuring smtp: ${err}') }
client.send(send_cfg) or { panic('Error resolving email address: ${err}') }

View file

@ -152,10 +152,10 @@ fn on_frame(mut app App) {
// drawing top
app.gg.draw_rect(0, 0, canvas_size, top_height, gx.black)
app.gg.draw_text(350, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
color: gx.white
align: .center
color: gx.white
align: .center
vertical_align: .middle
size: 80
size: 80
})
// checking if snake bit itself
@ -179,15 +179,15 @@ fn main() {
app.reset_game()
app.gg = gg.new_context(
bg_color: gx.white
frame_fn: on_frame
keydown_fn: on_keydown
user_data: &app
width: canvas_size
height: top_height + canvas_size
create_window: true
resizable: false
window_title: 'snek'
bg_color: gx.white
frame_fn: on_frame
keydown_fn: on_keydown
user_data: &app
width: canvas_size
height: top_height + canvas_size
create_window: true
resizable: false
window_title: 'snek'
html5_canvas_name: 'canvas'
)

View file

@ -140,16 +140,16 @@ fn on_frame(mut app App) {
// draw score bar
app.gg.draw_rect_filled(0, 0, canvas_size, top_height, gx.black)
app.gg.draw_text(150, top_height / 2, 'Score: ${app.score}', gx.TextCfg{
color: gx.white
align: .center
color: gx.white
align: .center
vertical_align: .middle
size: 65
size: 65
})
app.gg.draw_text(canvas_size - 150, top_height / 2, 'Best: ${app.best}', gx.TextCfg{
color: gx.white
align: .center
color: gx.white
align: .center
vertical_align: .middle
size: 65
size: 65
})
if progress == 1 {
@ -200,15 +200,15 @@ fn main() {
}
app.gg = gg.new_context(
bg_color: gx.white
frame_fn: on_frame
keydown_fn: on_keydown
user_data: &app
width: canvas_size
height: top_height + canvas_size
create_window: true
resizable: false
window_title: 'snek'
bg_color: gx.white
frame_fn: on_frame
keydown_fn: on_keydown
user_data: &app
width: canvas_size
height: top_height + canvas_size
create_window: true
resizable: false
window_title: 'snek'
font_bytes_normal: font_bytes
)

View file

@ -33,16 +33,16 @@ mut:
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
height: h
width: w
height: h
num_mipmaps: 0
// usage: .dynamic
label: &u8(0)
label: &u8(0)
d3d11_texture: 0
}
// comment, if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -51,8 +51,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -68,7 +68,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
gfx.update_image(sg_img, &tmp_sbc)
@ -311,7 +311,7 @@ fn my_init(mut app App) {
color_state := gfx.ColorTargetState{
blend: gfx.BlendState{
enabled: true
enabled: true
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}
@ -320,7 +320,7 @@ fn my_init(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
app.pip_3d = sgl.make_pipeline(&pipdesc)
@ -381,15 +381,15 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: '3D Cube Demo'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
window_title: '3D Cube Demo'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
)
app.gg.run()
}

View file

@ -56,16 +56,16 @@ mut:
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
height: h
width: w
height: h
num_mipmaps: 0
// usage: .dynamic
label: &u8(0)
label: &u8(0)
d3d11_texture: 0
}
// comment if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -74,8 +74,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -91,7 +91,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
gfx.update_image(sg_img, &tmp_sbc)
@ -304,7 +304,7 @@ fn init_cube_glsl(mut app App) {
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
ptr: vertices.data
size: usize(vertices.len * int(sizeof(Vertex_t)))
}
@ -331,7 +331,7 @@ fn init_cube_glsl(mut app App) {
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
ptr: indices.data
size: usize(indices.len * int(sizeof(u16)))
}
@ -356,7 +356,7 @@ fn init_cube_glsl(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
@ -407,7 +407,7 @@ fn draw_cube_glsl(app App) {
// passing the view matrix as uniform
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
vs_uniforms_range := gfx.Range{
ptr: &tr_matrix
ptr: &tr_matrix
size: usize(4 * 16)
}
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
@ -421,7 +421,7 @@ fn draw_cube_glsl(app App) {
0, // padding 4 Bytes == 1 f32
]!
fs_uniforms_range := gfx.Range{
ptr: unsafe { &text_res }
ptr: unsafe { &text_res }
size: usize(4 * 4)
}
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
@ -528,7 +528,7 @@ fn my_init(mut app App) {
color_state := gfx.ColorTargetState{
blend: gfx.BlendState{
enabled: true
enabled: true
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}
@ -537,7 +537,7 @@ fn my_init(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
@ -610,15 +610,15 @@ fn main() {
println(a)
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: '3D Cube Demo'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
window_title: '3D Cube Demo'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
)
app.ticks = time.ticks()

View file

@ -55,20 +55,20 @@ mut:
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
height: h
width: w
height: h
num_mipmaps: 0
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
label: &u8(0)
d3d11_texture: 0
}
// comment if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -77,8 +77,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -94,7 +94,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
gfx.update_image(sg_img, &tmp_sbc)
@ -171,7 +171,7 @@ fn init_cube_glsl(mut app App) {
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
ptr: vertices.data
size: usize(vertices.len * int(sizeof(Vertex_t)))
}
@ -197,7 +197,7 @@ fn init_cube_glsl(mut app App) {
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
ptr: indices.data
size: usize(indices.len * int(sizeof(u16)))
}
@ -222,7 +222,7 @@ fn init_cube_glsl(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
@ -284,7 +284,7 @@ fn draw_cube_glsl(app App) {
// passing the view matrix as uniform
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
vs_uniforms_range := gfx.Range{
ptr: &tr_matrix
ptr: &tr_matrix
size: usize(4 * 16)
}
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
@ -302,7 +302,7 @@ fn draw_cube_glsl(app App) {
0, // padding bytes , see "fs_params" struct paddings in rt_glsl.h
]!
fs_uniforms_range := gfx.Range{
ptr: unsafe { &tmp_fs_params }
ptr: unsafe { &tmp_fs_params }
size: usize(sizeof(tmp_fs_params))
}
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
@ -410,15 +410,15 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: '3D Ray Marching Cube'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
window_title: '3D Ray Marching Cube'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
event_fn: my_event_manager
)
app.ticks = time.ticks()
app.gg.run()

View file

@ -47,19 +47,19 @@ mut:
fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
width: w
height: h
}
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
sg_img := gfx.make_image(&img_desc)
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
return sg_img, sg_smp
@ -326,13 +326,13 @@ fn (mut app App) on_event(ev &gg.Event, x voidptr) {
fn main() {
mut app := &App{}
app.gg = gg.new_context(
width: 800
height: 800
width: 800
height: 800
window_title: '3D Dual shader Cube - click and rotate with the mouse'
user_data: app
frame_fn: app.frame
init_fn: app.on_init
event_fn: app.on_event
user_data: app
frame_fn: app.frame
init_fn: app.on_init
event_fn: app.on_event
)
app.gg.run()
}

View file

@ -80,7 +80,7 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
// vfmt on
// comment if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -89,8 +89,8 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -106,7 +106,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf byteptr) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
gfx.update_image(sg_img, &tmp_sbc)
@ -183,7 +183,7 @@ fn init_cube_glsl_i(mut app App) {
unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) }
vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vert_buffer_desc.data = gfx.Range{
ptr: vertices.data
ptr: vertices.data
size: usize(vertices.len * int(sizeof(Vertex_t)))
}
vert_buffer_desc.@type = .vertexbuffer
@ -218,7 +218,7 @@ fn init_cube_glsl_i(mut app App) {
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
index_buffer_desc.data = gfx.Range{
ptr: indices.data
ptr: indices.data
size: usize(indices.len * int(sizeof(u16)))
}
index_buffer_desc.@type = .indexbuffer
@ -253,7 +253,7 @@ fn init_cube_glsl_i(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
@ -330,7 +330,7 @@ fn draw_cube_glsl_i(mut app App) {
// vfmt on
}
range := gfx.Range{
ptr: unsafe { &app.inst_pos }
ptr: unsafe { &app.inst_pos }
size: usize(num_inst * int(sizeof(m4.Vec4)))
}
gfx.update_buffer(app.bind['inst'].vertex_buffers[1], &range)
@ -340,7 +340,7 @@ fn draw_cube_glsl_i(mut app App) {
// passing the view matrix as uniform
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
vs_uniforms_range := gfx.Range{
ptr: unsafe { &tr_matrix }
ptr: unsafe { &tr_matrix }
size: usize(4 * 16)
}
gfx.apply_uniforms(.vs, C.SLOT_vs_params_i, &vs_uniforms_range)

View file

@ -21,20 +21,20 @@ import stbi
pub fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
height: h
width: w
height: h
num_mipmaps: 0
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
label: &u8(0)
d3d11_texture: 0
}
// comment if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -43,8 +43,8 @@ pub fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -82,7 +82,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
vert_buffer_desc.size = usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct)))
vert_buffer_desc.data = gfx.Range{
ptr: obj_buf.vbuf.data
ptr: obj_buf.vbuf.data
size: usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct)))
}
@ -96,7 +96,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
index_buffer_desc.size = usize(obj_buf.ibuf.len * int(sizeof(u32)))
index_buffer_desc.data = gfx.Range{
ptr: obj_buf.ibuf.data
ptr: obj_buf.ibuf.data
size: usize(obj_buf.ibuf.len * int(sizeof(u32)))
}
@ -118,7 +118,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
color_state := gfx.ColorTargetState{
blend: gfx.BlendState{
enabled: true
enabled: true
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}
@ -127,7 +127,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .front
@ -243,11 +243,11 @@ pub fn (obj_part ObjPart) bind_and_draw(rend_data_index int, in_data Shader_data
gfx.apply_bindings(part_render_data.bind)
vs_uniforms_range := gfx.Range{
ptr: in_data.vs_data
ptr: in_data.vs_data
size: usize(in_data.vs_len)
}
fs_uniforms_range := gfx.Range{
ptr: unsafe { &tmp_fs_params }
ptr: unsafe { &tmp_fs_params }
size: usize(in_data.fs_len)
}

View file

@ -90,9 +90,9 @@ fn calc_matrices(w f32, h f32, rx f32, ry f32, in_scale f32, pos m4.Vec4) obj.Ma
mvp := mv * view_proj // model view projection
return obj.Mats{
mv: mv
mv: mv
mvp: mvp
nm: nm
nm: nm
}
}
@ -119,9 +119,9 @@ fn draw_model(app App, model_pos m4.Vec4) u32 {
mats := calc_matrices(dw, dh, rot[0], rot[1], zoom_scale, model_pos)
mut tmp_vs_param := obj.Tmp_vs_param{
mv: mats.mv
mv: mats.mv
mvp: mats.mvp
nm: mats.nm
nm: mats.nm
}
// *** fragment shader uniforms ***
@ -135,9 +135,9 @@ fn draw_model(app App, model_pos m4.Vec4) u32 {
sd := obj.Shader_data{
vs_data: unsafe { &tmp_vs_param }
vs_len: int(sizeof(tmp_vs_param))
vs_len: int(sizeof(tmp_vs_param))
fs_data: unsafe { &tmp_fs_params }
fs_len: int(sizeof(tmp_fs_params))
fs_len: int(sizeof(tmp_fs_params))
}
return app.obj_part.bind_and_draw_all(sd)
@ -292,16 +292,16 @@ fn main() {
}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: 'V Wavefront OBJ viewer - Use the mouse wheel to zoom'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
cleanup_fn: cleanup
event_fn: my_event_manager
window_title: 'V Wavefront OBJ viewer - Use the mouse wheel to zoom'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: my_init
cleanup_fn: cleanup
event_fn: my_event_manager
)
app.ticks = time.ticks()

View file

@ -34,8 +34,8 @@ struct Vertex_t {
fn main() {
mut app := &App{
width: 800
height: 400
width: 800
height: 400
pass_action: gfx.create_clear_pass_action(0.0, 0.0, 0.0, 1.0) // This will create a black color as a default pass (window background color)
}
app.run()
@ -53,15 +53,15 @@ mut:
fn (mut a App) run() {
title := 'V Simple Shader Example'
desc := sapp.Desc{
width: a.width
height: a.height
user_data: a
init_userdata_cb: init
frame_userdata_cb: frame
window_title: title.str
html5_canvas_name: title.str
width: a.width
height: a.height
user_data: a
init_userdata_cb: init
frame_userdata_cb: frame
window_title: title.str
html5_canvas_name: title.str
cleanup_userdata_cb: cleanup
sample_count: 4 // Enables MSAA (Multisample anti-aliasing) x4 on rendered output, this can be omitted.
sample_count: 4 // Enables MSAA (Multisample anti-aliasing) x4 on rendered output, this can be omitted.
}
sapp.run(&desc)
}
@ -100,7 +100,7 @@ fn init(user_data voidptr) {
vertex_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t)))
vertex_buffer_desc.data = gfx.Range{
ptr: vertices.data
ptr: vertices.data
size: vertex_buffer_desc.size
}

View file

@ -28,7 +28,7 @@ fn init(mut state State) {
fsq_verts := [f32(-1.0), -3.0, 3.0, 1.0, -1.0, 1.0]!
state.bind.vertex_buffers[0] = gfx.make_buffer(gfx.BufferDesc{
label: c'fsq vertices'
data: unsafe { gfx.Range{&fsq_verts[0], sizeof(fsq_verts)} }
data: unsafe { gfx.Range{&fsq_verts[0], sizeof(fsq_verts)} }
})
mut pipeline := gfx.PipelineDesc{}
@ -55,13 +55,13 @@ fn frame(mut state State) {
fn main() {
sapp.run(sapp.Desc{
window_title: c'SDF Rendering'
width: 512
height: 512
window_title: c'SDF Rendering'
width: 512
height: 512
frame_userdata_cb: frame
init_userdata_cb: init
cleanup_cb: gfx.shutdown
icon: sapp.IconDesc{
init_userdata_cb: init
cleanup_cb: gfx.shutdown
icon: sapp.IconDesc{
sokol_default: true
}
user_data: &State{}

View file

@ -14,12 +14,12 @@ fn frame(mut action gfx.PassAction) {
fn main() {
action := gfx.create_clear_pass_action(1.0, 0, 0, 1.0)
sapp.run(
window_title: c'Clear (sokol app)'
width: 400
height: 300
init_cb: || gfx.setup(sapp.create_desc())
cleanup_cb: || gfx.shutdown()
window_title: c'Clear (sokol app)'
width: 400
height: 300
init_cb: || gfx.setup(sapp.create_desc())
cleanup_cb: || gfx.shutdown()
frame_userdata_cb: frame
user_data: &action
user_data: &action
)
}

View file

@ -12,12 +12,12 @@ fn main() {
}
title := 'Sokol Drawing Template'
desc := sapp.Desc{
width: 640
height: 480
user_data: state
init_userdata_cb: init
width: 640
height: 480
user_data: state
init_userdata_cb: init
frame_userdata_cb: frame
window_title: title.str
window_title: title.str
html5_canvas_name: title.str
}
sapp.run(&desc)

View file

@ -14,15 +14,15 @@ mut:
fn main() {
state := &AppState{
pass_action: gfx.create_clear_pass_action(0.3, 0.3, 0.32, 1.0)
pass_action: gfx.create_clear_pass_action(0.3, 0.3, 0.32, 1.0)
font_context: unsafe { nil } // &fontstash.Context(0)
}
title := 'V Metal/GL Text Rendering'
desc := sapp.Desc{
user_data: state
init_userdata_cb: init
user_data: state
init_userdata_cb: init
frame_userdata_cb: frame
window_title: title.str
window_title: title.str
html5_canvas_name: title.str
}
sapp.run(&desc)

View file

@ -73,18 +73,18 @@ fn main() {
pass_action.colors[0] = color_action
state := &AppState{
pass_action: pass_action
fons: unsafe { nil } // &fontstash.Context(0)
fons: unsafe { nil } // &fontstash.Context(0)
}
title := 'V Metal/GL Text Rendering'
desc := sapp.Desc{
user_data: state
init_userdata_cb: init
user_data: state
init_userdata_cb: init
frame_userdata_cb: frame
window_title: title.str
window_title: title.str
html5_canvas_name: title.str
width: 600
height: 700
high_dpi: true
width: 600
height: 700
high_dpi: true
}
sapp.run(&desc)
}

View file

@ -11,11 +11,11 @@ const default_v_color = Color{93, 136, 193, 255}
// * Module public
pub fn new(location vec.Vec2[f64]) &Particle {
p := &Particle{
location: location
velocity: vec.Vec2[f64]{0, 0}
acceleration: vec.Vec2[f64]{0, 0}
color: particle.default_v_color
life_time: particle.default_life_time
location: location
velocity: vec.Vec2[f64]{0, 0}
acceleration: vec.Vec2[f64]{0, 0}
color: particle.default_v_color
life_time: particle.default_life_time
life_time_init: particle.default_life_time
}
return p

View file

@ -10,8 +10,8 @@ import particle
fn main() {
mut app := &App{
width: 800
height: 400
width: 800
height: 400
pass_action: gfx.create_clear_pass_action(0.1, 0.1, 0.1, 1.0)
}
app.init()
@ -33,7 +33,7 @@ fn (mut a App) init() {
a.frame = 0
a.last = time.ticks()
a.ps = particle.System{
width: a.width
width: a.width
height: a.height
}
a.ps.init(particle.SystemConfig{
@ -50,14 +50,14 @@ fn (mut a App) cleanup() {
fn (mut a App) run() {
title := 'V Particle Example'
desc := sapp.Desc{
width: a.width
height: a.height
user_data: a
init_userdata_cb: init
frame_userdata_cb: frame
event_userdata_cb: event
window_title: title.str
html5_canvas_name: title.str
width: a.width
height: a.height
user_data: a
init_userdata_cb: init
frame_userdata_cb: frame
event_userdata_cb: event
window_title: title.str
html5_canvas_name: title.str
cleanup_userdata_cb: cleanup
}
sapp.run(&desc)
@ -80,7 +80,7 @@ fn init(mut app App) {
color_state := gfx.ColorTargetState{
blend: gfx.BlendState{
enabled: true
enabled: true
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}

View file

@ -47,12 +47,12 @@ fn main() {
audio.setup(stream_userdata_cb: my_audio_stream_callback, user_data: state)
defer { audio.shutdown() }
state.gg = gg.new_context(
bg_color: gg.Color{50, 50, 50, 255}
width: 800
height: 600
bg_color: gg.Color{50, 50, 50, 255}
width: 800
height: 600
window_title: 'ByteBeat Music'
frame_fn: graphics_frame
user_data: state
frame_fn: graphics_frame
user_data: state
)
state.gg.run()
}

View file

@ -54,9 +54,9 @@ fn audio_player_callback(mut buffer &f32, num_frames int, num_channels int, mut
fn (mut p Player) init() {
audio.setup(
num_channels: 2
num_channels: 2
stream_userdata_cb: audio_player_callback
user_data: p
user_data: p
)
}

View file

@ -4,8 +4,8 @@ import net.mbedtls
fn main() {
mut client := mbedtls.new_ssl_conn(mbedtls.SSLConnectConfig{
verify: os.resource_abs_path('cert/ca.crt')
cert: os.resource_abs_path('cert/client.crt')
verify: os.resource_abs_path('cert/ca.crt')
cert: os.resource_abs_path('cert/client.crt')
cert_key: os.resource_abs_path('cert/client.key')
validate: true
})!

View file

@ -4,8 +4,8 @@ import net.mbedtls
fn main() {
mut server := mbedtls.new_ssl_listener('0.0.0.0:8443', mbedtls.SSLConnectConfig{
verify: os.resource_abs_path('cert/ca.crt')
cert: os.resource_abs_path('cert/server.crt')
verify: os.resource_abs_path('cert/ca.crt')
cert: os.resource_abs_path('cert/server.crt')
cert_key: os.resource_abs_path('cert/server.key')
validate: true // mTLS
})!

View file

@ -25,160 +25,160 @@ pub enum SiteCat {
fn data_get() []SiteConfig {
data := [
SiteConfig{
name: 'www_threefold_io'
url: 'https://github.com/threefoldfoundation/www_threefold_io'
branch: 'default'
pull: false
cat: .web
alias: 'tf'
name: 'www_threefold_io'
url: 'https://github.com/threefoldfoundation/www_threefold_io'
branch: 'default'
pull: false
cat: .web
alias: 'tf'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_io'
domains: ['www.threefold.io', 'www.threefold.me']
descr: 'is our entry point for everyone, redirect to the detailed websites underneath.'
domains: ['www.threefold.io', 'www.threefold.me']
descr: 'is our entry point for everyone, redirect to the detailed websites underneath.'
},
SiteConfig{
name: 'www_threefold_cloud'
url: 'https://github.com/threefoldfoundation/www_threefold_cloud'
branch: 'default'
pull: false
cat: .web
alias: 'cloud'
name: 'www_threefold_cloud'
url: 'https://github.com/threefoldfoundation/www_threefold_cloud'
branch: 'default'
pull: false
cat: .web
alias: 'cloud'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_cloud'
domains: ['cloud.threefold.io', 'cloud.threefold.me']
descr: 'for people looking to deploy solutions on top of a cloud, alternative to e.g. digital ocean'
domains: ['cloud.threefold.io', 'cloud.threefold.me']
descr: 'for people looking to deploy solutions on top of a cloud, alternative to e.g. digital ocean'
},
SiteConfig{
name: 'www_threefold_farming'
url: 'https://github.com/threefoldfoundation/www_threefold_farming'
branch: 'default'
pull: false
cat: .web
alias: 'farming'
name: 'www_threefold_farming'
url: 'https://github.com/threefoldfoundation/www_threefold_farming'
branch: 'default'
pull: false
cat: .web
alias: 'farming'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_farming'
domains: ['farming.threefold.io', 'farming.threefold.me']
descr: 'crypto & minining enthusiasts, be the internet, know about farming & tokens.'
domains: ['farming.threefold.io', 'farming.threefold.me']
descr: 'crypto & minining enthusiasts, be the internet, know about farming & tokens.'
},
SiteConfig{
name: 'www_threefold_twin'
url: 'https://github.com/threefoldfoundation/www_threefold_twin'
branch: 'default'
pull: false
cat: .web
alias: 'twin'
name: 'www_threefold_twin'
url: 'https://github.com/threefoldfoundation/www_threefold_twin'
branch: 'default'
pull: false
cat: .web
alias: 'twin'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_twin'
domains: ['twin.threefold.io', 'twin.threefold.me']
descr: 'you digital life'
domains: ['twin.threefold.io', 'twin.threefold.me']
descr: 'you digital life'
},
SiteConfig{
name: 'www_threefold_marketplace'
url: 'https://github.com/threefoldfoundation/www_threefold_marketplace'
branch: 'default'
pull: false
cat: .web
alias: 'marketplace'
name: 'www_threefold_marketplace'
url: 'https://github.com/threefoldfoundation/www_threefold_marketplace'
branch: 'default'
pull: false
cat: .web
alias: 'marketplace'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_marketplace'
domains: ['now.threefold.io', 'marketplace.threefold.io', 'now.threefold.me',
domains: ['now.threefold.io', 'marketplace.threefold.io', 'now.threefold.me',
'marketplace.threefold.me']
descr: 'apps for community builders, runs on top of evdc'
},
SiteConfig{
name: 'www_conscious_internet'
url: 'https://github.com/threefoldfoundation/www_conscious_internet'
branch: 'default'
pull: false
cat: .web
alias: 'conscious_internet'
name: 'www_conscious_internet'
url: 'https://github.com/threefoldfoundation/www_conscious_internet'
branch: 'default'
pull: false
cat: .web
alias: 'conscious_internet'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_conscious_internet'
domains: ['www.consciousinternet.org', 'eco.threefold.io', 'community.threefold.io',
domains: ['www.consciousinternet.org', 'eco.threefold.io', 'community.threefold.io',
'eco.threefold.me', 'community.threefold.me']
descr: 'community around threefold, partners, friends, ...'
},
SiteConfig{
name: 'www_threefold_tech'
url: 'https://github.com/threefoldtech/www_threefold_tech'
branch: 'default'
pull: false
cat: .web
alias: 'tech'
name: 'www_threefold_tech'
url: 'https://github.com/threefoldtech/www_threefold_tech'
branch: 'default'
pull: false
cat: .web
alias: 'tech'
path_code: '/Users/despiegk/codewww/github/threefoldtech/www_threefold_tech'
domains: ['www.threefold.tech']
descr: 'cyberpandemic, use the tech to build your own solutions with, certification for TFGrid'
domains: ['www.threefold.tech']
descr: 'cyberpandemic, use the tech to build your own solutions with, certification for TFGrid'
},
SiteConfig{
name: 'www_examplesite'
url: 'https://github.com/threefoldfoundation/www_examplesite'
branch: 'default'
pull: false
cat: .web
alias: 'example'
name: 'www_examplesite'
url: 'https://github.com/threefoldfoundation/www_examplesite'
branch: 'default'
pull: false
cat: .web
alias: 'example'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_examplesite'
domains: ['example.threefold.io']
descr: ''
domains: ['example.threefold.io']
descr: ''
},
SiteConfig{
name: 'info_threefold'
url: 'https://github.com/threefoldfoundation/info_foundation_archive'
branch: 'default'
pull: false
cat: .wiki
alias: 'threefold'
name: 'info_threefold'
url: 'https://github.com/threefoldfoundation/info_foundation_archive'
branch: 'default'
pull: false
cat: .wiki
alias: 'threefold'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_foundation_archive'
domains: ['info.threefold.io']
descr: 'wiki for foundation, collaborate, what if farmings, tokens'
domains: ['info.threefold.io']
descr: 'wiki for foundation, collaborate, what if farmings, tokens'
},
SiteConfig{
name: 'info_sdk'
url: 'https://github.com/threefoldfoundation/info_sdk'
branch: 'default'
pull: false
cat: .wiki
alias: 'sdk'
name: 'info_sdk'
url: 'https://github.com/threefoldfoundation/info_sdk'
branch: 'default'
pull: false
cat: .wiki
alias: 'sdk'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_sdk'
domains: ['sdk.threefold.io', 'sdk_info.threefold.io']
descr: 'for IAC, devops, how to do Infrastructure As Code, 3bot, Ansible, tfgrid-sdk, ...'
domains: ['sdk.threefold.io', 'sdk_info.threefold.io']
descr: 'for IAC, devops, how to do Infrastructure As Code, 3bot, Ansible, tfgrid-sdk, ...'
},
SiteConfig{
name: 'info_legal'
url: 'https://github.com/threefoldfoundation/info_legal'
branch: 'default'
pull: false
cat: .wiki
alias: 'legal'
name: 'info_legal'
url: 'https://github.com/threefoldfoundation/info_legal'
branch: 'default'
pull: false
cat: .wiki
alias: 'legal'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_legal'
domains: ['legal.threefold.io', 'legal_info.threefold.io']
descr: ''
domains: ['legal.threefold.io', 'legal_info.threefold.io']
descr: ''
},
SiteConfig{
name: 'info_cloud'
url: 'https://github.com/threefoldfoundation/info_cloud'
branch: 'default'
pull: false
cat: .wiki
alias: 'cloud'
name: 'info_cloud'
url: 'https://github.com/threefoldfoundation/info_cloud'
branch: 'default'
pull: false
cat: .wiki
alias: 'cloud'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_cloud'
domains: ['cloud_info.threefold.io']
descr: 'how to use the cloud for deploying apps: evdc, kubernetes, planetary fs, ... + marketplace solutions '
domains: ['cloud_info.threefold.io']
descr: 'how to use the cloud for deploying apps: evdc, kubernetes, planetary fs, ... + marketplace solutions '
},
SiteConfig{
name: 'info_tftech'
url: 'https://github.com/threefoldtech/info_tftech'
branch: 'default'
pull: false
cat: .wiki
alias: 'tftech'
name: 'info_tftech'
url: 'https://github.com/threefoldtech/info_tftech'
branch: 'default'
pull: false
cat: .wiki
alias: 'tftech'
path_code: '/Users/despiegk/codewww/github/threefoldtech/info_tftech'
domains: ['info.threefold.tech']
descr: ''
domains: ['info.threefold.tech']
descr: ''
},
SiteConfig{
name: 'info_digitaltwin'
url: 'https://github.com/threefoldfoundation/info_digitaltwin.git'
branch: 'default'
pull: false
cat: .wiki
alias: 'twin'
name: 'info_digitaltwin'
url: 'https://github.com/threefoldfoundation/info_digitaltwin.git'
branch: 'default'
pull: false
cat: .wiki
alias: 'twin'
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_digitaltwin'
domains: ['twin_info.threefold.io']
descr: ''
domains: ['twin_info.threefold.io']
descr: ''
},
]
return data

View file

@ -89,9 +89,9 @@ type FrameFn = fn (voidptr)
fn main() {
mut app := &App{}
app.tui = tui.init(
user_data: app
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
user_data: app
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
hide_cursor: true
)
app.tui.run()!

View file

@ -35,12 +35,12 @@ type EventFn = fn (&tui.Event, voidptr)
fn main() {
mut app := &App{}
app.tui = tui.init(
user_data: app
event_fn: EventFn(event)
window_title: 'V term.ui event viewer'
hide_cursor: true
capture_events: true
frame_rate: 60
user_data: app
event_fn: EventFn(event)
window_title: 'V term.ui event viewer'
hide_cursor: true
capture_events: true
frame_rate: 60
use_alternate_buffer: false
)
println('V term.ui event viewer (press `esc` to exit)\n\n')

View file

@ -491,15 +491,15 @@ type CleanupFn = fn (voidptr)
fn main() {
mut app := &App{}
app.tui = ui.init(
user_data: app
init_fn: InitFn(init)
frame_fn: FrameFn(frame)
cleanup_fn: CleanupFn(cleanup)
event_fn: EventFn(event)
fail_fn: fail
user_data: app
init_fn: InitFn(init)
frame_fn: FrameFn(frame)
cleanup_fn: CleanupFn(cleanup)
event_fn: EventFn(event)
fail_fn: fail
capture_events: true
hide_cursor: true
frame_rate: 60
hide_cursor: true
frame_rate: 60
)
app.tui.run()!
}

View file

@ -32,9 +32,9 @@ fn event(e &tui.Event, mut app App) {
.mouse_down {
app.is_drag = true
app.cur_rect = Rect{
c: random_color()
x: e.x
y: e.y
c: random_color()
x: e.x
y: e.y
x2: e.x
y2: e.y
}
@ -89,11 +89,11 @@ type FrameFn = fn (voidptr)
fn main() {
mut app := &App{}
app.tui = tui.init(
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
hide_cursor: true
frame_rate: 60
frame_rate: 60
)
app.tui.run()!
}

View file

@ -116,11 +116,11 @@ type FrameFn = fn (voidptr)
fn main() {
mut app := &App{}
app.ui = ui.init(
user_data: app
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
frame_rate: frame_rate
hide_cursor: true
user_data: app
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
frame_rate: frame_rate
hide_cursor: true
window_title: 'V terminal pixelart drawing app'
)
app.mouse_pos.x = 40
@ -196,8 +196,8 @@ fn event(event &ui.Event, mut app App) {
nevent := ui.Event{
...oevent
button: ui.MouseButton.left
x: app.mouse_pos.x
y: app.mouse_pos.y
x: app.mouse_pos.x
y: app.mouse_pos.y
}
app.paint(nevent)
}
@ -206,8 +206,8 @@ fn event(event &ui.Event, mut app App) {
nevent := ui.Event{
...oevent
button: ui.MouseButton.right
x: app.mouse_pos.x
y: app.mouse_pos.y
x: app.mouse_pos.x
y: app.mouse_pos.y
}
app.paint(nevent)
}
@ -216,8 +216,8 @@ fn event(event &ui.Event, mut app App) {
nevent := ui.Event{
...oevent
button: .left
x: app.mouse_pos.x
y: app.mouse_pos.y
x: app.mouse_pos.x
y: app.mouse_pos.y
}
app.paint(nevent)
}
@ -226,8 +226,8 @@ fn event(event &ui.Event, mut app App) {
nevent := ui.Event{
...oevent
button: .middle
x: app.mouse_pos.x
y: app.mouse_pos.y
x: app.mouse_pos.x
y: app.mouse_pos.y
}
app.paint(nevent)
}

View file

@ -177,7 +177,7 @@ fn (b Buffer) view(from int, to int) View {
}
raw := lines.join('\n')
return View{
raw: raw.replace('\t', strings.repeat(` `, b.tab_width))
raw: raw.replace('\t', strings.repeat(` `, b.tab_width))
cursor: Cursor{
pos_x: x
pos_y: b.cursor.pos_y
@ -644,10 +644,10 @@ fn main() {
files: files
}
a.tui = tui.init(
user_data: a
init_fn: InitFn(init)
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
user_data: a
init_fn: InitFn(init)
frame_fn: FrameFn(frame)
event_fn: EventFn(event)
capture_events: true
)
a.tui.run()!

View file

@ -162,7 +162,7 @@ fn (mut s Snake) grow() {
}
}
s.body << BodyPart{
pos: pos
pos: pos
facing: head.facing
}
}
@ -270,7 +270,7 @@ mut:
fn (mut a App) new_game() {
mut snake := Snake{
body: []BodyPart{len: 1, init: BodyPart{}}
app: a
app: a
}
snake.randomize()
mut rat := Rat{
@ -465,12 +465,12 @@ type FrameFn = fn (voidptr)
fn main() {
mut app := &App{}
app.termui = termui.init(
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
init_fn: InitFn(init)
user_data: app
event_fn: EventFn(event)
frame_fn: FrameFn(frame)
init_fn: InitFn(init)
hide_cursor: true
frame_rate: 10
frame_rate: 10
)
app.termui.run()!
}

View file

@ -24,12 +24,12 @@ const limit_thickness = 3
const text_cfg = gx.TextCfg{
align: .left
size: text_size
size: text_size
color: gx.rgb(0, 0, 0)
}
const over_cfg = gx.TextCfg{
align: .left
size: text_size
size: text_size
color: gx.white
}
@ -160,14 +160,14 @@ fn main() {
}
game.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'V Tetris' //
user_data: game
frame_fn: frame
event_fn: on_event
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'V Tetris' //
user_data: game
frame_fn: frame
event_fn: on_event
html5_canvas_name: 'canvas'
)
game.init_game()

View file

@ -25,12 +25,12 @@ const limit_thickness = 3
const text_cfg = gx.TextCfg{
align: .left
size: text_size
size: text_size
color: gx.rgb(0, 0, 0)
}
const over_cfg = gx.TextCfg{
align: .left
size: text_size
size: text_size
color: gx.white
}
@ -162,15 +162,15 @@ fn main() {
fpath = 'fonts/RobotoMono-Regular.ttf'
}
game.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'V Tetris'
user_data: game
frame_fn: frame
event_fn: on_event
font_path: fpath // wait_events: true
window_title: 'V Tetris'
user_data: game
frame_fn: frame
event_fn: on_event
font_path: fpath // wait_events: true
)
game.init_game()
game.gg.run() // Run the render loop in the main thread

View file

@ -117,15 +117,15 @@ fn my_event_manager(mut ev gg.Event, mut app App_data) {
fn main() {
mut app := &App_data{}
app.gg = gg.new_context(
width: win_width
height: win_height
width: win_width
height: win_height
create_window: true
window_title: 'Test TTF module'
user_data: app
bg_color: bg_color
frame_fn: draw_frame
event_fn: my_event_manager
init_fn: my_init
window_title: 'Test TTF module'
user_data: app
bg_color: bg_color
frame_fn: draw_frame
event_fn: my_event_manager
init_fn: my_init
)
// load TTF fonts
for font_path in font_paths {
@ -139,10 +139,10 @@ fn main() {
// TTF render 0 Frame counter
app.ttf_render << &ttf.TTF_render_Sokol{
bmp: &ttf.BitMap{
tf: &app.tf[0]
buf: unsafe { malloc_noscan(32000000) }
tf: &app.tf[0]
buf: unsafe { malloc_noscan(32000000) }
buf_size: (32000000)
color: 0xFF0000FF
color: 0xFF0000FF
// style: .raw
// use_font_metrics: true
}

View file

@ -159,9 +159,9 @@ fn (mut item_list Item_list) scan_folder(path string, in_index int) ! {
for c, x in lst {
pt := '${path}${item_list.path_sep}${x}'
mut item := Item{
path: path
name: x
container_index: in_index
path: path
name: x
container_index: in_index
container_item_index: c
}
if os.is_dir(pt) {
@ -189,8 +189,8 @@ fn (mut item_list Item_list) scan_folder(path string, in_index int) ! {
for x in folder_list {
pt := '${path}${item_list.path_sep}${x}'
item := Item{
path: path
name: x
path: path
name: x
i_type: .folder
}
item_list.lst << item
@ -224,10 +224,10 @@ fn (mut item_list Item_list) get_items_list(args []string) {
// scan folder
if os.is_dir(x) {
mut item := Item{
path: x
name: x
path: x
name: x
container_index: item_list.lst.len
i_type: .folder
i_type: .folder
}
item_list.lst << item
item_list.scan_folder(x, item_list.lst.len - 1) or {
@ -236,8 +236,8 @@ fn (mut item_list Item_list) get_items_list(args []string) {
}
} else {
mut item := Item{
path: ''
name: x
path: ''
name: x
container_index: -1
}
ext := get_extension(x)

View file

@ -115,16 +115,16 @@ mut:
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
height: h
width: w
height: h
num_mipmaps: 0
// usage: .dynamic
label: &u8(0)
label: &u8(0)
d3d11_texture: 0
}
// comment if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
@ -133,8 +133,8 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
mut smp_desc := gfx.SamplerDesc{
min_filter: .linear
mag_filter: .linear
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
}
sg_smp := gfx.make_sampler(&smp_desc)
@ -150,7 +150,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
ptr: buf
ptr: buf
size: usize(sz)
}
gfx.update_image(sg_img, &tmp_sbc)
@ -326,7 +326,7 @@ fn app_init(mut app App) {
color_state := gfx.ColorTargetState{
blend: gfx.BlendState{
enabled: true
enabled: true
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}
@ -335,7 +335,7 @@ fn app_init(mut app App) {
pipdesc.depth = gfx.DepthState{
write_enabled: true
compare: .less_equal
compare: .less_equal
}
pipdesc.cull_mode = .back
app.pip_viewer = sgl.make_pipeline(&pipdesc)
@ -572,12 +572,12 @@ fn draw_text(mut app App, in_txt string, in_x int, in_y int, fnt_sz f32) {
mut txt_conf_c0 := gx.TextCfg{
color: gx.white // gx.rgb( (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff)
align: .left
size: font_size
size: font_size
}
mut txt_conf_c1 := gx.TextCfg{
color: gx.black // gx.rgb( (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff)
align: .left
size: font_size
size: font_size
}
x := int(in_x * scale)
@ -801,7 +801,7 @@ fn main() {
mut app := &App{
gg: unsafe { nil }
// zip fields
zip: unsafe { nil }
zip: unsafe { nil }
item_list: unsafe { nil }
}
@ -815,19 +815,19 @@ fn main() {
load_and_show(os.args[1..], mut app)
app.gg = gg.new_context(
width: win_width
height: win_height
create_window: true
window_title: 'V Image viewer 0.8'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: app_init
cleanup_fn: cleanup
event_fn: my_event_manager
font_path: font_path
enable_dragndrop: true
max_dropped_files: 64
width: win_width
height: win_height
create_window: true
window_title: 'V Image viewer 0.8'
user_data: app
bg_color: bg_color
frame_fn: frame
init_fn: app_init
cleanup_fn: cleanup
event_fn: my_event_manager
font_path: font_path
enable_dragndrop: true
max_dropped_files: 64
max_dropped_file_path_length: 2048
// ui_mode: true
)

View file

@ -28,15 +28,15 @@ fn (mut il Item_list) scan_zip(path string, in_index int) ! {
if is_image(ext) == true {
il.n_item += 1
mut item := Item{
need_extract: true
path: path
name: name.clone()
container_index: in_index
need_extract: true
path: path
name: name.clone()
container_index: in_index
container_item_index: index
i_type: ext
n_item: il.n_item
drawable: true
size: size
i_type: ext
n_item: il.n_item
drawable: true
size: size
}
il.lst << item
}

View file

@ -62,9 +62,9 @@ fn make_token(user User) string {
jwt_header := JwtHeader{'HS256', 'JWT'}
jwt_payload := JwtPayload{
sub: '${user.id}'
sub: '${user.id}'
name: '${user.username}'
iat: time.now()
iat: time.now()
}
header := base64.url_encode(json.encode(jwt_header).bytes())

View file

@ -10,7 +10,7 @@ fn (mut app App) service_add_product(product_name string, user_id int) ! {
}
product_model := Product{
name: product_name
name: product_name
user_id: user_id
}

View file

@ -18,7 +18,7 @@ fn (mut app App) service_add_user(username string, password string) ! {
user_model := User{
username: username
password: hashed_password
active: true
active: true
}
mut insert_error := ''

View file

@ -60,9 +60,9 @@ fn make_token(user User) string {
jwt_header := JwtHeader{'HS256', 'JWT'}
jwt_payload := JwtPayload{
sub: '${user.id}'
sub: '${user.id}'
name: '${user.username}'
iat: time.now()
iat: time.now()
}
header := base64.url_encode(json.encode(jwt_header).bytes())

View file

@ -21,7 +21,7 @@ fn (mut app App) service_add_user(username string, password string) !User {
user_model := User{
username: username
password: hashed_password
active: true
active: true
}
sql db {

Some files were not shown because too many files have changed in this diff Show more