效果图:

原文地址:http://blog.csdn.net/qqmcy/article/details/38361587
代码下载:http://download.csdn.net/detail/qqmcy/7710567
使用方法:
setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
auto winSize = Director::getInstance()->getWinSize();
auto tableFormLayout = TableFormLayout::create();
tableFormLayout->setSize(Size(winSize.width, winSize.height - 250 * VisibleRect::getImageScaleY()));
tableFormLayout->addTableView(3);
addChild(tableFormLayout);
auto rp_sum_layout = ui::RelativeLayoutParameter::create();
rp_sum_layout->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM);
tableFormLayout->setLayoutParameter(rp_sum_layout);
下面粘贴具体的实现:之后我会将代码传上来
先粘贴下一个工具类这个工具在传代码时没有一起传上去。
VisibleRect.h
#ifndef __VISIBLERECT_H__
#define __VISIBLERECT_H__
#include "cocos2d.h"
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include<unistd.h>
#include<sys/stat.h>
#include<string.h>
#define Blue_Color Color4B(241, 104, 60, 255)//实际是橙色 之前上年累计
#define Green_Color Color4B(42, 214, 42, 255) //实际是绿色 前年累计
#define Red_Color Color4B(29, 139, 209, 255)//实际是蓝色 本年累计
#define purple_weak4 Color4B(93, 114, 123,255) //柔和紫色
#define Blue_Color1 Color4B(42, 214, 42, 255) //实际是绿色 之前上年累计
#define Green_Color1 Color4B(241, 104, 60, 255)//实际是橙色 前年累计
//#define Red_Color Color4B(243, 152, 0, 255)
//#define Green_Color Color4B(143, 195, 31, 255)
//#define Blue_Color Color4B(0, 160, 233, 255)
#define Blue_weak Color3B(89, 203, 222) //柔和蓝色
#define purple_weak Color4B(189, 203, 222,255) //柔和紫色
#define City_Color Color4B(39, 73, 150, 255)
#define HTTP_URLTest "http://10.1.1.99/jsp/mobileData/"
#define HTTP_URL "http://10.1.1.121:7080/MobileData/MobileData/getData?"
#define HTTP_Header "http://10.1.1.121:7080/MobileData/MobileData/"
#include "cocos2d.h"
USING_NS_CC;
class VisibleRect :public Ref
{
public:
static cocos2d::Rect getVisibleRect();
static cocos2d::Vec2 left();
static cocos2d::Vec2 right();
static cocos2d::Vec2 top();
static cocos2d::Vec2 bottom();
static cocos2d::Vec2 center();
static cocos2d::Vec2 leftTop();
static cocos2d::Vec2 rightTop();
static cocos2d::Vec2 leftBottom();
static cocos2d::Vec2 rightBottom();
static float getTitleFont();
static float getLabelFont();
static std::string getcurrTime();
static std::string getcurrMonthTime();
static std::string getTable_update_time(std::string tablename);
static void deleteFile(std::string filename);
static std::vector<std::string> getFilePathAtVec(std::string filePath);
static float getImageScale();
static float getImageScaleY();
static std::vector<std::string> getAuthVec();
static bool getIsVersion();
static bool IsVersionDownload();
static void updateApk();
private:
static void lazyInit();
static cocos2d::Rect s_visibleRect;
};
#endif /* __VISIBLERECT_H__ */
VisibleRect.cpp
#include "VisibleRect.h"
#include "external/json/document.h"
#include <stdio.h>
USING_NS_CC;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <jni.h>
#include "../../cocos2d/cocos/platform/android/jni/JniHelper.h"
#include <android/log.h>
#if 1
#define LOG_TAG "JniHelper"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#else
#define LOGD(...)
#endif
#endif
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
// no lazy init
// Useful if we change the resolution in runtime
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return s_visibleRect;
}
Vec2 VisibleRect::left()
{
lazyInit();
return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vec2 VisibleRect::right()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vec2 VisibleRect::top()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vec2 VisibleRect::bottom()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Vec2 VisibleRect::center()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vec2 VisibleRect::leftTop()
{
lazyInit();
return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vec2 VisibleRect::rightTop()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vec2 VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Vec2 VisibleRect::rightBottom()
{
lazyInit();
return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}
std::string VisibleRect::getcurrTime()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
struct timeval now;
struct tm* time;
gettimeofday(&now, NULL);
time = localtime(&now.tv_sec);
int year = time->tm_year + 1900;
log("year = %d",year);
char date[32] = {0};
sprintf(date, "%d-%02d-%02d",(int)time->tm_year + 1900,(int)time->tm_mon + 1,(int)time->tm_mday);
log("%s",date);
return StringUtils::format("%s",date);
#endif
#if ( CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 )
struct tm* tm;
time_t timep;
time(timep);
tm = localtime(&timep);
char date[32] = {0};
sprintf(date, "%d-%02d-%02d",(int)time->tm_year + 1900,(int)time->tm_mon + 1,(int)time->tm_mday);
log("%s",date);
return StringUtils::format("%s",date);
#endif
}
std::string VisibleRect::getcurrMonthTime()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
struct timeval now;
struct tm* time;
gettimeofday(&now, NULL);
time = localtime(&now.tv_sec);
int year = time->tm_year + 1900;
log("year = %d",year);
char date[32] = {0};
sprintf(date, "%d%02d%02d%02d%02d%02d",(int)time->tm_year + 1900,(int)time->tm_mon + 1,(int)time->tm_mday,time->tm_hour,time->tm_min,time->tm_sec);
log("%s",date);
return StringUtils::format("%s",date);
#endif
#if ( CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 )
struct tm* tm;
time_t timep;
time(timep);
tm = localtime(&timep);
char date[32] = {0};
sprintf(date, "%d-%02d-%02d",(int)time->tm_year + 1900,(int)time->tm_mon + 1,(int)time->tm_mday);
log("%s",date);
return StringUtils::format("%s",date);
#endif
}
float VisibleRect::getTitleFont()
{
auto winSize = Director::getInstance()->getWinSize();
float fontSize_title = 35;
if (winSize.height <= 960.0f) {
fontSize_title = 25;
}else if (winSize.height < 1140.0f && winSize.height > 960.0f)
{
fontSize_title = 30;
}else{
fontSize_title = 40;
}
return fontSize_title;
}
float VisibleRect::getLabelFont()
{
auto winSize = Director::getInstance()->getWinSize();
float fontSize_title = 25;
if (winSize.height < 1000.0f) {
fontSize_title = 20;
}else if (winSize.height < 1140.0f && winSize.height >= 1000.0f)
{
fontSize_title = 25;
}else{
fontSize_title = 30;
}
return fontSize_title;
}
std::string VisibleRect::getTable_update_time(std::string tablename)
{
std::string file_path_update = FileUtils::getInstance()->getWritablePath() + "update.json";
if (!FileUtils::getInstance()->isFileExist(file_path_update))
{
file_path_update = FileUtils::getInstance()->fullPathForFilename("update.json");
}
rapidjson::Document d1 ;
std::string contentStr = FileUtils::getInstance()->getStringFromFile(file_path_update);
d1.Parse<0>(contentStr.c_str());
const rapidjson::Value& v_time = d1["update_time"];
unsigned int num = 0;
const rapidjson::Value& v_time_vec = v_time[num];
const rapidjson::Value& v_time_table = v_time_vec[tablename.c_str()];
if (v_time_table.IsString())
{
return v_time_table.GetString();
}
return "null";
}
void VisibleRect::deleteFile(std::string filename)
{
std::string file_path_update = FileUtils::getInstance()->getWritablePath() + filename;
int res = remove(file_path_update.c_str());
if (!res) {
log("%s 删除文件成功",file_path_update.c_str());
}else{
log("%s 删除文件出错",file_path_update.c_str());
}
}
//获取目录下文件夹内容
std::vector<std::string> VisibleRect::getFilePathAtVec(std::string filePath)
{
std::vector<std::string> path_vec;
DIR *dp;
struct dirent *entry;
struct stat statbuf;
int i=0;
if((dp=opendir(filePath.c_str()))==NULL)
{
fprintf(stderr,"cannot open %s",filePath.c_str());
exit(1);
}
chdir(filePath.c_str());
while((entry=readdir(dp))!=NULL&&i<255)
{
stat(entry->d_name,&statbuf);
if(!S_ISREG(statbuf.st_mode))
continue;
path_vec.push_back(StringUtils::format("%s",entry->d_name));
}
return path_vec;
}
float VisibleRect::getImageScale()
{
lazyInit();
log("%f",s_visibleRect.size.width);
return s_visibleRect.size.width / 1080;
}
float VisibleRect::getImageScaleY()
{
lazyInit();
return s_visibleRect.size.height / 1920;
}
std::vector<std::string> VisibleRect::getAuthVec()
{
auto path_title = FileUtils::getInstance()->getWritablePath() + "role.json" ;
auto contentStr = FileUtils::getInstance()->getStringFromFile(path_title);
rapidjson::Document d1;
std::vector<std::string> role_name;
role_name.push_back("f_mobile_kpi_day");
role_name.push_back("f_mobile_car_mqpfl_org");
role_name.push_back("f_mobile_nocar");
role_name.push_back("f_mobile_per");
role_name.push_back("f_mobile_ea");
role_name.push_back("f_mobile_qd");
std::vector<std::string> auth_vec;
d1.Parse<0>(contentStr.c_str());
if (d1.IsObject())
{
for (int j = 0; j < role_name.size(); j++)
{
const rapidjson::Value &val1 = d1[role_name.at(j).c_str()];
auth_vec.push_back(val1.GetString());
}
}
return auth_vec;
}
#pragma mark - 获取版本是否需要更新 为真需要更新
bool VisibleRect::getIsVersion()
{
auto path_title = FileUtils::getInstance()->getWritablePath() + "version.json";
auto contentStr = FileUtils::getInstance()->getStringFromFile(path_title);
rapidjson::Document d1;
d1.Parse<0>(contentStr.c_str());
auto phone_version = UserDefault::getInstance()->getStringForKey("version");
if (strcmp(d1["version"].GetString(), "1.0") != 0&& strcmp(d1["version"].GetString(), phone_version.c_str()) != 0 )
{
return true;
}
return false;
}
#pragma mark - 获取版本是否需要更新 为真需要更新
bool VisibleRect::IsVersionDownload()
{
auto phone_version = UserDefault::getInstance()->getStringForKey("current_version");
auto download_version = UserDefault::getInstance()->getStringForKey("download_version");
if (strcmp(download_version.c_str(), phone_version.c_str()) != 0 )
{
return true;
}
return false;
}
void VisibleRect::updateApk()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
log("进入更新");
JniMethodInfo minfo;
jobject jobj;
bool b = JniHelper::getStaticMethodInfo(minfo,
"org/cocos2dx/cpp/AppActivity", //类路径
"cppCall_logsth", //静态方法名
"(Ljava/lang/String;)Ljava/lang/Object;"); //括号里的是参数,后面的是返回值。
if (!b) {
LOGD("JniHelper::getMethodInfo error...");
}else
{
std::string key = FileUtils::getInstance()->getWritablePath() + "update_mobile.apk";
jstring jkey = minfo.env->NewStringUTF(key.c_str());
jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID,jkey);
}
b = JniHelper::getMethodInfo(minfo, "org/cocos2dx/cpp/AppActivity", //类路径
"updateversion", //静态方法名
"(Ljava/lang/String;)V"); //括号里的是参数,后面的是返回值。
if (!b) {
LOGD("JniHelper::getMethodInfo error...");
}else
{
std::string key = FileUtils::getInstance()->getWritablePath() + "update_mobile.apk";
// std::string key = FileUtils::getInstance()->fullPathForFilename("update_mobile.apk");
jstring jkey = minfo.env->NewStringUTF(key.c_str());
minfo.env->CallVoidMethod(jobj, minfo.methodID,jkey);
}
#endif
}
TableFormView.h
//
// TableFormView.h
//
//
// Created by 杜甲 on 14-7-31.
//
//
#ifndef ____TableFormView__
#define ____TableFormView__
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
class TableFormView:public Layer
{
public:
CREATE_FUNC(TableFormView);
virtual bool init();
CC_SYNTHESIZE(int, labelWidth, LabelWidth);
CC_SYNTHESIZE(int, labelHeight, LabelHeight);
void initWithSection(int sectionNum,int rowNum,int fontSize);
void initWithData(std::vector<std::string> inData);
int i_addBorderColorFlag; //表格底部外框颜色标志,给表格中label添加外框(分割线)
int i_fontFlag; //设置大的字体,第一列设置为大的字体
int i_colorFlag; //颜色标志
int i_productFlag; //产品线专项显示标志
Size getTableFormSize();
private:
int i_beforerow; //记录是否换行
Vector<Label*> vec_Text;
float getImageScale();
float getImageScaleY();
Size tableFormSize;
};
#endif /* defined(__picc_mobile__TableFormView__) */
TableFormView.cpp
//
// TableFormView.cpp
//
//
// Created by 杜甲 on 14-7-31.
//
//
#include "TableFormView.h"
bool TableFormView::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!Layer::init());
// auto sprite = Sprite::create("HelloWorld.png");
//
//
// addChild(sprite);
// setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
bRet = true;
} while (0);
return bRet;
}
void TableFormView::initWithSection(int sectionNum, int rowNum,int fontSize)
{
if (labelWidth == 0) {
labelWidth = 80 * getImageScale();
}
if (labelHeight == 0) {
labelHeight = 35 * getImageScaleY();
}
for (int j = 0; j < rowNum; j++)
{
for (int i = 0; i < sectionNum; i++)
{
Color4B layer_color;
if (i_colorFlag == 1) //表头着色
{
if (j == 0)
{
layer_color = Color4B(54, 107, 12, 255);
}else
{
layer_color = Color4B(237, 237, 237, 255);
}
}else if (i_colorFlag == 2)
{
layer_color = Color4B(100, 160, 52, 255);
}else{
if (j % 2 == 0)
{
layer_color = Color4B(155, 210, 111, 255);
}else{
layer_color = Color4B(214, 245, 188, 255);
}
}
auto label_layer = LayerColor::create(layer_color, labelWidth, labelHeight);
label_layer->setPosition(Vec2(i * labelWidth, (rowNum -j - 1) * labelHeight));
addChild(label_layer);
auto label = Label::create();
vec_Text.pushBack(label);
label->setColor(Color3B::BLACK);
label->setString(StringUtils::format("%d%d",j,i));
label->setSystemFontSize(fontSize);
label->setPosition(Vec2(label_layer->getContentSize().width / 2, label_layer->getContentSize().height / 2));
label->setAlignment(cocos2d::TextHAlignment::CENTER);
label_layer->addChild(label);
}
}
tableFormSize = Size(labelWidth * sectionNum, labelHeight * rowNum);
}
void TableFormView::initWithData(std::vector<std::string> inData)
{
}
Size TableFormView::getTableFormSize()
{
return tableFormSize;
}
float TableFormView::getImageScale()
{
return Director::getInstance()->getWinSize().width / 1080;
}
float TableFormView::getImageScaleY()
{
return Director::getInstance()->getWinSize().height / 1920;
}
TableFormScrollView.h
//
// TableFormScrollView.h
//
//
// Created by 杜甲 on 14-7-31.
//
//
#ifndef __TableFormScrollView__
#define __TableFormScrollView__
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include "ui/cocosGUI.h"
#include "TableFormView.h"
USING_NS_CC;
typedef enum
{
Header_RightTag = 100,
City_Tag = 101,
City_Name = 102
}ScrollViewTag;
class TableFormScrollView;
class TableFormScrollViewDelegate {
public:
virtual void scrollViewToEdge() = 0;
virtual void scrollViewScrolling() = 0;
};
class TableFormScrollView : public ui::Layout ,public extension::ScrollViewDelegate
{
public:
CREATE_FUNC(TableFormScrollView);
virtual bool init();
CC_SYNTHESIZE(TableFormScrollViewDelegate*, _delegate, Delegate);
CC_SYNTHESIZE_RETAIN(extension::ScrollView*, _headerLeftScrollView, HeaderLeftScrollView);
CC_SYNTHESIZE_RETAIN(extension::ScrollView*, _cityScrollView1, CityScrollView1);
CC_SYNTHESIZE_RETAIN(extension::ScrollView*, _headerRightScrollView2, HeaderRightScrollView2);
CC_SYNTHESIZE_RETAIN(extension::ScrollView*, _cityNameScrollView3, CityNameScrollView3);
CC_SYNTHESIZE_RETAIN(TableFormView*, _ibCityTableView, ibCityTableView);
CC_SYNTHESIZE_RETAIN(TableFormView*, _ibCityNameTableView, ibCityNameTableView);
CC_SYNTHESIZE_RETAIN(TableFormView*, _ibCityHeaderRightTableView, ibCityHeaderRightTableView);
CC_SYNTHESIZE_RETAIN(TableFormView*, _ibCityHeaderLeftTableView, ibCityHeaderLeftTableView);
void setHeaderLeftAttribute(int fontFlag, int colorFlag, int section, int row ,float textWidth,float textHeight);
void setHeaderRightAttribute(int fontFlag,int colorFlag , int section , int row,float textWidth,float textHeight);
void setCityAttribute(int fontFlag,int colorFlag , int section , int row,float textWidth,float textHeight);
void setCityNameAttribute(int fontFlag,int colorFlag , int section , int row,float textWidth,float textHeight);
/*获取滚动视图是否到边界,true为到边界,false为没有*/
bool getEdge();
private:
Size winSize;
virtual void scrollViewDidScroll(extension::ScrollView* view);
/**
* @js NA
* @lua NA
*/
virtual void scrollViewDidZoom(extension::ScrollView* view);
bool isEdge;
};
#endif /* defined(__picc_mobile__TableFormScrollView__) */
TableFormLayout.h
//
// TableFormLayout.h
//
//
// Created by 杜甲 on 14-8-3.
//
//
#ifndef __TableFormLayout__
#define __TableFormLayout__
#include "cocos2d.h"
#include "ui/cocosGUI.h"
#include "TableFormScrollView.h"
USING_NS_CC;
class TableFormLayout: public ui::Layout , public TableFormScrollViewDelegate
{
public:
CREATE_FUNC(TableFormLayout);
virtual bool init();
float click_num;
double beforeTouchTime; //上次触摸时间
virtual void scrollViewToEdge();
virtual void scrollViewScrolling();
void addTableView(int num);
private:
bool isEdge;
Vec2 beforePoint;
Vec2 firstPoint;
int index;
};
#endif /* defined(__picc_mobile__TableFormLayout__) */
TableFormLayout.cpp
//
// TableFormLayout.cpp
//
//
// Created by 杜甲 on 14-8-3.
//
//
#include "TableFormLayout.h"
#include "../Tools/widget/VisibleRect.h"
bool TableFormLayout::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!ui::Layout::init());
// setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
index = 0;
bRet = true;
} while (0);
return bRet;
}
void TableFormLayout::addTableView(int num)
{
auto sum_layout = ui::Layout::create();
sum_layout->setLayoutType(cocos2d::ui::Layout::Type::RELATIVE);
sum_layout->setSize(Size(getSize().width * num, getSize().height));
// sum_layout->setPosition(Vec2(0, getSize().height / 2));
addChild(sum_layout);
// auto rp_sum_layout = ui::RelativeLayoutParameter::create();
// rp_sum_layout->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
// sum_layout->setLayoutParameter(rp_sum_layout);
for (int i = 0; i < num; i++)
{
auto tableForm = TableFormScrollView::create();
tableForm->setPosition(Vec2(getSize().width * i, 0));
if (i != 0) {
tableForm->setPosition(Vec2(getSize().width , 0));
}
tableForm->setDelegate(this);
tableForm->setSize(getSize());
tableForm->setHeaderLeftAttribute(1, 1, 2, 2, 90, 90);
tableForm->setHeaderRightAttribute(1, 1, 19, 2, 90, 90);
tableForm->setCityNameAttribute(1, 1, 2, 7, 90, 90);
tableForm->setCityAttribute(1, 1, 19, 7, 90, 90);
sum_layout->addChild(tableForm);
auto rp_tableForm = ui::RelativeLayoutParameter::create();
if (i == 0)
{
rp_tableForm->setRelativeName(StringUtils::format("tableForm%d",i));
rp_tableForm->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM);
}else{
rp_tableForm->setRelativeName(StringUtils::format("tableForm%d",i));
rp_tableForm->setRelativeToWidgetName(StringUtils::format("tableForm%d",i - 1));
rp_tableForm->setAlign(cocos2d::ui::RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER);
}
tableForm->setLayoutParameter(rp_tableForm);
}
auto sprite = Sprite::create("HelloWorld.png");
addChild(sprite);
isEdge = false;
beforeTouchTime = 0;
Size layout_size = getSize();
log("%f",layout_size.width);
auto listener1 = EventListenerTouchOneByOne::create();
listener1->setSwallowTouches(true);
listener1->onTouchBegan = [=](Touch* touch, Event* event)
{
log("began");
auto target = event->getCurrentTarget();
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
log("%f,%f",touch->getLocation().x,touch->getLocation().y);
beforePoint = touch->getLocation();
firstPoint = touch->getLocation();
// if ((atof(VisibleRect::getcurrMonthTime().c_str()) - beforeTouchTime < 1 ))
// {
//
// tableForm->runAction(MoveTo::create(1.0f, Vec2(-Director::getInstance()->getWinSize().width, tableForm->getPosition().y)));
//
//
// }
beforeTouchTime = atof(VisibleRect::getcurrMonthTime().c_str());
if (isEdge) {
return true;
}else{
return false;
}
};
listener1->onTouchMoved = [=](Touch* touch, Event* event)
{
float offset = beforePoint.x - touch->getLocation().x ;
sum_layout->setPosition(Vec2(sum_layout->getPosition().x - offset, sum_layout->getPosition().y));
beforePoint = touch->getLocation();
};
listener1->onTouchEnded = [ = ](Touch* touch, Event* event)
{
log("%f",layout_size.width);
if (firstPoint.x - beforePoint.x > getSize().width/3)
{
index += (num + 1) % num;
if (index >= num - 1) {
index = num - 1;
}
sum_layout->runAction(MoveTo::create(0.5f, Vec2(-layout_size.width * index, sum_layout->getPosition().y)));
}else if (firstPoint.x - beforePoint.x < -getSize().width/3)
{
index -= (num - 1) % num;
if (index <= 0)
{
index = 0;
}
sum_layout->runAction(MoveTo::create(0.5f, Vec2(-layout_size.width * index, sum_layout->getPosition().y)));
}else
{
sum_layout->runAction(MoveTo::create(0.5f, Vec2(-layout_size.width * index, sum_layout->getPosition().y)));
}
isEdge = false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);
}
void TableFormLayout::scrollViewToEdge()
{
isEdge = true;
}
void TableFormLayout::scrollViewScrolling()
{
isEdge = false;
}
|