axmol/tests/fairygui-tests/Source/VirtualListScene.cpp

34 lines
1.2 KiB
C++
Raw Normal View History

2020-08-04 13:15:02 +08:00
#include "VirtualListScene.h"
#include "MailItem.h"
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:17:01 +08:00
_list->itemRenderer = AX_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
}