mirror of https://github.com/axmolengine/axmol.git
tableview touch area fix.
This commit is contained in:
parent
739048e6f2
commit
87935ac436
|
@ -332,7 +332,10 @@ unsigned int CCTableView::_indexFromOffset(CCPoint offset)
|
||||||
offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height;
|
offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height;
|
||||||
}
|
}
|
||||||
index = MAX(0, this->__indexFromOffset(offset));
|
index = MAX(0, this->__indexFromOffset(offset));
|
||||||
index = MIN(index, maxIdx);
|
if (index >maxIdx)
|
||||||
|
{
|
||||||
|
index = CC_INVALID_INDEX;
|
||||||
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
@ -401,6 +404,10 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view)
|
||||||
offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height;
|
offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height;
|
||||||
}
|
}
|
||||||
startIdx = this->_indexFromOffset(offset);
|
startIdx = this->_indexFromOffset(offset);
|
||||||
|
if (startIdx == CC_INVALID_INDEX)
|
||||||
|
{
|
||||||
|
startIdx = uCountOfItems - 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_eVordering == kCCTableViewFillTopDown)
|
if (m_eVordering == kCCTableViewFillTopDown)
|
||||||
{
|
{
|
||||||
|
@ -413,6 +420,10 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view)
|
||||||
offset.x += m_tViewSize.width/this->getContainer()->getScaleX();
|
offset.x += m_tViewSize.width/this->getContainer()->getScaleX();
|
||||||
|
|
||||||
endIdx = this->_indexFromOffset(offset);
|
endIdx = this->_indexFromOffset(offset);
|
||||||
|
if (endIdx == CC_INVALID_INDEX)
|
||||||
|
{
|
||||||
|
endIdx = uCountOfItems - 1;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0 // For Testing.
|
#if 0 // For Testing.
|
||||||
CCObject* pObj;
|
CCObject* pObj;
|
||||||
|
@ -492,7 +503,11 @@ void CCTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pTouchedCell){
|
if (m_pTouchedCell){
|
||||||
if(m_pTableViewDelegate != NULL) {
|
CCRect bb = this->boundingBox();
|
||||||
|
bb.origin = m_pParent->convertToWorldSpace(bb.origin);
|
||||||
|
|
||||||
|
if (bb.containsPoint(pTouch->getLocation()) && m_pTableViewDelegate != NULL)
|
||||||
|
{
|
||||||
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
||||||
m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell);
|
m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell);
|
||||||
}
|
}
|
||||||
|
@ -523,7 +538,14 @@ bool CCTableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
index = this->_indexFromOffset(point);
|
index = this->_indexFromOffset(point);
|
||||||
|
if (index == CC_INVALID_INDEX)
|
||||||
|
{
|
||||||
|
m_pTouchedCell = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_pTouchedCell = this->cellAtIndex(index);
|
m_pTouchedCell = this->cellAtIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_pTouchedCell && m_pTableViewDelegate != NULL) {
|
if (m_pTouchedCell && m_pTableViewDelegate != NULL) {
|
||||||
m_pTableViewDelegate->tableCellHighlight(this, m_pTouchedCell);
|
m_pTableViewDelegate->tableCellHighlight(this, m_pTouchedCell);
|
||||||
|
|
|
@ -30,7 +30,7 @@ bool TableViewTestLayer::init()
|
||||||
this->addChild(tableView);
|
this->addChild(tableView);
|
||||||
tableView->reloadData();
|
tableView->reloadData();
|
||||||
|
|
||||||
tableView = CCTableView::create(this, CCSizeMake(60, 280));
|
tableView = CCTableView::create(this, CCSizeMake(60, 250));
|
||||||
tableView->setDirection(kCCScrollViewDirectionVertical);
|
tableView->setDirection(kCCScrollViewDirectionVertical);
|
||||||
tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120));
|
tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120));
|
||||||
tableView->setDelegate(this);
|
tableView->setDelegate(this);
|
||||||
|
|
Loading…
Reference in New Issue