DVUI

hash

Hashes all the values of the options

Only useful to check exact equality between two Options

Parameters

#
self:*const Options
*const Options

Source

Implementation

#
pub fn hash(self: *const Options) u64 {
    const asBytes = std.mem.asBytes;
    var hasher = dvui.fnv.init();

    hasher.update(asBytes(&self.min_size_contentGet()));
    hasher.update(asBytes(&self.max_size_contentGet()));
    if (self.rect) |rect| hasher.update(asBytes(&rect));

    hasher.update(asBytes(&self.borderGet()));
    hasher.update(asBytes(&self.marginGet()));
    hasher.update(asBytes(&self.paddingGet()));

    hasher.update(asBytes(&self.cornersGet()));
    hasher.update(asBytes(&self.gravityGet()));
    hasher.update(asBytes(&self.expandGet()));
    hasher.update(asBytes(&self.rotationGet()));
    hasher.update(asBytes(&self.backgroundGet()));

    hasher.update(asBytes(&self.styleGet()));
    // FIXME: Should hash the theme fields here in a consistent way
    // hasher.update(asBytes(self.themeGet()));

    if (self.color_fill) |col| hasher.update(asBytes(&col));
    if (self.color_fill_hover) |col| hasher.update(asBytes(&col));
    if (self.color_fill_press) |col| hasher.update(asBytes(&col));
    if (self.color_text) |col| hasher.update(asBytes(&col));
    if (self.color_text_hover) |col| hasher.update(asBytes(&col));
    if (self.color_text_press) |col| hasher.update(asBytes(&col));
    if (self.color_border) |col| hasher.update(asBytes(&col));

    const font = self.fontGet();
    hasher.update(asBytes(&font.hash()));

    if (self.tab_index) |ti| hasher.update(asBytes(&ti));
    hasher.update(asBytes(&self.idExtra()));
    if (self.tag) |tag| hasher.update(tag);
    if (self.name) |name| hasher.update(name);

    return hasher.final();
}