| 1093 | } |
| 1094 | |
| 1095 | std::optional<int> dropdownIndexFromPoint(Ui::Window* window, int x, int y) |
| 1096 | { |
| 1097 | // Check whether x and y are over a list item |
| 1098 | int left = x - window->x; |
| 1099 | if (left < 0) |
| 1100 | { |
| 1101 | return std::nullopt; |
| 1102 | } |
| 1103 | if (left >= window->width) |
| 1104 | { |
| 1105 | return std::nullopt; |
| 1106 | } |
| 1107 | |
| 1108 | // 2px of padding on the top of the list? |
| 1109 | int top = y - window->y - 2; |
| 1110 | if (top < 0) |
| 1111 | { |
| 1112 | return std::nullopt; |
| 1113 | } |
| 1114 | |
| 1115 | unsigned int itemY = top / _dropdownItemHeight; |
| 1116 | if (itemY >= _dropdownItemCount) |
| 1117 | { |
| 1118 | return std::nullopt; |
| 1119 | } |
| 1120 | |
| 1121 | left -= 2; |
| 1122 | if (left < 0) |
| 1123 | { |
| 1124 | return std::nullopt; |
| 1125 | } |
| 1126 | |
| 1127 | unsigned int itemX = left / _dropdownItemWidth; |
| 1128 | if (itemX >= _dropdownColumnCount) |
| 1129 | { |
| 1130 | return std::nullopt; |
| 1131 | } |
| 1132 | if (itemY >= _dropdownRowCount) |
| 1133 | { |
| 1134 | return std::nullopt; |
| 1135 | } |
| 1136 | |
| 1137 | int item = itemY * _dropdownColumnCount + itemX; |
| 1138 | if (item >= _dropdownItemCount) |
| 1139 | { |
| 1140 | return std::nullopt; |
| 1141 | } |
| 1142 | |
| 1143 | if (item < 32 && (_dropdownDisabledItems & (1ULL << item)) != 0) |
| 1144 | { |
| 1145 | return std::nullopt; |
| 1146 | } |
| 1147 | |
| 1148 | if (_dropdownItemFormats[item] == 0) |
| 1149 | { |
| 1150 | return std::nullopt; |
| 1151 | } |
| 1152 |
no outgoing calls
no test coverage detected