mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14653 from liamcindy/v3_ui_pageView
update pageview to support adjust child size
This commit is contained in:
commit
bc29bde5ae
|
@ -390,8 +390,8 @@ protected:
|
||||||
|
|
||||||
virtual void onItemListChanged();
|
virtual void onItemListChanged();
|
||||||
|
|
||||||
|
virtual void remedyLayoutParameter(Widget* item);
|
||||||
void updateInnerContainerSize();
|
void updateInnerContainerSize();
|
||||||
void remedyLayoutParameter(Widget* item);
|
|
||||||
void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex);
|
void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex);
|
||||||
void remedyHorizontalLayoutParameter(LinearLayoutParameter* layoutParameter,ssize_t itemIndex);
|
void remedyHorizontalLayoutParameter(LinearLayoutParameter* layoutParameter,ssize_t itemIndex);
|
||||||
|
|
||||||
|
|
|
@ -427,6 +427,11 @@ const Color3B& PageView::getIndicatorSelectedIndexColor() const
|
||||||
return _indicator->getSelectedIndexColor();
|
return _indicator->getSelectedIndexColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PageView::remedyLayoutParameter(Widget *item)
|
||||||
|
{
|
||||||
|
item->setContentSize(this->getContentSize());
|
||||||
|
ListView::remedyLayoutParameter(item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -350,6 +350,7 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
protected:
|
protected:
|
||||||
void pageTurningEvent();
|
void pageTurningEvent();
|
||||||
|
|
||||||
|
virtual void remedyLayoutParameter(Widget* item)override;
|
||||||
virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override;
|
virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override;
|
||||||
virtual void onItemListChanged() override;
|
virtual void onItemListChanged() override;
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
|
@ -13,6 +13,7 @@ UIPageViewTests::UIPageViewTests()
|
||||||
ADD_TEST_CASE(UIPageViewJumpToPageTest);
|
ADD_TEST_CASE(UIPageViewJumpToPageTest);
|
||||||
ADD_TEST_CASE(UIPageViewVerticalTest);
|
ADD_TEST_CASE(UIPageViewVerticalTest);
|
||||||
ADD_TEST_CASE(UIPageViewDisableTouchTest);
|
ADD_TEST_CASE(UIPageViewDisableTouchTest);
|
||||||
|
ADD_TEST_CASE(UIPageViewChildSizeTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UIPageViewTest
|
// UIPageViewTest
|
||||||
|
@ -876,3 +877,88 @@ bool UIPageViewDisableTouchTest::init()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UIPageViewTest
|
||||||
|
UIPageViewChildSizeTest::UIPageViewChildSizeTest()
|
||||||
|
: _displayValueLabel(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UIPageViewChildSizeTest::~UIPageViewChildSizeTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UIPageViewChildSizeTest::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
// Add a label in which the dragpanel events will be displayed
|
||||||
|
_displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32);
|
||||||
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||||
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
|
widgetSize.height / 2.0f +
|
||||||
|
_displayValueLabel->getContentSize().height * 1.5));
|
||||||
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
|
// Add the black background
|
||||||
|
Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30);
|
||||||
|
alert->setColor(Color3B(159, 168, 176));
|
||||||
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||||
|
_uiLayer->addChild(alert);
|
||||||
|
|
||||||
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||||
|
|
||||||
|
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||||
|
|
||||||
|
// Create the page view
|
||||||
|
Size size(240, 130);
|
||||||
|
PageView* pageView = PageView::create();
|
||||||
|
pageView->setDirection(PageView::Direction::HORIZONTAL);
|
||||||
|
pageView->setContentSize(size);
|
||||||
|
Size backgroundSize = background->getContentSize();
|
||||||
|
pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f);
|
||||||
|
pageView->removeAllItems();
|
||||||
|
pageView->setIndicatorEnabled(true);
|
||||||
|
|
||||||
|
int pageCount = 4;
|
||||||
|
for (int i = 0; i < pageCount; ++i)
|
||||||
|
{
|
||||||
|
ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png");
|
||||||
|
imageView->setScale9Enabled(true);
|
||||||
|
|
||||||
|
Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30);
|
||||||
|
label->setColor(Color3B(192, 192, 192));
|
||||||
|
label->setAnchorPoint(Vec2::ZERO);
|
||||||
|
imageView->addChild(label);
|
||||||
|
|
||||||
|
pageView->insertCustomItem(imageView, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
pageView->addEventListener(CC_CALLBACK_2(UIPageViewChildSizeTest::pageViewEvent, this));
|
||||||
|
|
||||||
|
_uiLayer->addChild(pageView);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIPageViewChildSizeTest::pageViewEvent(Ref *pSender, PageView::EventType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PageView::EventType::TURNING:
|
||||||
|
{
|
||||||
|
PageView* pageView = dynamic_cast<PageView*>(pSender);
|
||||||
|
|
||||||
|
_displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,4 +139,20 @@ protected:
|
||||||
cocos2d::ui::Text* _displayValueLabel;
|
cocos2d::ui::Text* _displayValueLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIPageViewChildSizeTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(UIPageViewChildSizeTest);
|
||||||
|
|
||||||
|
UIPageViewChildSizeTest();
|
||||||
|
~UIPageViewChildSizeTest();
|
||||||
|
virtual bool init() override;
|
||||||
|
|
||||||
|
void pageViewEvent(cocos2d::Ref* sender, cocos2d::ui::PageView::EventType type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
cocos2d::ui::Text* _displayValueLabel;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* defined(__TestCpp__UIPageViewTest__) */
|
#endif /* defined(__TestCpp__UIPageViewTest__) */
|
||||||
|
|
Loading…
Reference in New Issue