- ret = floor(pos);
- for (i = 0; i < category_draw_count; ++i) {
- float first = i + category_item[i];
- float firstPos = i * me.categoriesHeight + category_item[i];
- if (pos >= firstPos)
- ret = first;
- if (pos >= firstPos + me.categoriesHeight)
- ret = first + 1 + floor(pos - firstPos - me.categoriesHeight);
+ // TODO when item+category merging is done, manually expand these macros
+#define ITEM_STARTPOS_SINGLE(itemidx, itempos) \
+ if (pos >= itempos) \
+ return itemidx
+#define ITEM_STARTPOS_MULTI(itemidx, itempos) \
+ if (pos >= itempos) \
+ return itemidx + floor(pos - (itempos))
+ float i;
+ for (i = category_draw_count - 1; i >= 0; --i) {
+ ITEM_STARTPOS_MULTI((i + 1) + category_item[i], (i + 1) * me.categoriesHeight + category_item[i]);
+ ITEM_STARTPOS_SINGLE(i + category_item[i], i * me.categoriesHeight + category_item[i]);