use builtin hash functions instead of rolling my own

font_atlas
Alessandro Mauri 1 month ago
parent bb1745a05d
commit 9a785e0f06
  1. 2
      src/ugui_button.c3
  2. 16
      src/ugui_data.c3
  3. 2
      src/ugui_div.c3
  4. 2
      src/ugui_impl.c3
  5. 4
      src/ugui_slider.c3

@ -5,7 +5,7 @@ import std::io;
// draw a button, return the events on that button
fn ElemEvents! Ctx.button(&ctx, String label, Rect size)
{
Id id = hash(label);
Id id = label.hash();
Elem *parent = ctx.get_parent()!;
Elem *c_elem = ctx.get_elem(id)!;

@ -104,22 +104,6 @@ fault UgError {
UNEXPECTED_ELEMENT,
}
fn Id fnv1a(String str)
{
const ulong FNV_OFF = 0xcbf29ce484222325;
const ulong FNV_PRIME = 0x100000001b3;
ulong hash = FNV_OFF;
foreach (c : str) {
hash ^= c;
hash *= FNV_PRIME;
}
return hash;
}
macro hash(String str) { return fnv1a(str); }
macro uint_to_rgba(uint u) {
return Color{
.r = (char)((u >> 24) & 0xff),

@ -4,7 +4,7 @@ import std::io;
fn void! Ctx.div_begin(&ctx, String label, Rect size)
{
Id id = hash(label);
Id id = label.hash();
Elem *parent = ctx.get_parent()!;
Elem* c_elem = ctx.get_elem(id)!;

@ -28,7 +28,7 @@ macro Ctx.get_elem(&ctx, Id id)
// if it does't find one
macro Ctx.get_elem_by_label(&ctx, String label)
{
Id id = hash(label);
Id id = label.hash();
return ctx.cache.search(id);
}

@ -9,7 +9,7 @@ import std::io;
*/
fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
{
Id id = hash(label);
Id id = label.hash();
Elem *parent = ctx.get_parent()!;
Elem *c_elem = ctx.get_elem(id)!;
@ -81,7 +81,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
*/
fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
{
Id id = hash(label);
Id id = label.hash();
Elem *parent = ctx.get_parent()!;
Elem *c_elem = ctx.get_elem(id)!;

Loading…
Cancel
Save