1. ListView demo compeleted.

2. Optimized ListViewReader format.
This commit is contained in:
yusheng.lu 2014-12-08 19:00:12 +08:00
parent 2f456a5668
commit 7426a32d9f
7 changed files with 98 additions and 42 deletions

View File

@ -89,8 +89,8 @@ namespace cocostudio
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
std::string path = "";
std::string plistFile = "";
std::string path;
std::string plistFile;
int resourceType = 0;
bool clipEnabled = false;
@ -107,12 +107,12 @@ namespace cocostudio
int direction = 0;
bool bounceEnabled = false;
int itemMargin = 0;
std::string directionType = "";
std::string horizontalType = "";
std::string verticalType = "";
std::string directionType;
std::string horizontalType;
std::string verticalType;
// attributes
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
auto attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
@ -185,7 +185,7 @@ namespace cocostudio
if (name == "InnerNodeSize")
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
name = attribute->Name();
@ -205,7 +205,7 @@ namespace cocostudio
}
else if (name == "Size" && backGroundScale9Enabled)
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
@ -226,7 +226,7 @@ namespace cocostudio
}
else if (name == "SingleColor")
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
@ -251,7 +251,7 @@ namespace cocostudio
}
else if (name == "EndColor")
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
@ -276,7 +276,7 @@ namespace cocostudio
}
else if (name == "FirstColor")
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
@ -301,7 +301,7 @@ namespace cocostudio
}
else if (name == "ColorVector")
{
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
name = attribute->Name();
@ -321,10 +321,10 @@ namespace cocostudio
}
else if (name == "FileData")
{
std::string texture = "";
std::string texturePng = "";
std::string texture;
std::string texturePng;
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
auto attribute = child->FirstAttribute();
while (attribute)
{
@ -457,15 +457,9 @@ namespace cocostudio
auto f_innerSize = options->innerSize();
Size innerSize(f_innerSize->width(), f_innerSize->height());
listView->setInnerContainerSize(innerSize);
// int direction = options->direction();
// listView->setDirection((ScrollView::Direction)direction);
bool bounceEnabled = options->bounceEnabled();
listView->setBounceEnabled(bounceEnabled);
// int gravityValue = options->gravity();
// ListView::Gravity gravity = (ListView::Gravity)gravityValue;
// listView->setGravity(gravity);
std::string directionType = options->directionType()->c_str();
if (directionType == "")
{

View File

@ -118,6 +118,7 @@ bool AppDelegate::applicationDidFinishLaunching()
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UISlider");
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UITextField");
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIWidgetAddNode");
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIListView/New");
searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest");
searchPaths.push_back("hd/ActionTimeline");
@ -156,9 +157,9 @@ bool AppDelegate::applicationDidFinishLaunching()
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UISlider");
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UITextField");
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIWidgetAddNode");
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIListView/New");
searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest");
searchPaths.push_back("ActionTimeline");
}

View File

@ -207,7 +207,6 @@ g_guisTests[] =
Director::getInstance()->replaceScene(pScene);
}
},
/*
{
"gui ListView Editor Test",
[](Ref* sender)
@ -220,7 +219,6 @@ g_guisTests[] =
Director::getInstance()->replaceScene(pScene);
}
},
*/
/*
{
"gui GridViewTest",

View File

@ -124,14 +124,19 @@ bool UIListViewTest_Vertical_Editor::init()
{
if (UIScene_Editor::init())
{
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView/Vertical/windows_ui_listview_editor_1.json"));
Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/New/crossplatform_UIListView_Editor_Vertical.csb");
Node* child = node->getChildByTag(5);
child->removeFromParent();
_layout = dynamic_cast<Layout*>(child);
_touchGroup->addChild(_layout);
this->configureGUIScene();
Menu* menu = static_cast<Menu*>(getChildByTag(1));
MenuItemToggle* menuItemToggle = static_cast<MenuItemToggle*>(menu->getChildByTag(1));
MenuItem* selectedItem = menuItemToggle->getSelectedItem();
menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f));
auto listView1 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView1"));
auto listView2 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView2"));
auto listView3 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView3"));
setupListView(listView1);
setupListView(listView2);
setupListView(listView3);
return true;
}
@ -139,6 +144,60 @@ bool UIListViewTest_Vertical_Editor::init()
return false;
}
void UIListViewTest_Vertical_Editor::setupListView(ListView* listView)
{
float scale = 0.5f;
float itemMargin = listView->getItemsMargin();
auto item0 = Text::create();
item0->setString(String::createWithFormat("Item margin: %d", static_cast<int>(itemMargin))->getCString());
listView->addChild(item0);
auto item1 = Layout::create();
auto checkbox = CheckBox::create("selected01.png", "selected01.png", "selected02.png", "selected01.png", "selected01.png");
checkbox->setPosition(Vec2(checkbox->getCustomSize().width / 2, checkbox->getCustomSize().height / 2));
item1->addChild(checkbox);
auto checkboxText = Text::create();
checkboxText->setString("CheckBox");
checkboxText->setFontSize(checkbox->getCustomSize().width * .8f);
checkboxText->setPosition(Vec2(checkbox->getCustomSize().width + checkboxText->getCustomSize().width / 2, checkbox->getCustomSize().height / 2));
item1->addChild(checkboxText);
float item1Width = scale * (checkbox->getCustomSize().width + checkboxText->getCustomSize().width);
float item1Height = scale * checkbox->getCustomSize().height;
item1->setContentSize(Size(item1Width, item1Height));
item1->setScale(scale);
listView->addChild(item1);
auto item2 = Text::create();
item2->setString("Text2");
item2->setFontSize(checkbox->getCustomSize().width * .4f);
item2->setTextColor(Color4B(0, 255, 0, 255));
listView->addChild(item2);
auto item3 = Layout::create();
auto imageview0 = ImageView::create("image.png");
auto imageview1 = ImageView::create("image.png");
imageview1->setPositionX(imageview1->getCustomSize().width * 2);
imageview0->setAnchorPoint(Vec2(0, 0));
imageview1->setAnchorPoint(Vec2(0, 0));
item3->setContentSize(Size(imageview0->getCustomSize().width * 3 * scale, imageview0->getCustomSize().height * scale));
item3->addChild(imageview0);
item3->addChild(imageview1);
item3->setScale(scale);
listView->addChild(item3);
auto item4 = Button::create("button.png", "button_p.png");
item4->setTitleText("Button");
listView->pushBackCustomItem(item4);
auto itemModel = Text::create();
itemModel->setTextColor(Color4B(255, 0, 0, 125));
itemModel->setString("List item model");
listView->setItemModel(itemModel);
listView->pushBackDefaultItem();
listView->pushBackDefaultItem();
}
// UIListViewTest_Horizontal_Editor
@ -256,16 +315,20 @@ bool UIListViewTest_Horizontal_Editor::init()
{
if (UIScene_Editor::init())
{
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView/Horizontal/windows_ui_listview_horizontal_editor_1.json"));
Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/New/crossplatform_UIListView_Editor_Horizontal.csb");
Node* child = node->getChildByTag(5);
child->removeFromParent();
_layout = dynamic_cast<Layout*>(child);
_touchGroup->addChild(_layout);
this->configureGUIScene();
Menu* menu = static_cast<Menu*>(getChildByTag(1));
MenuItemToggle* menuItemToggle = static_cast<MenuItemToggle*>(menu->getChildByTag(1));
MenuItem* selectedItem = menuItemToggle->getSelectedItem();
menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f));
auto listView1 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView1"));
auto listView2 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView2"));
auto listView3 = dynamic_cast<ListView*>(Helper::seekWidgetByName(_layout, "ListView3"));
UIListViewTest_Vertical_Editor::setupListView(listView1);
UIListViewTest_Vertical_Editor::setupListView(listView2);
UIListViewTest_Vertical_Editor::setupListView(listView3);
return true;
}

View File

@ -30,6 +30,7 @@
class UIListViewTest_Vertical_Editor : public UIScene_Editor
{
public:
static void setupListView(ListView* listView);
UIListViewTest_Vertical_Editor();
~UIListViewTest_Vertical_Editor();
bool init();

View File

@ -41,9 +41,9 @@ static const char* s_testArray[] =
"UILayoutTest_Layout_Linear_Horizontal_Editor",
"UILayoutTest_Layout_Relative_Align_Parent_Editor",
"UILayoutTest_Layout_Relative_Location_Editor",
*/
"UIListViewTest_Vertical_Editor",
"UIListViewTest_Horizontal_Editor",
*/
"UIPageViewTest_Editor",
"UIScrollViewTest_Vertical_Editor",
"UIScrollViewTest_Horizontal_Editor",
@ -161,13 +161,12 @@ Scene* UISceneManager_Editor::currentUIScene()
case kUILayoutTest_Layout_Relative_Location_Editor:
return UILayoutTest_Layout_Relative_Location_Editor::sceneWithTitle(s_testArray[_currentUISceneId]);
*/
case kUIListViewTest_Vertical_Editor:
return UIListViewTest_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIListViewTest_Horizontal_Editor:
return UIListViewTest_Horizontal_Editor::sceneWithTitle(s_testArray[_currentUISceneId]);
*/
case kUIPageViewTest_Editor:
return UIPageViewTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]);

View File

@ -51,9 +51,9 @@ enum
kUILayoutTest_Layout_Linear_Horizontal_Editor,
kUILayoutTest_Layout_Relative_Align_Parent_Editor,
kUILayoutTest_Layout_Relative_Location_Editor,
*/
kUIListViewTest_Vertical_Editor,
kUIListViewTest_Horizontal_Editor,
*/
kUIPageViewTest_Editor,
kUIScrollViewTest_Vertical_Editor,
kUIScrollViewTest_Horizontal_Editor,