mirror of https://github.com/axmolengine/axmol.git
Merge pull request #4671 from nutty898/develop_nutty_modify_framework_newrender_modify_projectfiles
Add refresh layout method and uses Range loop for GUI codes
This commit is contained in:
commit
8dfc428599
|
@ -38,7 +38,7 @@ Widget* UIHelper::seekWidgetByTag(Widget* root, int tag)
|
|||
{
|
||||
return root;
|
||||
}
|
||||
Vector<Node*> arrayRootChildren = root->getChildren();
|
||||
const auto& arrayRootChildren = root->getChildren();
|
||||
int length = arrayRootChildren.size();
|
||||
for (int i=0;i<length;i++)
|
||||
{
|
||||
|
@ -62,11 +62,10 @@ Widget* UIHelper::seekWidgetByName(Widget* root, const char *name)
|
|||
{
|
||||
return root;
|
||||
}
|
||||
Vector<Node*> arrayRootChildren = root->getChildren();
|
||||
int length = arrayRootChildren.size();
|
||||
for (int i=0;i<length;i++)
|
||||
const auto& arrayRootChildren = root->getChildren();
|
||||
for (auto& subWidget : arrayRootChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
Widget* res = seekWidgetByName(child,name);
|
||||
if (res != nullptr)
|
||||
{
|
||||
|
@ -82,11 +81,10 @@ Widget* UIHelper::seekWidgetByRelativeName(Widget *root, const char *name)
|
|||
{
|
||||
return nullptr;
|
||||
}
|
||||
Vector<Node*> arrayRootChildren = root->getChildren();
|
||||
int length = arrayRootChildren.size();
|
||||
for (int i=0;i<length;i++)
|
||||
const auto& arrayRootChildren = root->getChildren();
|
||||
for (auto& subWidget : arrayRootChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
||||
if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0)
|
||||
{
|
||||
|
@ -107,11 +105,10 @@ Widget* UIHelper::seekActionWidgetByActionTag(Widget* root, int tag)
|
|||
{
|
||||
return root;
|
||||
}
|
||||
Vector<Node*> arrayRootChildren = root->getChildren();
|
||||
int length = arrayRootChildren.size();
|
||||
for (int i=0;i<length;i++)
|
||||
const auto& arrayRootChildren = root->getChildren();
|
||||
for (auto& subWidget : arrayRootChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
Widget* res = seekActionWidgetByActionTag(child,tag);
|
||||
if (res != nullptr)
|
||||
{
|
||||
|
|
|
@ -710,6 +710,11 @@ LayoutType Layout::getLayoutType() const
|
|||
return _layoutType;
|
||||
}
|
||||
|
||||
void Layout::requestDoLayout()
|
||||
{
|
||||
_doLayoutDirty = true;
|
||||
}
|
||||
|
||||
void Layout::doLayout()
|
||||
{
|
||||
if (!_doLayoutDirty)
|
||||
|
@ -722,12 +727,12 @@ void Layout::doLayout()
|
|||
break;
|
||||
case LAYOUT_LINEAR_VERTICAL:
|
||||
{
|
||||
int length = _widgetChildren.size();
|
||||
Size layoutSize = getSize();
|
||||
float topBoundary = layoutSize.height;
|
||||
for (int i=0; i<length; ++i)
|
||||
|
||||
for (auto& subWidget : _widgetChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
||||
|
||||
if (layoutParameter)
|
||||
|
@ -762,12 +767,11 @@ void Layout::doLayout()
|
|||
}
|
||||
case LAYOUT_LINEAR_HORIZONTAL:
|
||||
{
|
||||
int length = _widgetChildren.size();
|
||||
Size layoutSize = getSize();
|
||||
float leftBoundary = 0.0f;
|
||||
for (int i=0; i<length; ++i)
|
||||
for (auto& subWidget : _widgetChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
||||
|
||||
if (layoutParameter)
|
||||
|
@ -802,22 +806,19 @@ void Layout::doLayout()
|
|||
}
|
||||
case LAYOUT_RELATIVE:
|
||||
{
|
||||
int length = _widgetChildren.size();
|
||||
int unlayoutChildCount = length;
|
||||
int unlayoutChildCount = _widgetChildren.size();
|
||||
Size layoutSize = getSize();
|
||||
|
||||
for (int i=0; i<length; i++)
|
||||
for (auto& subWidget : _widgetChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
||||
layoutParameter->_put = false;
|
||||
}
|
||||
|
||||
while (unlayoutChildCount > 0)
|
||||
{
|
||||
for (int i=0; i<length; i++)
|
||||
for (auto& subWidget : _widgetChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
||||
|
||||
if (layoutParameter)
|
||||
|
|
|
@ -212,6 +212,8 @@ public:
|
|||
virtual void visit();
|
||||
|
||||
virtual void sortAllChildren() override;
|
||||
|
||||
void requestDoLayout();
|
||||
protected:
|
||||
//override "init" method of widget.
|
||||
virtual bool init() override;
|
||||
|
|
|
@ -90,9 +90,8 @@ void ListView::updateInnerContainerSize()
|
|||
{
|
||||
int length = _items.size();
|
||||
float totalHeight = (length - 1) * _itemsMargin;
|
||||
for (int i=0; i<length; i++)
|
||||
for (auto& item : _items)
|
||||
{
|
||||
Widget* item = _items.at(i);
|
||||
totalHeight += item->getSize().height;
|
||||
}
|
||||
float finalWidth = _size.width;
|
||||
|
@ -104,9 +103,8 @@ void ListView::updateInnerContainerSize()
|
|||
{
|
||||
int length = _items.size();
|
||||
float totalWidth = (length - 1) * _itemsMargin;
|
||||
for (int i=0; i<length; i++)
|
||||
for (auto& item : _items)
|
||||
{
|
||||
Widget* item = _items.at(i);
|
||||
totalWidth += item->getSize().width;
|
||||
}
|
||||
float finalWidth = totalWidth;
|
||||
|
@ -363,6 +361,11 @@ void ListView::setDirection(SCROLLVIEW_DIR dir)
|
|||
ScrollView::setDirection(dir);
|
||||
}
|
||||
|
||||
void ListView::requestRefreshView()
|
||||
{
|
||||
_refreshViewDirty = true;
|
||||
}
|
||||
|
||||
void ListView::refreshView()
|
||||
{
|
||||
int length = _items.size();
|
||||
|
@ -441,12 +444,9 @@ Widget* ListView::createCloneInstance()
|
|||
|
||||
void ListView::copyClonedWidgetChildren(Widget* model)
|
||||
{
|
||||
Vector<Widget*> arrayItems = getItems();
|
||||
|
||||
int length = arrayItems.size();
|
||||
for (int i=0; i<length; i++)
|
||||
auto& arrayItems = getItems();
|
||||
for (auto& item : arrayItems)
|
||||
{
|
||||
Widget* item = arrayItems.at(i);
|
||||
pushBackCustomItem(item->clone());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,6 +165,8 @@ public:
|
|||
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
void requestRefreshView();
|
||||
|
||||
protected:
|
||||
virtual void addChild(Node* child) override{ScrollView::addChild(child);};
|
||||
virtual void addChild(Node * child, int zOrder) override{ScrollView::addChild(child, zOrder);};
|
||||
|
|
|
@ -181,7 +181,7 @@ void PageView::insertPage(Layout* page, int idx)
|
|||
page->setSize(pvSize);
|
||||
}
|
||||
int length = _pages.size();
|
||||
for (int i=(idx+1); i<length; i++) {
|
||||
for (int i=(idx+1); i<length; i++){
|
||||
Widget* behindPage = _pages.at(i);
|
||||
Point formerPos = behindPage->getPosition();
|
||||
behindPage->setPosition(Point(formerPos.x+getSize().width, 0));
|
||||
|
@ -268,10 +268,8 @@ void PageView::onSizeChanged()
|
|||
void PageView::updateChildrenSize()
|
||||
{
|
||||
Size selfSize = getSize();
|
||||
int length = _pages.size();
|
||||
for (long i=0; i<length; i++)
|
||||
for (auto& page : _pages)
|
||||
{
|
||||
Layout* page = _pages.at(i);
|
||||
page->setSize(selfSize);
|
||||
}
|
||||
}
|
||||
|
@ -410,13 +408,11 @@ void PageView::onTouchCancelled(Touch *touch, Event *unusedEvent)
|
|||
|
||||
void PageView::movePages(float offset)
|
||||
{
|
||||
int length = _pages.size();
|
||||
for (int i = 0; i < length; i++)
|
||||
for (auto& page : _pages)
|
||||
{
|
||||
Widget* child = _pages.at(i);
|
||||
_movePagePoint.x = child->getPosition().x + offset;
|
||||
_movePagePoint.y = child->getPosition().y;
|
||||
child->setPosition(_movePagePoint);
|
||||
_movePagePoint.x = page->getPosition().x + offset;
|
||||
_movePagePoint.y = page->getPosition().y;
|
||||
page->setPosition(_movePagePoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,11 +602,9 @@ Widget* PageView::createCloneInstance()
|
|||
|
||||
void PageView::copyClonedWidgetChildren(Widget* model)
|
||||
{
|
||||
Vector<Layout*> modelPages = dynamic_cast<PageView*>(model)->getPages();
|
||||
int length = modelPages.size();
|
||||
for (int i=0; i<length; i++)
|
||||
auto& modelPages = dynamic_cast<PageView*>(model)->getPages();
|
||||
for (auto& page : modelPages)
|
||||
{
|
||||
Layout* page = modelPages.at(i);
|
||||
addPage(dynamic_cast<Layout*>(page->clone()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -977,10 +977,11 @@ Widget* Widget::createCloneInstance()
|
|||
|
||||
void Widget::copyClonedWidgetChildren(Widget* model)
|
||||
{
|
||||
int length = model->getChildren().size();
|
||||
for (int i=0; i<length; i++)
|
||||
auto& modelChildren = model->getChildren();
|
||||
|
||||
for (auto& subWidget : modelChildren)
|
||||
{
|
||||
Widget* child = static_cast<Widget*>(model->getChildren().at(i));
|
||||
Widget* child = static_cast<Widget*>(subWidget);
|
||||
addChild(child->clone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue