当前位置: 首页>>代码示例>>C++>>正文


C++ LinearLayoutParameter::setGravity方法代码示例

本文整理汇总了C++中LinearLayoutParameter::setGravity方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearLayoutParameter::setGravity方法的具体用法?C++ LinearLayoutParameter::setGravity怎么用?C++ LinearLayoutParameter::setGravity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinearLayoutParameter的用法示例。


在下文中一共展示了LinearLayoutParameter::setGravity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

bool WindowProtocol::init(){
    bool ret = false;
    
    //super init
    if(!Layer::init())
        return ret;
    
    //Put blocker
    Layer* blocker = LayerColor::create(Color4B(0, 0, 0, 255*0.5), VisibleRect::getVisibleRect().size.width, VisibleRect::getVisibleRect().size.height);
    blocker->setAnchorPoint(Vec2::ZERO);
    blocker->setPosition(Vec2(VisibleRect::getVisibleRect().origin.x, VisibleRect::getVisibleRect().origin.y));
    
    //Base window
    _baseWindow = Scale9Sprite::createWithSpriteFrameName("WindowBase.psd",BASE_WINDOW_INSET_RECT);
    _baseWindow->setContentSize(Size(850,490-10-10));
    _baseWindow->setAnchorPoint(Vec2(0.0, 1.0));
    _baseWindow->setPosition(Vec2(55, VisibleRect::getVisibleRect().size.height-60));
    
    //Put base window
    _baseLayout = Layout::create();
    CCASSERT(_baseLayout!=nullptr, "_baseLayout cannot be null.");
    _baseLayout->setLayoutType(Layout::Type::VERTICAL);
    _baseLayout->setContentSize(_baseWindow->getCapInsets().size);
    _baseLayout->setAnchorPoint(Vec2(0.0, 1.0));
    _baseLayout->setPosition(Vec2(2,_baseWindow->getContentSize().height-2));
    //PutLayout on sprite
    _baseWindow->addChild(_baseLayout,0);
    
    //---Title---
    //Layout
    _titleLayout = Layout::create();
    CCASSERT(_titleLayout!=nullptr, "_titleLayer cannot be null.");
    //_titleLayout->setAnchorPoint(Vec2(0.0, 1.0));
    _titleLayout->setLayoutType(Layout::Type::HORIZONTAL);
    _titleLayout->setContentSize(Size(850-2*2, 55));
    _titleLayout->setPosition(Vec2(_baseLayout->getContentSize().width/2, _baseLayout->getContentSize().height/2));
    //set baseTitle as titleLayout background
    //No longer need title base image...
    _titleLayout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
    _titleLayout->setBackGroundColor(Color3B(200, 200, 169));
    //Close Button
    LinearLayoutParameter* lpCloseButton = LinearLayoutParameter::create();
    _closeButton = Button::create("MainUI_Windows_Close_Normal.png","MainUI_Windows_Close_Pressed.png","",TextureResType::PLIST);
    CCASSERT(_closeButton!=nullptr, "_closeButton cannot be null.");
    _closeButton->setPosition(Vec2(_titleLayout->getContentSize().width/2, _titleLayout->getContentSize().height/2));
    lpCloseButton->setGravity(LinearLayoutParameter::LinearGravity::LEFT);
    lpCloseButton->setMargin(Margin(0, 0, 0, 0));
    _closeButton->setLayoutParameter(lpCloseButton);
    if(_closeCallback!=nullptr)
        _closeButton->addTouchEventListener(_closeCallback);
    
    //Title text
    LinearLayoutParameter* lpTitleText = LinearLayoutParameter::create();
    _titleText = Text::create(_titleString, "fonts/Apple_LiGothic_Medium.ttf", computeFontSize(42));
    CCASSERT(_titleText!=nullptr, "_titletext cannot be null.");
    _titleText->setColor(Color3B(59,134,134));
    _titleText->setPosition(Vec2(_titleLayout->getContentSize().width/2, _titleLayout->getContentSize().height/2));
    lpTitleText->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
    lpTitleText->setMargin(Margin(_titleLayout->getContentSize().width/2-_titleText->getContentSize().width/2-_closeButton->getContentSize().width, 0, 0, 0));
    _titleText->setLayoutParameter(lpTitleText);
    
    
    //Add component to title layout
    _titleLayout->addChild(_closeButton,1);
    _titleLayout->addChild(_titleText,2);
    
    //---add to base layout---
    _baseLayout->addChild(_titleLayout);
    
    //setBlockerTouchDispatcher
    auto touchBlocker = EventListenerTouchOneByOne::create();
    touchBlocker->setSwallowTouches(true);
    //lambda decide later
    touchBlocker->onTouchBegan= [](Touch* touch,Event* e){
        return true;
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchBlocker, blocker);
    
    //addChild
    addChild(blocker,0);
    addChild(_baseWindow,1);
    
    ret = true;
    return ret;
}
开发者ID:visualcshape,项目名称:Parallelformosa,代码行数:85,代码来源:WindowProtocol.cpp

示例2: remedyLayoutParameter

void ListView::remedyLayoutParameter(Widget *item)
{
    if (!item)
    {
        return;
    }
    switch (_direction) {
        case SCROLLVIEW_DIR_VERTICAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case LISTVIEW_GRAVITY_LEFT:
                        defaultLp->setGravity(LINEAR_GRAVITY_LEFT);
                        break;
                    case LISTVIEW_GRAVITY_RIGHT:
                        defaultLp->setGravity(LINEAR_GRAVITY_RIGHT);
                        break;
                    case LISTVIEW_GRAVITY_CENTER_HORIZONTAL:
                        defaultLp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(MarginZero);
                }
                else
                {
                    defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(MarginZero);
                }
                else
                {
                    llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                switch (_gravity) {
                    case LISTVIEW_GRAVITY_LEFT:
                        llp->setGravity(LINEAR_GRAVITY_LEFT);
                        break;
                    case LISTVIEW_GRAVITY_RIGHT:
                        llp->setGravity(LINEAR_GRAVITY_RIGHT);
                        break;
                    case LISTVIEW_GRAVITY_CENTER_HORIZONTAL:
                        llp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
            }
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case LISTVIEW_GRAVITY_TOP:
                        defaultLp->setGravity(LINEAR_GRAVITY_TOP);
                        break;
                    case LISTVIEW_GRAVITY_BOTTOM:
                        defaultLp->setGravity(LINEAR_GRAVITY_BOTTOM);
                        break;
                    case LISTVIEW_GRAVITY_CENTER_VERTICAL:
                        defaultLp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(MarginZero);
                }
                else
                {
                    defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(MarginZero);
                }
                else
                {
                    llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
//.........这里部分代码省略.........
开发者ID:BellyWong,项目名称:EarthWarrior3D,代码行数:101,代码来源:UIListView.cpp

示例3: remedyLayoutParameter

void ListView::remedyLayoutParameter(Widget *item)
{
    if (!item)
    {
        return;
    }
    switch (_direction) {
        case Direction::VERTICAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter());
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case Gravity::LEFT:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::LEFT);
                        break;
                    case Gravity::RIGHT:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT);
                        break;
                    case Gravity::CENTER_HORIZONTAL:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(Margin::ZERO);
                }
                else
                {
                    defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(Margin::ZERO);
                }
                else
                {
                    llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                switch (_gravity) {
                    case Gravity::LEFT:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::LEFT);
                        break;
                    case Gravity::RIGHT:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT);
                        break;
                    case Gravity::CENTER_HORIZONTAL:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
            }
            break;
        }
        case Direction::HORIZONTAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter());
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case Gravity::TOP:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::TOP);
                        break;
                    case Gravity::BOTTOM:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::BOTTOM);
                        break;
                    case Gravity::CENTER_VERTICAL:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(Margin::ZERO);
                }
                else
                {
                    defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(Margin::ZERO);
                }
                else
                {
                    llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
//.........这里部分代码省略.........
开发者ID:skatpgusskat,项目名称:December,代码行数:101,代码来源:UIListView.cpp


注:本文中的LinearLayoutParameter::setGravity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。