2020-08-04 13:15:02 +08:00
|
|
|
#include "VirtualListScene.h"
|
|
|
|
#include "MailItem.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2020-08-04 13:15:02 +08:00
|
|
|
|
|
|
|
void VirtualListScene::continueInit()
|
|
|
|
{
|
|
|
|
UIPackage::addPackage("UI/VirtualList");
|
|
|
|
UIConfig::horizontalScrollBar = "";
|
|
|
|
UIConfig::verticalScrollBar = "";
|
|
|
|
UIObjectFactory::setPackageItemExtension("ui://VirtualList/mailItem", []() {return MailItem::create(); });
|
|
|
|
|
|
|
|
_view = UIPackage::createObject("VirtualList", "Main")->as<GComponent>();
|
|
|
|
_groot->addChild(_view);
|
|
|
|
|
|
|
|
_view->getChild("n6")->addClickListener([this](EventContext*) { _list->addSelection(500, true); });
|
|
|
|
_view->getChild("n7")->addClickListener([this](EventContext*) { _list->getScrollPane()->scrollTop(); });
|
|
|
|
_view->getChild("n8")->addClickListener([this](EventContext*) { _list->getScrollPane()->scrollBottom(); });
|
|
|
|
|
|
|
|
_list = _view->getChild("mailList")->as<GList>();
|
2022-07-15 19:44:31 +08:00
|
|
|
_list->itemRenderer = CC_CALLBACK_2(VirtualListScene::renderListItem, this);
|
2020-08-04 13:15:02 +08:00
|
|
|
_list->setVirtual();
|
|
|
|
_list->setNumItems(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualListScene::renderListItem(int index, GObject* obj)
|
|
|
|
{
|
|
|
|
MailItem* item = obj->as<MailItem>();
|
|
|
|
item->setFetched(index % 3 == 0);
|
|
|
|
item->setRead(index % 2 == 0);
|
|
|
|
item->setTime("5 Nov 2015 16:24:33");
|
2020-08-06 19:58:24 +08:00
|
|
|
item->setText(std::to_string(index) + " Mail title here");
|
2020-08-04 13:15:02 +08:00
|
|
|
}
|