Exemple #1
0
bool UIFocusTestNestedLayout3::init()
{
    if (UIFocusTestBase::init()) {

        Size winSize = Director::getInstance()->getVisibleSize();

        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(40, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setScale(0.8f);

        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _verticalLayout->setTag(-1000);
        _firstFocusedWidget = _verticalLayout;


        HBox *upperHBox = HBox::create();
        upperHBox->setTag(-200);
        _verticalLayout->addChild(upperHBox);

        LinearLayoutParameter *params = LinearLayoutParameter::create();
        params->setMargin(Margin(0,0,50,0));

        LinearLayoutParameter *vparams = LinearLayoutParameter::create();
        vparams->setMargin(Margin(10, 0, 0, 140));
        upperHBox->setLayoutParameter(vparams);

        int count = 3;
        for (int i=0; i<count; ++i) {
            VBox *firstVbox = VBox::create();
            firstVbox->setScale(0.5);
            firstVbox->setLayoutParameter(params);
            firstVbox->setTag((i+1) * 100);

            int count1 = 3;
            for (int j=0; j<count1; ++j) {
                ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
                w->setTouchEnabled(true);
                w->setTag(j+firstVbox->getTag()+1);
                w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
                firstVbox->addChild(w);
            }

            upperHBox->addChild(firstVbox);

        }

        HBox *bottomHBox = HBox::create();
        bottomHBox->setScale(0.5);
        bottomHBox->setTag(600);

        bottomHBox->setLayoutParameter(vparams);
        count = 3;
        LinearLayoutParameter *bottomParams = LinearLayoutParameter::create();
        bottomParams->setMargin(Margin(0, 0, 8, 0));
        for (int i=0; i < count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setLayoutParameter(bottomParams);
            w->setTouchEnabled(true);
            w->setTag(i+601);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
            bottomHBox->addChild(w);
        }
        _verticalLayout->addChild(bottomHBox);



        _loopText = Text::create("loop enabled", "Arial", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);

        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this));
        this->addChild(btn);


        return true;
    }
    return false;
}
Exemple #2
0
bool UIFocusTestNestedLayout1::init()
{
    if (UIFocusTestBase::init()) {

        Size winSize = Director::getInstance()->getVisibleSize();

        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(winSize.width/2 - 80, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setScale(0.5);

        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _verticalLayout->setTag(100);
        _firstFocusedWidget = _verticalLayout;

        int count1 = 1;
        for (int i=0; i<count1; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setAnchorPoint(Vec2::ZERO);
            w->setTouchEnabled(true);
            w->setScaleX(2.5);
            w->setTag(i+count1);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
            _verticalLayout->addChild(w);
        }

        //add HBox into VBox
        HBox *hbox = HBox::create();
        hbox->setScale(0.8f);
        hbox->setTag(101);
        _verticalLayout->addChild(hbox);

        int count2 = 2;
        for (int i=0; i < count2; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setAnchorPoint(Vec2(0,1));
            w->setScaleY(2.0);
            w->setTouchEnabled(true);
            w->setTag(i+count1+count2);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
            hbox->addChild(w);
        }

        VBox *innerVBox = VBox::create();
        hbox->addChild(innerVBox);
        innerVBox->setTag(102);
//        innerVBox->setPassFocusToChild(false);
//        innerVBox->setFocusEnabled(false);


        int count3 = 2;
        for (int i=0; i<count3; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setTouchEnabled(true);
            w->setTag(i+count1+count2+count3);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
            innerVBox->addChild(w);
        }

        _loopText = Text::create("loop enabled", "Arial", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);

        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::toggleFocusLoop, this));
        this->addChild(btn);


        return true;
    }
    return false;
}