Skip to content

Instantly share code, notes, and snippets.

@OkiStuff
Created November 20, 2021 15:48
Show Gist options
  • Save OkiStuff/b7cd8441b7c0432ae725c55b3afdbfd9 to your computer and use it in GitHub Desktop.
Save OkiStuff/b7cd8441b7c0432ae725c55b3afdbfd9 to your computer and use it in GitHub Desktop.
void update_navbar(navbar* bar, Applet* self)
{
// This trash code should only make it so an event is called once and never called again until a different event has occurred.
for (int i = 0; i < ARRAY_LENGTH(bar->components); i++)
{
int hover_once = 0;
int normal_once = 0;
if (CHECK_COLLISION_POINT_REC(get_mouse_position_vec2(self), bar->components[i]->box))
{
// very trash code below
int one_mouse_press = 0;
normal_once = 0;
if (mouse_down(self, MOUSE_LEFT) && one_mouse_press == 0)
{
bar->components[i]->handle(PRESSED, bar->components[i]);
one_mouse_press = 1;
}
else if (mouse_up(self, MOUSE_LEFT) && one_mouse_press == 1) one_mouse_press = 0;
else if (hover_once == 0)
{
hover_once = 1;
bar->components[i]->handle(HOVER, bar->components[i]);
}
}
else if (normal_once == 0)
{
if (hover_once != 0) hover_once = 0;
bar->components[i]->handle(-1, bar->components[i]);
normal_once = 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment