symbian自定义列表,支持拖拽功能,有阻尼效果
void CListContainer::MoveUp(TUint aDistance)
{
TPoint tl(0,0);
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
TInt count = iItemArray.Count();
TBool meetVisible = EFalse;//遇见可视的列表项
for (TInt i=0; i < count; i++)
{
CListItem* item = iItemArray[i];
if (meetVisible)
{
item->SetPosition(tl);
if (tl.iY > cavasHeight)
{
item->MakeVisible(EFalse);
tl.iY += item->Size().iHeight;
}
else if (tl.iY > 0)
{
item->MakeVisible(ETrue);
tl.iY += item->Size().iHeight;
}
else
{
tl.iY += item->Size().iHeight;
if (tl.iY > 0)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
else
{
if (item->IsVisible())
{
meetVisible = ETrue;
tl = item->Position();
tl.iY -= aDistance;
item->SetPosition(tl);
tl.iY += item->Size().iHeight;
if (tl.iY < 0)
item->MakeVisible(EFalse);
}
}
}
if (!meetVisible)
{
for (TInt i=0; i < count; i++)
{
CListItem* item = iItemArray[i];
tl = item->Position();
tl.iY -= aDistance;
item->SetPosition(tl);
if (tl.iY > cavasHeight)
{
item->MakeVisible(EFalse);
}
else if (tl.iY > 0)
{
item->MakeVisible(ETrue);
}
else
{
tl.iY += item->Size().iHeight;
if (tl.iY > 0)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
}
}
{
TPoint tl(0,0);
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
TInt count = iItemArray.Count();
TBool meetVisible = EFalse;//遇见可视的列表项
for (TInt i=0; i < count; i++)
{
CListItem* item = iItemArray[i];
if (meetVisible)
{
item->SetPosition(tl);
if (tl.iY > cavasHeight)
{
item->MakeVisible(EFalse);
tl.iY += item->Size().iHeight;
}
else if (tl.iY > 0)
{
item->MakeVisible(ETrue);
tl.iY += item->Size().iHeight;
}
else
{
tl.iY += item->Size().iHeight;
if (tl.iY > 0)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
else
{
if (item->IsVisible())
{
meetVisible = ETrue;
tl = item->Position();
tl.iY -= aDistance;
item->SetPosition(tl);
tl.iY += item->Size().iHeight;
if (tl.iY < 0)
item->MakeVisible(EFalse);
}
}
}
if (!meetVisible)
{
for (TInt i=0; i < count; i++)
{
CListItem* item = iItemArray[i];
tl = item->Position();
tl.iY -= aDistance;
item->SetPosition(tl);
if (tl.iY > cavasHeight)
{
item->MakeVisible(EFalse);
}
else if (tl.iY > 0)
{
item->MakeVisible(ETrue);
}
else
{
tl.iY += item->Size().iHeight;
if (tl.iY > 0)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
}
}
void CListContainer::MoveDown(TUint aDistance)
{
TPoint tl(0,0);
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
TInt count = iItemArray.Count();
TBool meetVisible = EFalse;//遇见可视的列表项
for (TInt i=count-1; i >= 0; i--)
{
CListItem* item = iItemArray[i];
if (meetVisible)
{
if (tl.iY < 0)
{
item->MakeVisible(EFalse);
tl.iY -= item->Size().iHeight;
}
else if (tl.iY < cavasHeight)
{
item->MakeVisible(ETrue);
tl.iY -= item->Size().iHeight;
}
else
{
tl.iY -= item->Size().iHeight;
if (tl.iY < cavasHeight)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
item->SetPosition(tl);
}
else
{
if (item->IsVisible())
{
meetVisible = ETrue;
tl = item->Position();
tl.iY += aDistance;
item->SetPosition(tl);
if (tl.iY > cavasHeight)
item->MakeVisible(EFalse);
}
}
}
if (!meetVisible)
{
for (TInt i=count-1; i >= 0; i--)
{
CListItem* item = iItemArray[i];
tl = item->Position();
tl.iY += aDistance;
item->SetPosition(tl);
if (tl.iY < 0)
{
item->MakeVisible(EFalse);
}
else if (tl.iY < cavasHeight)
{
item->MakeVisible(ETrue);
}
else
{
tl.iY -= item->Size().iHeight;
if (tl.iY < cavasHeight)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
}
}
{
TPoint tl(0,0);
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
TInt count = iItemArray.Count();
TBool meetVisible = EFalse;//遇见可视的列表项
for (TInt i=count-1; i >= 0; i--)
{
CListItem* item = iItemArray[i];
if (meetVisible)
{
if (tl.iY < 0)
{
item->MakeVisible(EFalse);
tl.iY -= item->Size().iHeight;
}
else if (tl.iY < cavasHeight)
{
item->MakeVisible(ETrue);
tl.iY -= item->Size().iHeight;
}
else
{
tl.iY -= item->Size().iHeight;
if (tl.iY < cavasHeight)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
item->SetPosition(tl);
}
else
{
if (item->IsVisible())
{
meetVisible = ETrue;
tl = item->Position();
tl.iY += aDistance;
item->SetPosition(tl);
if (tl.iY > cavasHeight)
item->MakeVisible(EFalse);
}
}
}
if (!meetVisible)
{
for (TInt i=count-1; i >= 0; i--)
{
CListItem* item = iItemArray[i];
tl = item->Position();
tl.iY += aDistance;
item->SetPosition(tl);
if (tl.iY < 0)
{
item->MakeVisible(EFalse);
}
else if (tl.iY < cavasHeight)
{
item->MakeVisible(ETrue);
}
else
{
tl.iY -= item->Size().iHeight;
if (tl.iY < cavasHeight)
item->MakeVisible(ETrue);
else
item->MakeVisible(EFalse);
}
}
}
}
void CListContainer::Damp()
{
#if 1
TInt count = iItemArray.Count();
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
CListItem* first = iItemArray[0];
CListItem* last = iItemArray[count-1];
if (first->Position().iY > 0)
{
//开头需要调整
MoveUp(first->Position().iY);
}
else if (last->Rect().iBr.iY < cavasHeight && first->Position().iY < 0)
{
//尾部需要调整
MoveDown(cavasHeight - last->Rect().iBr.iY);
if (first->Position().iY > 0)
{
MoveUp(first->Position().iY);
}
}
DrawToCavas();
DrawNow();
#endif
}
{
#if 1
TInt count = iItemArray.Count();
TInt cavasHeight = iCavas->SizeInPixels().iHeight;
CListItem* first = iItemArray[0];
CListItem* last = iItemArray[count-1];
if (first->Position().iY > 0)
{
//开头需要调整
MoveUp(first->Position().iY);
}
else if (last->Rect().iBr.iY < cavasHeight && first->Position().iY < 0)
{
//尾部需要调整
MoveDown(cavasHeight - last->Rect().iBr.iY);
if (first->Position().iY > 0)
{
MoveUp(first->Position().iY);
}
}
DrawToCavas();
DrawNow();
#endif
}