tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit 7f496de5c8407f6d566da0bf99bbc1ef2b16a506
parent 6810bb54e1c597f8326aa62a5b1ce51fc421c9c0
Author: GNUfault <connor@gnufault.org>
Date: Fri, 30 Oct 2026 16:59:44 +0000
Allocate the button list dynamically
Diffstat:
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/game/src/ta_button.c b/game/src/ta_button.c
@@ -29,6 +29,8 @@ void ta_button_lists_init(ta_button_lists *list) {
return;
}
+ list->buttons = TA_NULL;
+ list->buttons_size = 0;
list->size = 0;
list->selected = 0;
list->up_was_down = ta_false;
@@ -41,6 +43,19 @@ ta_bool ta_button_lists_add(ta_button_lists *list, const char *label, ta_button_
return ta_false;
}
+ if (list->size >= list->buttons_size) {
+ ta_size new_capacity = (list->buttons_size == 0) ? 4 : (list->buttons_size * 2);
+
+ ta_button *temp = (ta_button *)ta_realloc(list->buttons, new_capacity * sizeof(ta_button));
+
+ if (temp == TA_NULL) {
+ return ta_false;
+ }
+
+ list->buttons = temp;
+ list->buttons_size = new_capacity;
+ }
+
ta_uint32 font_size = scale_to_display(TA_BUTTON_FONT_SIZE);
if (font_size > TA_BUTTON_FONT_SIZE_MAX) {
@@ -53,7 +68,6 @@ ta_bool ta_button_lists_add(ta_button_lists *list, const char *label, ta_button_
if (text_idle == 0 || text_selected == 0) {
ta_text_destroy(text_idle);
ta_text_destroy(text_selected);
-
return ta_false;
}
@@ -65,6 +79,7 @@ ta_bool ta_button_lists_add(ta_button_lists *list, const char *label, ta_button_
button->text_selected = text_selected;
button->text_width = ta_text_width(text_idle);
button->text_height = ta_text_height(text_idle);
+
list->size++;
return ta_true;
@@ -134,5 +149,9 @@ void ta_button_lists_destroy(ta_button_lists *list) {
ta_text_destroy(list->buttons[i].text_selected);
}
+ if (list->buttons != TA_NULL) {
+ ta_free(list->buttons);
+ }
+
ta_button_lists_init(list);
}