fix scrolllayer improper culling

This commit is contained in:
dankmeme01 2025-03-02 15:45:15 +01:00
parent ecdd3b290f
commit b136e3b0e6

View file

@ -18,9 +18,18 @@ void GenericContentLayer::setPosition(CCPoint const& pos) {
// all be TableViewCells
CCLayerColor::setPosition(pos);
CCSize scrollLayerSize{};
if (auto parent = this->getParent()) {
scrollLayerSize = parent->getContentSize();
}
for (auto child : CCArrayExt<CCNode*>(m_pChildren)) {
auto y = this->getPositionY() + child->getPositionY();
child->setVisible(!((m_obContentSize.height < y) || (y < -child->getContentSize().height)));
float childY = this->getPositionY() + child->getPositionY();
float childTop = childY + (1.f - child->getAnchorPoint().y) * child->getScaledContentSize().height;
float childBottom = childY - child->getAnchorPoint().y * child->getScaledContentSize().height;
bool visible = childTop > 0 && childBottom < scrollLayerSize.height;
child->setVisible(visible);
}
}