mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
gg: make create_image() return !Image
This commit is contained in:
parent
75deb66fd4
commit
d60ceb45cd
6 changed files with 31 additions and 26 deletions
|
@ -25,11 +25,10 @@ pub mut:
|
|||
}
|
||||
|
||||
// create_image creates an `Image` from `file`.
|
||||
// TODO return !Image
|
||||
pub fn (ctx &Context) create_image(file string) Image {
|
||||
pub fn (ctx &Context) create_image(file string) !Image {
|
||||
// println('\ncreate_image("$file")')
|
||||
if !os.exists(file) {
|
||||
return Image{}
|
||||
return error('image file "${file}" not found')
|
||||
}
|
||||
$if macos {
|
||||
if ctx.native_rendering {
|
||||
|
@ -47,7 +46,7 @@ pub fn (ctx &Context) create_image(file string) Image {
|
|||
if !gfx.is_valid() {
|
||||
// Sokol is not initialized yet, add stbi object to a queue/cache
|
||||
// ctx.image_queue << file
|
||||
stb_img := stbi.load(file) or { return Image{} }
|
||||
stb_img := stbi.load(file)!
|
||||
img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -220,8 +219,8 @@ fn create_image(file string) Image {
|
|||
// memory buffer `buf` of size `bufsize`.
|
||||
//
|
||||
// See also: create_image_from_byte_array
|
||||
pub fn (mut ctx Context) create_image_from_memory(buf &u8, bufsize int) Image {
|
||||
stb_img := stbi.load_from_memory(buf, bufsize) or { return Image{} }
|
||||
pub fn (mut ctx Context) create_image_from_memory(buf &u8, bufsize int) !Image {
|
||||
stb_img := stbi.load_from_memory(buf, bufsize)!
|
||||
mut img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -239,7 +238,7 @@ pub fn (mut ctx Context) create_image_from_memory(buf &u8, bufsize int) Image {
|
|||
// byte array `b`.
|
||||
//
|
||||
// See also: create_image_from_memory
|
||||
pub fn (mut ctx Context) create_image_from_byte_array(b []u8) Image {
|
||||
pub fn (mut ctx Context) create_image_from_byte_array(b []u8) !Image {
|
||||
return ctx.create_image_from_memory(b.data, b.len)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue