DVUI

iconWidth

Get the width of an icon at a specified height.

Only valid between Window.beginand Window.end.

Parameters

#
name:[]const u8
[]const u8
tvg_bytes:[]const u8
[]const u8
height:f32
f32

Source

Implementation

#
pub fn iconWidth(name: []const u8, tvg_bytes: []const u8, height: f32) TvgError!f32 {
    if (comptime !useTvg) {
        return (Options{}).fontGet().withSize(height / 2).textSize(name).w;
    }

    if (height == 0) return 0.0;
    var stream: std.Io.Reader = .fixed(tvg_bytes);
    var parser = tvg.tvg.parse(currentWindow().arena(), &stream) catch |err| {
        log.warn("iconWidth Tinyvg error {any} parsing icon {s}\n", .{ err, name });
        return TvgError.tvgError;
    };
    defer parser.deinit();

    return height * @as(f32, @floatFromInt(parser.header.width)) / @as(f32, @floatFromInt(parser.header.height));
}