Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

ResourceType

rc.ResourceType
pub const ResourceType = enum

File

Code

pub const ResourceType = enum {
    accelerators,
    bitmap,
    cursor,
    dialog,
    dialogex,
    /// As far as I can tell, this is undocumented; the most I could find was this:
    /// https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/91697
    dlginclude,
    /// Undocumented, basically works exactly like RCDATA
    dlginit,
    font,
    html,
    icon,
    menu,
    menuex,
    messagetable,
    plugplay, // Obsolete
    rcdata,
    stringtable,
    /// Undocumented
    toolbar,
    user_defined,
    versioninfo,
    vxd, // Obsolete

    // Types that are treated as a user-defined type when encountered, but have
    // special meaning without the Visual Studio GUI. We match the Win32 RC compiler
    // behavior by acting as if these keyword don't exist when compiling the .rc
    // (thereby treating them as user-defined).
    //textinclude, // A special resource that is interpreted by Visual C++.
    //typelib, // A special resource that is used with the /TLBID and /TLBOUT linker options

    // Types that can only be specified by numbers, they don't have keywords
    cursor_num,
    icon_num,
    string_num,
    anicursor_num,
    aniicon_num,
    fontdir_num,
    manifest_num,

    const map = std.StaticStringMapWithEql(
        ResourceType,
        std.static_string_map.eqlAsciiIgnoreCase,
    ).initComptime(.{
        .{ "ACCELERATORS", .accelerators },
        .{ "BITMAP", .bitmap },
        .{ "CURSOR", .cursor },
        .{ "DIALOG", .dialog },
        .{ "DIALOGEX", .dialogex },
        .{ "DLGINCLUDE", .dlginclude },
        .{ "DLGINIT", .dlginit },
        .{ "FONT", .font },
        .{ "HTML", .html },
        .{ "ICON", .icon },
        .{ "MENU", .menu },
        .{ "MENUEX", .menuex },
        .{ "MESSAGETABLE", .messagetable },
        .{ "PLUGPLAY", .plugplay },
        .{ "RCDATA", .rcdata },
        .{ "STRINGTABLE", .stringtable },
        .{ "TOOLBAR", .toolbar },
        .{ "VERSIONINFO", .versioninfo },
        .{ "VXD", .vxd },
    });

    pub fn fromString(bytes: SourceBytes) ResourceType {
        const maybe_ordinal = res.NameOrOrdinal.maybeOrdinalFromString(bytes);
        if (maybe_ordinal) |ordinal| {
            if (ordinal.ordinal >= 256) return .user_defined;
            return fromRT(@fromBackingInt(@intCast(ordinal.ordinal)));
        }
        return map.get(bytes.slice) orelse .user_defined;
    }

    // TODO: Some comptime validation that RT <-> ResourceType conversion is synced?
    pub fn fromRT(rt: res.RT) ResourceType {
        return switch (rt) {
            .ACCELERATOR => .accelerators,
            .ANICURSOR => .anicursor_num,
            .ANIICON => .aniicon_num,
            .BITMAP => .bitmap,
            .CURSOR => .cursor_num,
            .DIALOG => .dialog,
            .DLGINCLUDE => .dlginclude,
            .DLGINIT => .dlginit,
            .FONT => .font,
            .FONTDIR => .fontdir_num,
            .GROUP_CURSOR => .cursor,
            .GROUP_ICON => .icon,
            .HTML => .html,
            .ICON => .icon_num,
            .MANIFEST => .manifest_num,
            .MENU => .menu,
            .MESSAGETABLE => .messagetable,
            .PLUGPLAY => .plugplay,
            .RCDATA => .rcdata,
            .STRING => .string_num,
            .TOOLBAR => .toolbar,
            .VERSION => .versioninfo,
            .VXD => .vxd,
            _ => .user_defined,
        };
    }

    pub fn canUseRawData(resource: ResourceType) bool {
        return switch (resource) {
            .user_defined,
            .html,
            .plugplay, // Obsolete
            .rcdata,
            .vxd, // Obsolete
            .manifest_num,
            .dlginit,
            => true,
            else => false,
        };
    }

    pub fn nameForErrorDisplay(resource: ResourceType) []const u8 {
        return switch (resource) {
            // zig fmt: off
            .accelerators, .bitmap, .cursor, .dialog, .dialogex, .dlginclude, .dlginit, .font,
            .html, .icon, .menu, .menuex, .messagetable, .plugplay, .rcdata, .stringtable,
            .toolbar, .versioninfo, .vxd => @tagName(resource),
            // zig fmt: on
            .user_defined => "user-defined",
            .cursor_num => std.fmt.comptimePrint("{d} (cursor)", .{@backingInt(res.RT.CURSOR)}),
            .icon_num => std.fmt.comptimePrint("{d} (icon)", .{@backingInt(res.RT.ICON)}),
            .string_num => std.fmt.comptimePrint("{d} (string)", .{@backingInt(res.RT.STRING)}),
            .anicursor_num => std.fmt.comptimePrint("{d} (anicursor)", .{@backingInt(res.RT.ANICURSOR)}),
            .aniicon_num => std.fmt.comptimePrint("{d} (aniicon)", .{@backingInt(res.RT.ANIICON)}),
            .fontdir_num => std.fmt.comptimePrint("{d} (fontdir)", .{@backingInt(res.RT.FONTDIR)}),
            .manifest_num => std.fmt.comptimePrint("{d} (manifest)", .{@backingInt(res.RT.MANIFEST)}),
        };
    }
}