Process hit-testing on resizing borders. Actual size change will be applied in EndTable() - Set table->HoveredColumnBorder with a short delay/timer to reduce visual feedback noise.
| 1173 | // Process hit-testing on resizing borders. Actual size change will be applied in EndTable() |
| 1174 | // - Set table->HoveredColumnBorder with a short delay/timer to reduce visual feedback noise. |
| 1175 | void ImGui::TableUpdateBorders(ImGuiTable* table) |
| 1176 | { |
| 1177 | ImGuiContext& g = *GImGui; |
| 1178 | IM_ASSERT(table->Flags & ImGuiTableFlags_Resizable); |
| 1179 | |
| 1180 | // At this point OuterRect height may be zero or under actual final height, so we rely on temporal coherency and |
| 1181 | // use the final height from last frame. Because this is only affecting _interaction_ with columns, it is not |
| 1182 | // really problematic (whereas the actual visual will be displayed in EndTable() and using the current frame height). |
| 1183 | // Actual columns highlight/render will be performed in EndTable() and not be affected. |
| 1184 | ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1185 | const float hit_half_width = TABLE_RESIZE_SEPARATOR_HALF_THICKNESS; |
| 1186 | const float hit_y1 = table->OuterRect.Min.y; |
| 1187 | const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table_instance->LastOuterHeight); |
| 1188 | const float hit_y2_head = hit_y1 + table_instance->LastFirstRowHeight; |
| 1189 | |
| 1190 | for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1191 | { |
| 1192 | if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193 | continue; |
| 1194 | |
| 1195 | const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1196 | ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1197 | if (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) |
| 1198 | continue; |
| 1199 | |
| 1200 | // ImGuiTableFlags_NoBordersInBodyUntilResize will be honored in TableDrawBorders() |
| 1201 | const float border_y2_hit = (table->Flags & ImGuiTableFlags_NoBordersInBody) ? hit_y2_head : hit_y2_body; |
| 1202 | if ((table->Flags & ImGuiTableFlags_NoBordersInBody) && table->IsUsingHeaders == false) |
| 1203 | continue; |
| 1204 | |
| 1205 | if (!column->IsVisibleX && table->LastResizedColumn != column_n) |
| 1206 | continue; |
| 1207 | |
| 1208 | ImGuiID column_id = TableGetColumnResizeID(table, column_n, table->InstanceCurrent); |
| 1209 | ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, border_y2_hit); |
| 1210 | ItemAdd(hit_rect, column_id, NULL, ImGuiItemFlags_NoNav); |
| 1211 | //GetForegroundDrawList()->AddRect(hit_rect.Min, hit_rect.Max, IM_COL32(255, 0, 0, 100)); |
| 1212 | |
| 1213 | bool hovered = false, held = false; |
| 1214 | bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_NoNavFocus); |
| 1215 | if (pressed && IsMouseDoubleClicked(0)) |
| 1216 | { |
| 1217 | TableSetColumnWidthAutoSingle(table, column_n); |
| 1218 | ClearActiveID(); |
| 1219 | held = hovered = false; |
| 1220 | } |
| 1221 | if (held) |
| 1222 | { |
| 1223 | if (table->LastResizedColumn == -1) |
| 1224 | table->ResizeLockMinContentsX2 = table->RightMostEnabledColumn != -1 ? table->Columns[table->RightMostEnabledColumn].MaxX : -FLT_MAX; |
| 1225 | table->ResizedColumn = (ImGuiTableColumnIdx)column_n; |
| 1226 | table->InstanceInteracted = table->InstanceCurrent; |
| 1227 | } |
| 1228 | if ((hovered && g.HoveredIdTimer > TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER) || held) |
| 1229 | { |
| 1230 | table->HoveredColumnBorder = (ImGuiTableColumnIdx)column_n; |
| 1231 | SetMouseCursor(ImGuiMouseCursor_ResizeEW); |
| 1232 | } |
nothing calls this directly
no test coverage detected