1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

autofree: more tests; gg: fix draw_circle with hidpi

This commit is contained in:
Alexander Medvednikov 2020-11-15 15:09:35 +01:00
parent fe3d2a9aba
commit 26785668c0
5 changed files with 35 additions and 4 deletions

View File

@ -211,8 +211,6 @@ jobs:
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
# - name: Build vpm
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
# - name: Build V UI examples
# run: ./v install ui && git clone --depth 1 https://github.com/vlang/ui && cd ui && ../v examples/calculator.v && cd ..
# - name: Freestanding
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
- name: v self compilation

View File

@ -308,10 +308,16 @@ pub fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.C
sgl.end()
}
pub fn (ctx &Context) draw_circle(x f32, y f32, r int, c gx.Color) {
pub fn (ctx &Context) draw_circle(x f32, y f32, r f32, c gx.Color) {
if ctx.scale == 1 {
ctx.draw_circle_with_segments(x,y,r,10, c)
}
else {
ctx.draw_circle_with_segments(x*f32(ctx.scale),y*f32(ctx.scale),r*ctx.scale,10, c)
}
}
pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r int, segments int, c gx.Color) {
pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r f32, segments int, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}

View File

@ -217,6 +217,11 @@ fn get_font_path_variant(font_path string, variant FontVariant) string {
} else {
fpath += '-bold'
}
$if macos {
if os.exists('SFNS-bold') {
fpath = 'SFNS-bold'
}
}
}
.italic {
if fpath.ends_with('-Regular') {

View File

@ -1025,6 +1025,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
// g.autofree_call_pregen(node.exprs[0] as ast.CallExpr)
}
// g.autofree_scope_vars(node.pos.pos - 1)
g.writeln('// ast.Return free_end')
// g.write_autofree_stmts_when_needed(node)
}
g.return_statement(node, af)
@ -3785,6 +3786,10 @@ fn (mut g Gen) return_statement(node ast.Return, af bool) {
defer {
g.inside_return = false
}
if af {
tmp := g.new_tmp_var()
g.writeln('// $tmp = ...')
}
// got to do a correct check for multireturn
sym := g.table.get_type_symbol(g.fn_decl.return_type)
fn_return_is_multi := sym.kind == .multi_return

View File

@ -240,6 +240,22 @@ fn free_before_return_bool() bool {
return true
}
struct User {
name string
age int
}
fn free_array_except_returned_element() {
user := get_user()
println(user)
}
fn get_user() User {
users := [User{'Peter', 25}, User{'Alice', 21}]
user := users[0] // has to be cloned, since `users` are going to be freed at the end of the function
return user
}
fn main() {
println('start')
simple()
@ -262,6 +278,7 @@ fn main() {
// free_before_return_bool()
// free_map()
// loop_map()
// free_array_except_returned_element()
println('end')
}