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.

Entry

ico.Entry
pub const Entry = struct

File

Code

pub const Entry = struct {
    // Icons are limited to u8 sizes, cursors can have u16,
    // so we store as u16 and truncate when needed.
    width: u16,
    height: u16,
    num_colors: u8,
    /// This should always be zero, but whatever value it is gets
    /// carried over so we need to store it
    reserved: u8,
    type_specific_data: union(ImageType) {
        icon: struct {
            color_planes: u16,
            bits_per_pixel: u16,
        },
        cursor: struct {
            hotspot_x: u16,
            hotspot_y: u16,
        },
    },
    data_size_in_bytes: u32,
    data_offset_from_start_of_file: u32,

    pub const res_byte_len = 14;

    pub fn writeResData(self: Entry, writer: *std.Io.Writer, id: u16) !void {
        switch (self.type_specific_data) {
            .icon => |icon_data| {
                try writer.writeInt(u8, @as(u8, @truncate(self.width)), .little);
                try writer.writeInt(u8, @as(u8, @truncate(self.height)), .little);
                try writer.writeInt(u8, self.num_colors, .little);
                try writer.writeInt(u8, self.reserved, .little);
                try writer.writeInt(u16, icon_data.color_planes, .little);
                try writer.writeInt(u16, icon_data.bits_per_pixel, .little);
                try writer.writeInt(u32, self.data_size_in_bytes, .little);
            },
            .cursor => |cursor_data| {
                try writer.writeInt(u16, self.width, .little);
                try writer.writeInt(u16, self.height, .little);
                try writer.writeInt(u16, cursor_data.hotspot_x, .little);
                try writer.writeInt(u16, cursor_data.hotspot_y, .little);
                try writer.writeInt(u32, self.data_size_in_bytes + 4, .little);
            },
        }
        try writer.writeInt(u16, id, .little);
    }
}