void UIListViewEx::copyClonedWidgetChildren(UIWidget* model) { ccArray* arrayItems = dynamic_cast<UIListViewEx*>(model)->getItems()->data; int length = arrayItems->num; for (int i=0; i<length; i++) { UIWidget* item = (UIWidget*)(arrayItems->arr[i]); pushBackCustomItem(item->clone()); } }
void ListView::copyClonedWidgetChildren(Widget* model) { ccArray* arrayModelItems = static_cast<ListView*>(model)->getItems()->data; int length = arrayModelItems->num; for (int i=0; i<length; i++) { Widget* item = static_cast<Widget*>(arrayModelItems->arr[i]); pushBackCustomItem(item->clone()); } }
void Sensors::showSensorByQueue(float dt) { auto p_panel = this->_p_contents->getChildByName<ui::Layout *>("panelBackground"); auto p_list_view = p_panel->getChildByName<ui::ListView *>("listSensors"); static int count_down = 5; if (this->m_sensor_main_ids.empty()) { // Unschedule unschedule(schedule_selector(Sensors::showSensorByQueue)); p_list_view->jumpToTop(); this->detachWaitAnimationLocal(); return; } int m_sensor_main_id = this->m_sensor_main_ids.front(); this->m_sensor_main_ids.pop_front(); count_down--; CCLOG("Sensors::showSensorByQueue m_sensor_main_id %d", m_sensor_main_id); lib::object::LocationItem item = lib::network::DataStoreSingleton::getInstance()->getLocationItem( m_sensor_main_id); auto favorite = lib::Util::getFavorite(item.m_sensor_main_id); if (this->task_id == Task_Id_Favorite && !favorite) { return; } auto p_record = CSLoader::getInstance()->createNode("res/sensors_record.csb"); this->setMesurementData(p_record, item); p_record->setTag(Tag_Id_Sensor_Record); if (count_down > 0) { // set animation p_record->setCascadeOpacityEnabled(true); p_record->setOpacity(0); auto action = FadeIn::create(0.3f); p_record->runAction(action); } auto widget = ui::Widget::create(); widget->addChild(p_record); widget->setTag(item.m_sensor_main_id); widget->setContentSize(p_record->getContentSize()); p_list_view->pushBackCustomItem(widget); widget->setTouchEnabled(true); // enable listview touch event } }
bool CScrollMenu::init(Size size) { if (!ListView::init()) { return false; } setSize(size); setBounceEnabled(true); m_pRadioMenu = RadioButtonSet::create(); m_sRadioSize = Size(0,size.height); m_pRadioMenu->setContentSize(m_sRadioSize); m_pRadioMenu->setAnchorPoint(Point::ZERO); m_pRadioMenu->SetRelayout(true); pushBackCustomItem(m_pRadioMenu); addEventListenerScrollView(this,scrollvieweventselector(CScrollMenu::scrollEvent)); return true; }
void UI::initListView(){ auto lv=ListView::create(); lv->setContentSize(cocos2d::Size(640,480)); lv->setItemsMargin(20);//设置间隔 lv->setDirection(cocos2d::ui::ScrollView::Direction::VERTICAL); for (int i=0; i<50; i++) { auto ub=Button::create(); ub->loadTextureNormal("0.png"); ub->loadTexturePressed("1.png"); ub->loadTextureDisabled("0.png"); ub->setScale9Enabled(true); ub->setContentSize(Size(600,400)); ub->setPressedActionEnabled(true); ub->setZoomScale(0.5f); ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); ub->setTag(i); lv->pushBackCustomItem(ub); } lv->addEventListener(CC_CALLBACK_2(UI::ListViewCall, this)); addChild(lv); }
void Sensors::showSensorList() { // get http response auto http_response_data = lib::network::DataStoreSingleton::getInstance()->getResponseData( lib::network::DataStoreSingleton::Request_Pointcast_Home_e); const char* json = http_response_data.c_str(); // JSON解析 rapidjson::Document document; document.Parse<0>(json); if (document.HasParseError()) { // 解析エラー assert(false); return; } // read list view auto p_panel = this->_p_contents->getChildByName<ui::Layout*>("panelBackground"); auto p_list_view = p_panel->getChildByName<ui::ListView*>("listSensors"); p_list_view->setInnerContainerSize(p_list_view->getContentSize()); p_list_view->setBounceEnabled(true); p_list_view->setTouchEnabled(true); p_list_view->addEventListener( [this](Ref* ref, ui::ListView::EventType eventType) { if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) { auto listView = static_cast<ui::ListView*>(ref); auto selectedIndex = listView->getCurSelectedIndex(); // revert color all record for (auto widget : listView->getItems()) { auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record); p_record->getChildByName<ui::Layout*>("panelRecord") ->setColor(Color3B::WHITE); } // change color selected record auto widget = listView->getItem(selectedIndex); auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record); p_record->getChildByName<ui::Layout*>("panelRecord") ->setColor(Color3B(250, 219, 218)); CCLOG("selected index %ld", selectedIndex); this->showAnalyticsDialog(widget->getTag()); } else { CCLOG("touch list event type %d", eventType); } }); std::map<int, lib::object::LocationItem> m_sensors = lib::network::DataStoreSingleton::getInstance()->getLocationItemAll(); for (auto item : m_sensors) { auto p_record = CSLoader::getInstance()->createNode("res/sensors_record.csb"); this->setMesurementData(p_record, item.second); auto widget = ui::Widget::create(); p_record->setTag(Tag_Id_Sensor_Record); widget->addChild(p_record); widget->setTag(item.second.m_sensor_main_id); widget->setContentSize(p_record->getContentSize()); p_list_view->pushBackCustomItem(widget); widget->setTouchEnabled(true); // enable listview touch event } }
void TableSelect::initTable(Size visibleSize,Vec2 origin){ //layout left auto backgroundLeft = M9Path::create("tab_one.9.png",Size(visibleSize.width*0.2f,visibleSize.height*0.75f)); backgroundLeft->setPosition(origin.x,origin.y+ visibleSize.height/2-backgroundLeft->getContentSize().height/2); this->addChild(backgroundLeft); auto hoatdong = MLabel::create("Hoạt động",32); hoatdong->setPosition(Vec2(origin.x+backgroundLeft->getContentSize().width/2-hoatdong->getContentSize().width/2, backgroundLeft->getPosition().y+backgroundLeft->getContentSize().height -1.8f*hoatdong->getContentSize().height)); this->addChild(hoatdong); Layout* layoutLeft = Layout::create(); layoutLeft->setContentSize(Size(backgroundLeft->getWidth()-30,backgroundLeft->getHeight()*5/6)); layoutLeft->setPosition(Vec2(origin.x+15,origin.y+visibleSize.height*0.125f)); this->addChild(layoutLeft); auto lv1 = ListView::create(); //auto testxxx = MText::create("This is a notification xxxxxx!",15); //lv1->setItemModel(testxxx); for(int i=0;i<20;i++){ auto testxxx = MText::create("This is a notification xxxxxx!,nothing.don't look at me!please!",15); testxxx->ignoreContentAdaptWithSize(false); testxxx->setContentSize(Size(layoutLeft->getContentSize().width,testxxx->getHeight()*2)); lv1->pushBackCustomItem(testxxx); } lv1->setItemsMargin(10); //lv1->setBounceEnabled(true); lv1->setGravity(ListView::Gravity::LEFT); lv1->setContentSize(layoutLeft->getContentSize()); //lv1->setPosition(layoutLeft->getPosition()); lv1->setScrollBarEnabled(false); layoutLeft->addChild(lv1); //==========================Layout Right auto backgroundRight = M9Path::create("tab_two.9.png",Size(visibleSize.width*0.8f,visibleSize.height*0.75f)); backgroundRight->setPosition(origin.x+visibleSize.width*0.2f, origin.y+visibleSize.height/2-backgroundRight->getHeight()/2); this->addChild(backgroundRight); auto ban_so = MLabel::create("Bàn số ▿",32); ban_so->setPosition(Vec2(origin.x-ban_so->getWidth()/2 + visibleSize.width*0.32f, hoatdong->getPosition().y)); this->addChild(ban_so); auto tien_cuoc = MLabel::create("Tiền cược ▿",32); tien_cuoc->setPosition(Vec2(origin.x-tien_cuoc->getWidth()/2 + visibleSize.width*0.55f, hoatdong->getPosition().y)); this->addChild(tien_cuoc); auto trang_thai = MLabel::create("Trạng thái ▿",32); trang_thai->setPosition(Vec2(origin.x-trang_thai->getWidth()/2 + visibleSize.width*0.76f, hoatdong->getPosition().y)); this->addChild(trang_thai); auto khoa = MLabel::create("Khóa ▿",32); khoa->setPosition(Vec2(origin.x-khoa->getWidth()/2 + visibleSize.width*0.945f, hoatdong->getPosition().y)); this->addChild(khoa); Layout* layoutRight = Layout::create(); layoutRight->setContentSize(Size(backgroundRight->getWidth()-30,backgroundRight->getHeight()*5/6)); layoutRight->setPosition(Vec2(origin.x+15+backgroundLeft->getWidth(),origin.y+visibleSize.height*0.125f)); this->addChild(layoutRight); auto lvRight = ListView::create(); //auto model = Button::create(); //lvRight->setItemModel(model); for (int i=0; i<20; i++) { auto bkg_item = Sprite::create("bgr_list_item.png"); auto number_table = MLabel::create("6",30); auto money = MLabel::create("1000 xu",30); auto status = MLabel::create("xxx",30); auto lock = Sprite::create("ic_lock.png"); auto custom_item = Layout::create(); custom_item->setContentSize(Size(layoutRight->getContentSize().width,lock->getContentSize().height*2)); bkg_item->setScale(layoutRight->getContentSize().width/bkg_item->getContentSize().width, lock->getContentSize().height*2/bkg_item->getContentSize().height); bkg_item->setPosition(layoutRight->getContentSize().width/2,custom_item->getContentSize().height/2); number_table->setPosition(Vec2(number_table->getContentSize().width/2+backgroundRight->getContentSize().width/8, custom_item->getContentSize().height / 2.0f-number_table->getContentSize().height/2)); money->setPosition(Vec2(money->getContentSize().width/2+backgroundRight->getContentSize().width*2.5f/8, custom_item->getContentSize().height / 2.0f-money->getContentSize().height/2)); status->setPosition(Vec2(status->getContentSize().width/2+backgroundRight->getContentSize().width*5/8, custom_item->getContentSize().height / 2.0f-status->getContentSize().height/2)); lock->setPosition(Vec2(lock->getContentSize().width/2+backgroundRight->getContentSize().width*7/8, custom_item->getContentSize().height / 2.0f)); custom_item->addChild(bkg_item); custom_item->addChild(number_table); custom_item->addChild(money); custom_item->addChild(status); custom_item->addChild(lock); lvRight->pushBackCustomItem(custom_item); } lvRight->setItemsMargin(15); lvRight->setBounceEnabled(true); lvRight->setGravity(ListView::Gravity::LEFT); lvRight->setContentSize(layoutRight->getContentSize()); layoutRight->addChild(lvRight); //====== }