DVUI

updateImageSource

Update a texture that was created with textureCreate. or fromImageSource

The dimensions of the image must match the initial dimensions! Only valid to call while the underlying Texture is not destroyed!

Only valid between Window.begin and Window.end.

Parameters

#
self:*Texture
*Texture
src:ImageSource
ImageSource

Source

Implementation

#
pub fn updateImageSource(self: *Texture, src: ImageSource) !void {
    switch (src) {
        .imageFile => |f| {
            const img = try Color.PMAImage.fromImageFile(f.name, dvui.currentWindow().arena(), f.bytes);
            defer dvui.currentWindow().arena().free(img.pma);
            try update(self, img.pma);
        },
        .pixels => |px| {
            const copy = try dvui.currentWindow().arena().dupe(u8, px.rgba);
            defer dvui.currentWindow().arena().free(copy);
            const pma = Color.PMA.sliceFromRGBA(copy);
            try update(self, pma);
        },
        .pixelsPMA => |px| {
            try update(self, px.rgba);
        },
        .texture => @panic("this is not supported currently"),
    }
}