static UIElement* get_container_and_slot(int x, int y, int* slot) { UIElement* closest_container = NULL; int closest_slot = NULL_SLOT; // get topmost container click // WARNING: doesnt support overlapping containers yet. for (size_t i=0; i<MAX_CONTAINER_TYPES; i++) { UIElement* container = ui_elements[i]; if (container == NULL) continue; if (container->container_id == NULL_CONTAINER) continue; if (!container->point_inside(x,y)) continue; closest_container = container; closest_slot = container->get_slot_at(x,y); } *slot = closest_slot; return closest_container; }