init
It's expected to call this when self is undefined
Parameters
- self:*IconWidget
- *IconWidget
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- name:[]const u8
- []const u8
- tvg_bytes:[]const u8
- []const u8
- icon_opts:dvui.IconRenderOptions
- dvui.IconRenderOptions
- opts:Options
- Options
Source
Implementation
pub fn init(self: *IconWidget, src: std.builtin.SourceLocation, name: []const u8, tvg_bytes: []const u8, icon_opts: dvui.IconRenderOptions, opts: Options) void {
var size = Size{};
if (opts.min_size_content) |msc| {
// user gave us a min size, use it
size = msc;
size.w = @max(size.w, dvui.iconWidth(name, tvg_bytes, size.h) catch size.w);
} else {
// user didn't give us one, make it the height of text
const h = opts.fontGet().textHeight();
size = Size{ .w = dvui.iconWidth(name, tvg_bytes, h) catch h, .h = h };
}
const defaults = Options{ .label = .{ .text = name }, .role = .image };
self.* = .{
.wd = WidgetData.init(src, .{}, defaults.override(opts).override(.{ .min_size_content = size })),
.name = name,
.tvg_bytes = tvg_bytes,
.icon_opts = icon_opts,
};
self.data().register();
self.data().borderAndBackground(.{});
}