update: getIcon and fallback
This commit is contained in:
parent
966035dccb
commit
cce0c6a954
1 changed files with 15 additions and 9 deletions
|
|
@ -22,15 +22,6 @@ pub const SvgIcon = struct {
|
||||||
pub fn init(allocator: std.mem.Allocator) !SvgIcon {
|
pub fn init(allocator: std.mem.Allocator) !SvgIcon {
|
||||||
var self = SvgIcon{};
|
var self = SvgIcon{};
|
||||||
|
|
||||||
// const sets = [_]IconSet{ .bootstrap, .dripicons, .hero_outline, .hero_solid, .material };
|
|
||||||
//
|
|
||||||
// inline for (sets) |set| {
|
|
||||||
// const data = embedded_data.get(set).?;
|
|
||||||
//
|
|
||||||
// try self.loadSet(allocator, set, data);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
inline for (std.meta.fields(IconSet)) |field| {
|
inline for (std.meta.fields(IconSet)) |field| {
|
||||||
const set = @field(IconSet, field.name);
|
const set = @field(IconSet, field.name);
|
||||||
const data = embedded_data.get(set);
|
const data = embedded_data.get(set);
|
||||||
|
|
@ -55,6 +46,12 @@ pub const SvgIcon = struct {
|
||||||
return self.icon_map.get(key);
|
return self.icon_map.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getIcon(self: *const SvgIcon,allocator: std.mem.Allocator, kind: []const u8, name: []const u8) ?[]const u8 {
|
||||||
|
const key = std.fmt.allocPrint(allocator, "{s}:{s}", .{ kind, name }) catch return null;
|
||||||
|
defer allocator.free(key);
|
||||||
|
return self.icon_map.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn count(self: *const SvgIcon) usize {
|
pub fn count(self: *const SvgIcon) usize {
|
||||||
return self.icon_map.count();
|
return self.icon_map.count();
|
||||||
}
|
}
|
||||||
|
|
@ -109,3 +106,12 @@ pub const SvgIcon = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const fallback_svg =
|
||||||
|
\\<div class="svg-container">
|
||||||
|
\\<svg width="24" height="24" fill="none">
|
||||||
|
\\ <rect width="24" height="24" rx="4" fill="#f0f0f0"/>
|
||||||
|
\\ <text x="12" y="16" font-size="10" text-anchor="middle" fill="#999">?</text>
|
||||||
|
\\</svg>
|
||||||
|
\\</div>
|
||||||
|
;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue