* Move the badge class to the previous position. * @param feature Feature being used. * @param class_badge Class badge. */
| 401 | * @param class_badge Class badge. |
| 402 | */ |
| 403 | static void BadgeClassMovePrevious(GrfSpecFeature feature, Badge &class_badge) |
| 404 | { |
| 405 | GUIBadgeClasses gui_classes(feature); |
| 406 | if (gui_classes.GetClasses().empty()) return; |
| 407 | |
| 408 | auto config = GetBadgeClassConfiguration(feature); |
| 409 | auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label); |
| 410 | if (it == std::end(config)) return; |
| 411 | |
| 412 | auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index); |
| 413 | if (pos_cur == std::begin(gui_classes.GetClasses())) { |
| 414 | if (it->column > 0) --it->column; |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | auto pos_prev = std::ranges::find(config, std::prev(pos_cur)->label, &BadgeClassConfigItem::label); |
| 419 | if (it->column > pos_prev->column) { |
| 420 | --it->column; |
| 421 | } else { |
| 422 | /* Rotate elements right so that it is placed before pos_prev, maintaining order of non-visible elements. */ |
| 423 | std::rotate(pos_prev, it, std::next(it)); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Move the badge class to the next position. |
no test coverage detected