fix issues if an item is added to a popup multiple times

This commit is contained in:
Felix Kratz 2024-02-23 12:03:04 +01:00
parent b5c2c65447
commit 533d4914f9

View file

@ -258,7 +258,15 @@ static void popup_close_window(struct popup* popup) {
window_close(&popup->window);
}
static bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
for (int i = 0; i < popup->num_items; i++) {
if (popup->items[i] == bar_item) return true;
}
return false;
}
void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
if (popup_contains_item(popup, bar_item)) return;
popup->num_items++;
popup->items = realloc(popup->items,
sizeof(struct bar_item*)*popup->num_items);
@ -267,13 +275,6 @@ void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
popup->needs_ordering = true;
}
static bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
for (int i = 0; i < popup->num_items; i++) {
if (popup->items[i] == bar_item) return true;
}
return false;
}
void popup_remove_item(struct popup* popup, struct bar_item* bar_item) {
if (popup->num_items == 0 || !popup_contains_item(popup, bar_item))
return;