mirror of https://github.com/axmolengine/axmol.git
ListViewReader completed and listview callback feature.
This commit is contained in:
parent
51220a200f
commit
2f456a5668
|
@ -1447,8 +1447,10 @@ struct ListViewOptions : private flatbuffers::Table {
|
|||
const FlatSize *innerSize() const { return GetStruct<const FlatSize *>(28); }
|
||||
int32_t direction() const { return GetField<int32_t>(30, 0); }
|
||||
uint8_t bounceEnabled() const { return GetField<uint8_t>(32, 0); }
|
||||
int32_t gravity() const { return GetField<int32_t>(34, 0); }
|
||||
int32_t itemMargin() const { return GetField<int32_t>(36, 0); }
|
||||
int32_t itemMargin() const { return GetField<int32_t>(34, 0); }
|
||||
const flatbuffers::String *directionType() const { return GetPointer<const flatbuffers::String *>(36); }
|
||||
const flatbuffers::String *horizontalType() const { return GetPointer<const flatbuffers::String *>(38); }
|
||||
const flatbuffers::String *verticalType() const { return GetPointer<const flatbuffers::String *>(40); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* widgetOptions */) &&
|
||||
|
@ -1468,8 +1470,13 @@ struct ListViewOptions : private flatbuffers::Table {
|
|||
VerifyField<FlatSize>(verifier, 28 /* innerSize */) &&
|
||||
VerifyField<int32_t>(verifier, 30 /* direction */) &&
|
||||
VerifyField<uint8_t>(verifier, 32 /* bounceEnabled */) &&
|
||||
VerifyField<int32_t>(verifier, 34 /* gravity */) &&
|
||||
VerifyField<int32_t>(verifier, 36 /* itemMargin */) &&
|
||||
VerifyField<int32_t>(verifier, 34 /* itemMargin */) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 36 /* directionType */) &&
|
||||
verifier.Verify(directionType()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 38 /* horizontalType */) &&
|
||||
verifier.Verify(horizontalType()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 40 /* verticalType */) &&
|
||||
verifier.Verify(verticalType()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
@ -1492,12 +1499,14 @@ struct ListViewOptionsBuilder {
|
|||
void add_innerSize(const FlatSize *innerSize) { fbb_.AddStruct(28, innerSize); }
|
||||
void add_direction(int32_t direction) { fbb_.AddElement<int32_t>(30, direction, 0); }
|
||||
void add_bounceEnabled(uint8_t bounceEnabled) { fbb_.AddElement<uint8_t>(32, bounceEnabled, 0); }
|
||||
void add_gravity(int32_t gravity) { fbb_.AddElement<int32_t>(34, gravity, 0); }
|
||||
void add_itemMargin(int32_t itemMargin) { fbb_.AddElement<int32_t>(36, itemMargin, 0); }
|
||||
void add_itemMargin(int32_t itemMargin) { fbb_.AddElement<int32_t>(34, itemMargin, 0); }
|
||||
void add_directionType(flatbuffers::Offset<flatbuffers::String> directionType) { fbb_.AddOffset(36, directionType); }
|
||||
void add_horizontalType(flatbuffers::Offset<flatbuffers::String> horizontalType) { fbb_.AddOffset(38, horizontalType); }
|
||||
void add_verticalType(flatbuffers::Offset<flatbuffers::String> verticalType) { fbb_.AddOffset(40, verticalType); }
|
||||
ListViewOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
ListViewOptionsBuilder &operator=(const ListViewOptionsBuilder &);
|
||||
flatbuffers::Offset<ListViewOptions> Finish() {
|
||||
auto o = flatbuffers::Offset<ListViewOptions>(fbb_.EndTable(start_, 17));
|
||||
auto o = flatbuffers::Offset<ListViewOptions>(fbb_.EndTable(start_, 19));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
@ -1518,11 +1527,15 @@ inline flatbuffers::Offset<ListViewOptions> CreateListViewOptions(flatbuffers::F
|
|||
const FlatSize *innerSize = 0,
|
||||
int32_t direction = 0,
|
||||
uint8_t bounceEnabled = 0,
|
||||
int32_t gravity = 0,
|
||||
int32_t itemMargin = 0) {
|
||||
int32_t itemMargin = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> directionType = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> horizontalType = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> verticalType = 0) {
|
||||
ListViewOptionsBuilder builder_(_fbb);
|
||||
builder_.add_verticalType(verticalType);
|
||||
builder_.add_horizontalType(horizontalType);
|
||||
builder_.add_directionType(directionType);
|
||||
builder_.add_itemMargin(itemMargin);
|
||||
builder_.add_gravity(gravity);
|
||||
builder_.add_direction(direction);
|
||||
builder_.add_innerSize(innerSize);
|
||||
builder_.add_scale9Size(scale9Size);
|
||||
|
|
|
@ -106,9 +106,10 @@ namespace cocostudio
|
|||
Size innerSize(200, 300);
|
||||
int direction = 0;
|
||||
bool bounceEnabled = false;
|
||||
int gravity = 0;
|
||||
int itemMargin = 0;
|
||||
|
||||
std::string directionType = "";
|
||||
std::string horizontalType = "";
|
||||
std::string verticalType = "";
|
||||
|
||||
// attributes
|
||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||
|
@ -154,64 +155,15 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "DirectionType")
|
||||
{
|
||||
if (value == "Vertical")
|
||||
{
|
||||
direction = 1;
|
||||
|
||||
attribute = objectData->FirstAttribute();
|
||||
while (attribute)
|
||||
{
|
||||
name = attribute->Name();
|
||||
value = attribute->Value();
|
||||
|
||||
if (name == "HorizontalType")
|
||||
{
|
||||
if (value == "HORIZONTAL_LEFT")
|
||||
{
|
||||
gravity = 0;
|
||||
}
|
||||
else if (value == "HORIZONTAL_RIGHT")
|
||||
{
|
||||
gravity = 1;
|
||||
}
|
||||
else if (value == "HORIZONTAL_CENTER")
|
||||
{
|
||||
gravity = 2;
|
||||
}
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
}
|
||||
else if (value == "Horizontal")
|
||||
{
|
||||
direction = 2;
|
||||
|
||||
attribute = objectData->FirstAttribute();
|
||||
while (attribute)
|
||||
{
|
||||
name = attribute->Name();
|
||||
value = attribute->Value();
|
||||
|
||||
if (name == "VerticalType")
|
||||
{
|
||||
if (value == "VERTICAL_TOP")
|
||||
{
|
||||
gravity = 3;
|
||||
}
|
||||
else if (value == "VERTICAL_BOTTOM")
|
||||
{
|
||||
gravity = 4;
|
||||
}
|
||||
else if (value == "VERTICAL_CENTER")
|
||||
{
|
||||
gravity = 5;
|
||||
}
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
}
|
||||
directionType = value;
|
||||
}
|
||||
else if (name == "HorizontalType")
|
||||
{
|
||||
horizontalType = value;
|
||||
}
|
||||
else if (name == "VerticalType")
|
||||
{
|
||||
verticalType = value;
|
||||
}
|
||||
else if (name == "IsBounceEnabled")
|
||||
{
|
||||
|
@ -233,7 +185,7 @@ namespace cocostudio
|
|||
|
||||
if (name == "InnerNodeSize")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
while (attribute)
|
||||
{
|
||||
name = attribute->Name();
|
||||
|
@ -253,7 +205,7 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "Size" && backGroundScale9Enabled)
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
|
@ -274,7 +226,7 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "SingleColor")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
|
@ -299,7 +251,7 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "EndColor")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
|
@ -324,7 +276,7 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "FirstColor")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
|
@ -349,7 +301,7 @@ namespace cocostudio
|
|||
}
|
||||
else if (name == "ColorVector")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
while (attribute)
|
||||
{
|
||||
name = attribute->Name();
|
||||
|
@ -372,7 +324,7 @@ namespace cocostudio
|
|||
std::string texture = "";
|
||||
std::string texturePng = "";
|
||||
|
||||
attribute = child->FirstAttribute();
|
||||
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
|
@ -436,8 +388,10 @@ namespace cocostudio
|
|||
&f_innerSize,
|
||||
direction,
|
||||
bounceEnabled,
|
||||
gravity,
|
||||
itemMargin);
|
||||
itemMargin,
|
||||
builder->CreateString(directionType),
|
||||
builder->CreateString(horizontalType),
|
||||
builder->CreateString(verticalType));
|
||||
|
||||
return *(Offset<Table>*)(&options);
|
||||
}
|
||||
|
@ -503,19 +457,54 @@ 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);
|
||||
// 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);
|
||||
// int gravityValue = options->gravity();
|
||||
// ListView::Gravity gravity = (ListView::Gravity)gravityValue;
|
||||
// listView->setGravity(gravity);
|
||||
|
||||
std::string directionType = options->directionType()->c_str();
|
||||
if (directionType == "")
|
||||
{
|
||||
listView->setDirection(ListView::Direction::HORIZONTAL);
|
||||
std::string verticalType = options->verticalType()->c_str();
|
||||
if (verticalType == "")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::TOP);
|
||||
}
|
||||
else if (verticalType == "Align_Bottom")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::BOTTOM);
|
||||
}
|
||||
else if (verticalType == "Align_VerticalCenter")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::CENTER_VERTICAL);
|
||||
}
|
||||
}
|
||||
else if (directionType == "Vertical")
|
||||
{
|
||||
listView->setDirection(ListView::Direction::VERTICAL);
|
||||
std::string horizontalType = options->horizontalType()->c_str();
|
||||
if (horizontalType == "")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::LEFT);
|
||||
}
|
||||
else if (horizontalType == "Align_Right")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::RIGHT);
|
||||
}
|
||||
else if (horizontalType == "Align_HorizontalCenter")
|
||||
{
|
||||
listView->setGravity(ListView::Gravity::CENTER_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
|
||||
float itemMargin = options->itemMargin();
|
||||
listView->setItemsMargin(itemMargin);
|
||||
|
||||
|
||||
|
||||
auto widgetReader = WidgetReader::getInstance();
|
||||
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
||||
|
||||
|
|
|
@ -484,6 +484,10 @@ void ListView::selectedItemEvent(TouchEventType event)
|
|||
if (_eventCallback) {
|
||||
_eventCallback(this,EventType::ON_SELECTED_ITEM_START);
|
||||
}
|
||||
if (_ccEventCallback)
|
||||
{
|
||||
_ccEventCallback(this, static_cast<int>(EventType::ON_SELECTED_ITEM_START));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -495,6 +499,10 @@ void ListView::selectedItemEvent(TouchEventType event)
|
|||
if (_eventCallback) {
|
||||
_eventCallback(this, EventType::ON_SELECTED_ITEM_END);
|
||||
}
|
||||
if (_ccEventCallback)
|
||||
{
|
||||
_ccEventCallback(this, static_cast<int>(EventType::ON_SELECTED_ITEM_END));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue