| 460 | } |
| 461 | } |
| 462 | |
| 463 | void RuntimeManager::onColorPaletteUpdated(const ColorPalette& /*colorPalette*/) { |
| 464 | FlatSet<AttributeId> attributesToReapply; |
| 465 | |
| 466 | // Clear the cache for all color attributes |
| 467 | for (const auto& viewManagerContext : _viewManagerContexts) { |
| 468 | for (const auto& it : viewManagerContext->getAttributesManager().getAllBoundAttributes()) { |
| 469 | for (const auto& handlerIt : it.second->getHandlers()) { |
| 470 | auto* handler = it.second->getAttributeHandlerForId(handlerIt.first); |
| 471 | |
| 472 | if (handler->shouldReevaluateOnColorPaletteChange()) { |
| 473 | handler->clearPreprocessorCache(); |
| 474 | attributesToReapply.insert(handlerIt.first); |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // Reapply all the color attributes |
| 481 | auto allAttributes = makeShared<std::vector<AttributeId>>(); |
| 482 | allAttributes->insert(allAttributes->end(), attributesToReapply.begin(), attributesToReapply.end()); |
| 483 | |
| 484 | #if VALDI_DEBUG_TREE_UPDATES |
| 485 | std::string applyTrigger = "apply_attributes"; |
| 486 | if (!_viewManagerContexts.empty() && !attributesToReapply.empty()) { |
| 487 | const auto& attributeIds = _viewManagerContexts.front()->getAttributesManager().getAttributeIds(); |
| 488 | std::string names; |
| 489 | size_t count = 0; |
| 490 | constexpr size_t kMaxNames = 12; |
| 491 | constexpr size_t kMaxLen = 80; |
| 492 | for (AttributeId id : attributesToReapply) { |
| 493 | if (count >= kMaxNames || (count > 0 && names.size() >= kMaxLen)) { |
| 494 | names += ",..."; |
| 495 | break; |
| 496 | } |
| 497 | if (count != 0) { |
| 498 | names += ","; |
| 499 | } |
| 500 | names += attributeIds.getNameForId(id).slowToString(); |
| 501 | ++count; |
| 502 | } |
| 503 | if (!names.empty()) { |
| 504 | applyTrigger += ":"; |
| 505 | applyTrigger += names; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | for (const auto& runtime : getAllRuntimes()) { |
| 510 | for (const auto& tree : runtime->getViewNodeTreeManager().getAllRootViewNodeTrees()) { |
| 511 | tree->scheduleExclusiveUpdate( |
| 512 | [treePtr = tree.get(), allAttributes]() { |
| 513 | auto rootViewNode = treePtr->getRootViewNode(); |
| 514 | if (rootViewNode != nullptr) { |
| 515 | rootViewNode->reapplyAttributesRecursive( |
| 516 | treePtr->getCurrentViewTransactionScope(), *allAttributes, false); |
| 517 | } |
| 518 | }, |
| 519 | Valdi::DispatchFunction(), |
no test coverage detected