renderIcon
Calls renderTexture with the texture created from tvg_bytes
Only valid between Window.beginand Window.end.
Parameters
- name:[]const u8
- []const u8
- tvg_bytes:[]const u8
- []const u8
- rs:RectScale
- RectScale
- opts:TextureOptions
- TextureOptions
- icon_opts:IconRenderOptions
- IconRenderOptions
Source
Implementation
pub fn renderIcon(name: []const u8, tvg_bytes: []const u8, rs: RectScale, opts: TextureOptions, icon_opts: IconRenderOptions) Backend.GenericError!void {
if (rs.s == 0) return;
if (dvui.clipGet().intersect(rs.r).empty()) return;
if (comptime !dvui.useTvg) {
try renderText(.{
.font = (dvui.Options{}).fontGet().withSize(0.5 * rs.r.h / rs.s),
.text = name,
.rs = rs,
.color = (dvui.Options{}).color(.text),
});
return;
}
// Ask for an integer size icon, then render it to fit rs
const target_size = rs.r.h;
const ask_height = @ceil(target_size);
var h = dvui.fnv.init();
h.update(std.mem.asBytes(&tvg_bytes.ptr));
h.update(std.mem.asBytes(&ask_height));
h.update(std.mem.asBytes(&icon_opts));
const hash = h.final();
const texture = dvui.textureGetCached(hash) orelse blk: {
const texture = Texture.fromTvgFile(name, tvg_bytes, @trunc(ask_height), icon_opts) catch |err| {
dvui.logError(@src(), err, "Could not create texture from tvg file \"{s}\"", .{name});
return;
};
dvui.textureAddToCache(hash, texture);
break :blk texture;
};
try renderTexture(texture, rs, opts);
}