Exemplo n.º 1
0
void NDUITableLayer::MoveSection(unsigned int sectionIndex, int moveLen)
{
    if (moveLen == 0)
        return;

    NDUISectionTitle* sectionTitle = m_sectionTitles.at(sectionIndex);
    CGRect sectionRect = sectionTitle->GetFrameRect();
    sectionTitle->SetFrameRect(CGRectMake(sectionRect.origin.x, sectionRect.origin.y + moveLen, sectionRect.size.width, sectionRect.size.height));

    NDUIRecttangle* background = m_backgrounds.at(sectionIndex);
    CGRect bkgRect = background->GetFrameRect();
    background->SetFrameRect(CGRectMake(bkgRect.origin.x, bkgRect.origin.y + moveLen, bkgRect.size.width, bkgRect.size.height));

    if (m_scrollBarVisibled)
    {
        NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(sectionIndex);
        CGRect sbRect = scrollBar->GetFrameRect();
        scrollBar->SetFrameRect(CGRectMake(sbRect.origin.x, sbRect.origin.y + moveLen, sbRect.size.width, sbRect.size.height));
    }

    NDSection* section = m_dataSource->Section(sectionIndex);
    for (unsigned int j = 0; j < section->Count(); j++)
    {
        NDUINode* uiNode = section->Cell(j);

        CGRect nodeRect = uiNode->GetFrameRect();
        uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + moveLen, nodeRect.size.width, nodeRect.size.height));
    }
}
Exemplo n.º 2
0
bool NDUITableLayer::TouchMoved(NDTouch* touch)
{
    NDUILayer::TouchMoved(touch);

    if (m_sectionTitleVisibled)
    {
        for (unsigned int i = 0; i < m_sectionTitles.size(); i++)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(i);
            CGRect rect = sectionTitle->GetScreenRect();
            if (CGRectContainsPoint(rect, m_beginTouch))
                return false;
        }
    }

    //this->SetFocusOnCell(m_curSection->GetFocusCellIndex());

    if (m_curSection)
    {
        CGPoint prePos = touch->GetPreviousLocation();
        CGPoint curPos = touch->GetLocation();
        CGFloat subValue = curPos.y - prePos.y;

        if (m_sectionTitles.size() > m_curSectionIndex)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex);
            CGRect sectionTitleRect = sectionTitle->GetFrameRect();

            if (m_curSection->Count() > 0)
            {
                if (subValue > 0)
                {
                    NDUINode* firstCell = m_curSection->Cell(0);
                    if (m_sectionTitleVisibled)
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }
                    else
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y  - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }

                    if (subValue <= 0)
                        return false;
                }
                else
                {
                    NDUINode* lastCell = m_curSection->Cell(m_curSection->Count() - 1);
                    CGFloat sectionBottom = this->GetFrameRect().size.height;
                    if (m_curSectionIndex + 1 < m_dataSource->Count())
                    {
                        NDUISectionTitle* nextSectionTitle = m_sectionTitles.at(m_curSectionIndex + 1);
                        sectionBottom = nextSectionTitle->GetFrameRect().origin.y - m_cellsInterval;
                    }
                    if (lastCell->GetFrameRect().origin.y + lastCell->GetFrameRect().size.height + subValue < sectionBottom)
                    {
                        subValue = sectionBottom - lastCell->GetFrameRect().origin.y - lastCell->GetFrameRect().size.height - m_cellsInterval;
                    }

                    if (subValue >= 0)
                        return false;
                }
            }
        }

        if (m_backgrounds.size() > m_curSectionIndex)
        {
            NDUIRecttangle* cellBackground = m_backgrounds.at(m_curSectionIndex);
            for (unsigned int i = 0; i < m_curSection->Count(); i++)
            {
                NDUINode* uiNode = m_curSection->Cell(i);
                CGRect nodeRect = uiNode->GetFrameRect();
                uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + subValue, nodeRect.size.width, nodeRect.size.height));
                bool bDraw = CGRectIntersectsRect(cellBackground->GetFrameRect(), uiNode->GetFrameRect());
                uiNode->EnableDraw(bDraw);
            }
        }


        if (m_scrollBars.size() > m_curSectionIndex)
        {
            if (m_scrollBarVisibled)
            {
                NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(m_curSectionIndex);
                scrollBar->SetCurrentContentY(scrollBar->GetCurrentContentY() - subValue);
            }
        }

    }

    return true;
}
Exemplo n.º 3
0
void NDUITableLayer::ReflashData()
{
    if (!m_dataSource)
        return;

    m_sectionTitles.clear();
    m_backgrounds.clear();
    m_scrollBars.clear();

    for (unsigned int i = 0; i < m_dataSource->Count(); i++)
    {
        NDSection* section = m_dataSource->Section(i);
        for (unsigned int j = 0; j < section->Count(); j++)
        {
            NDUINode* uiNode = section->Cell(j);
            if (uiNode->GetParent())
            {
                uiNode->RemoveFromParent(false);
            }
        }
    }

    this->RemoveAllChildren(true);

    CGRect thisRect = this->GetFrameRect();
    CGSize winSize = NDDirector::DefaultDirector()->GetWinSize();

    //draw sections
    for (unsigned int i = 0; i < m_dataSource->Count(); i++)
    {
        NDSection* section = m_dataSource->Section(i);

        //draw background
        this->DrawBackground(i);

        //draw scrollbar
        if (m_scrollBarVisibled)
        {
            if (section->Count() > 0)
            {
                NDUIVerticalScrollBar* scrollBar = this->DrawScrollbar(i);
                //scrollBar->SetContentHeight((row - 1) * (section->GetRowHeight() + m_cellsInterval));
                CGRect lastCellRect = this->GetCellRectWithIndex(i, section->Count()-1);
                if (m_sectionTitleVisibled)
                    scrollBar->SetContentHeight(lastCellRect.origin.y + lastCellRect.size.height - (i + 1) * m_sectionTitlesHeight);
                else
                    scrollBar->SetContentHeight(lastCellRect.origin.y + lastCellRect.size.height);
            }
        }

        for (unsigned int j = 0; j < section->Count(); j++)
        {
            NDUINode* uiNode = section->Cell(j);

            //防止uilayer拦截行选择事件
            if (uiNode->IsKindOfClass(RUNTIME_CLASS(NDUILayer)) && !uiNode->IsKindOfClass(RUNTIME_CLASS(NDUITableLayer)))
            {
                NDUILayer* uiLayer = (NDUILayer*)uiNode;
                uiLayer->SetTouchEnabled(false);
            }

            CGRect cellRect = this->GetCellRectWithIndex(i, j);
            bool bDraw = CGRectIntersectsRect(m_backgrounds.at(i)->GetFrameRect(), cellRect) && (i == m_dataSource->Count() - 1);

            //draw cell
            uiNode->SetFrameRect(cellRect);
            uiNode->EnableDraw(bDraw);
            this->AddChild(uiNode);
        }
    }

    if (m_dataSource->Count() > 0)
    {
        m_curSectionIndex = m_dataSource->Count()-1;
        m_curSection = m_dataSource->Section(m_curSectionIndex);

        //draw section titles
        for (unsigned int i = 0; i < m_dataSource->Count(); i++)
        {
            this->DrawSectionTitle(i);
        }
        if (m_dataSource->Count() > 0)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex);
            sectionTitle->OnTouchDown(true);
        }
        this->SetFocusOnCell(m_curSection->GetFocusCellIndex());
    }
    else
    {
        m_curSection = NULL;
    }

}