libs/libgui/gui.c
// TODO: This is very recursive and inefficient -> improve!
This is very recursive and inefficient -> improve!
This is very recursive and inefficient - > improve!
static vec2 gui_widget_offset(struct gui_widget *parent, struct gui_widget *child)
{
	if (!parent || !parent->children || !child)
		return vec2(0, 0);
	vec2 offset = vec2(0, 0);
	struct node *iterator = parent->children->head;
	while (iterator) {
		struct gui_widget *w = iterator->data;
		if (w == child) {
			offset = vec2_add(offset, w->pos);
			break;
		}
		struct gui_widget *sub = gui_widget_in_widget(w, child->id);
		if (sub) {
			offset = vec2_add(offset, w->pos);
			gui_widget_offset(w, child);
			break;
		}
		iterator = iterator->next;
	}
	return offset;
}
static vec2 gui_widget_offset ( struct gui_widget * parent , struct gui_widget * child ) { if ( ! parent || ! parent -> children || ! child ) return vec2 ( 0 , 0 ) ; vec2 offset = vec2 ( 0 , 0 ) ; struct node * iterator = parent -> children -> head ; while ( iterator ) { struct gui_widget * w = iterator -> data ; if ( w == child ) { offset = vec2_add ( offset , w -> pos ) ; break ; } struct gui_widget * sub = gui_widget_in_widget ( w , child -> id ) ; if ( sub ) { offset = vec2_add ( offset , w -> pos ) ; gui_widget_offset ( w , child ) ; break ; } iterator = iterator -> next ; } return offset ; }
TODO: This is very recursive and inefficient -> improve!
TODO : This is very recursive and inefficient - > improve!