Ejemplo n.º 1
0
void FrameLayout::setForegroundGravity(int foregroundGravity) {
    if (m_foregroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity::RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity::START;
        }

        if ((foregroundGravity & Gravity::VERTICAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity::TOP;
        }

        m_foregroundGravity = foregroundGravity;

        /*if (m_foregroundGravity == Gravity::FILL && m_foreground != null) {
            Rect padding = new Rect();
            if (m_foreground.getPadding(padding)) {
                m_foregroundPaddingLeft = padding.left;
                m_foregroundPaddingTop = padding.top;
                m_foregroundPaddingRight = padding.right;
                m_foregroundPaddingBottom = padding.bottom;
            }
        } else {*/
        m_foregroundPaddingLeft = 0;
        m_foregroundPaddingTop = 0;
        m_foregroundPaddingRight = 0;
        m_foregroundPaddingBottom = 0;

        requestLayout();
    }
}
Ejemplo n.º 2
0
 void Container::detach(Element * const element)
 {
     if(element != nullptr)
     {
         ResetFocus();
         for (auto childPtrIt = _children.begin(); childPtrIt != _children.end(); ++childPtrIt)
         {
             if (childPtrIt->get() == element)
             {
                 (*childPtrIt)->_upper = nullptr;
                 onDetach(childPtrIt->get());
                 _children.erase(childPtrIt);
                 return;
             }
         }
     }
     requestLayout();
 }
Ejemplo n.º 3
0
    void NdCxListItem::requestLayout(void)
    {
        if (m_pChildren && m_pChildren->count() > 0)
        {
            CCPoint child_pos;
            CCSize size = getContentSize();
            CCPoint curr_pos;
            CCPoint prev_pos;
            float vertical_height = size.height;
            bool height_changed = false;

            for (int i = 0, l = m_pChildren->count(); i < l; ++i)
            {
                CCNode *it = (CCNode *)m_pChildren->objectAtIndex(i);
                if (!(it))
                {
                    break;
                }

                CCSize child_size = (*(it)).getContentSize();
                child_size.width *= (*(it)).getScaleX();
                child_size.height *= (*(it)).getScaleY();
                
                std::map<CCNode *, LayoutParam>::iterator pos = layout_info_.find(it);
                CCAssert(layout_info_.end() != pos, "!!");
                LayoutParam *lp = &pos->second;
                switch ((*lp).val_x.t)
                {
                case PARENT_CENTER:
                    child_pos.x = (size.width - child_size.width) / 2;
                    break;
                case HORIZONTAL_LEFT:
                    child_pos.x = horizontal_margin_;
                    break;
                case HORIZONTAL_RIGHT:
                    child_pos.x = size.width - child_size.width - horizontal_margin_;
                    break;
                case ABS_WITH_PIXEL:
                    child_pos.x = (float)(*lp).val_x.val.pixel_val;
                    break;
                case ABS_WITH_PERCENT:
                    child_pos.x = horizontal_margin_ + (*lp).val_x.val.percent_val * (size.width - 2*horizontal_margin_);
                    break;
                case REF_PREV_X_INC:
                    {
                        child_pos.x = prev_pos.x + (*lp).padding;
                        break;
                    }
                case REF_PREV_X_DEC:
                    {
                        child_pos.x = prev_pos.x - (*lp).padding;
                        break;
                    }
                case REL_FLOW:
                    child_pos.x = curr_pos.x + (*lp).padding;
                    break;
                }

                if (!(*lp).wrap)
                {
                    curr_pos.x = child_pos.x + child_size.width;
                }

                switch ((*lp).val_y.t)
                {
                case PARENT_CENTER:
                    {
                        if (child_size.height > vertical_height - 2*vertical_margin_)
                        {
                            vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
                            height_changed = true;
                        }

                        child_pos.y = (vertical_height - child_size.height)*0.5f;

                        break;
                    }
                case VERTICAL_TOP:
                    {
                        if (child_size.height > vertical_height - 2*vertical_margin_)
                        {
                            vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
                            height_changed = true;
                        }

                        child_pos.y = vertical_height - (child_size.height + vertical_margin_);

                        break;
                    }
                case VERTICAL_BOTTOM:
                    {
                        if (child_size.height > vertical_height - 2*vertical_margin_)
                        {
                            vertical_height += child_size.height - (vertical_height - 2*vertical_margin_);
                            height_changed = true;
                        }

                        child_pos.y = vertical_margin_;

                        break;
                    }
                case ABS_WITH_PIXEL:
                    {
                        child_pos.y = (float)(*lp).val_y.val.pixel_val;
                        if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
                        {
                            vertical_height = child_pos.y + child_size.height + vertical_margin_;
                            height_changed = true;
                        }

                        break;
                    }
                case ABS_WITH_PERCENT:
                    {
                        child_pos.y = (*lp).val_y.val.percent_val * (vertical_height - 2*vertical_margin_);
                        if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
                        {
                            vertical_height = child_pos.y + child_size.height + vertical_margin_;
                            height_changed = true;
                        }

                        break;
                    }
                case REF_PREV_Y_INC:
                    {
                        child_pos.y = prev_pos.y + (*lp).padding;
                        if (child_pos.y + child_size.height > + vertical_height - vertical_margin_)
                        {
                            vertical_height = child_pos.y + child_size.height + vertical_margin_;
                            height_changed = true;
                        }

                        break;
                    }
                case REF_PREV_Y_DEC:
                    {
                        child_pos.y = prev_pos.y - (child_size.height + (*lp).padding);
                        if (child_pos.y < vertical_margin_)
                        {
                            vertical_height += vertical_margin_-child_pos.y + vertical_margin_;
                            child_pos.y = vertical_margin_;
                            height_changed = true;
                        }
                        
                        break;
                    }                    
                case REL_FLOW:
                    {
                        child_pos.y = curr_pos.y + (*lp).padding;
                        if (child_pos.y + child_size.height > vertical_height - vertical_margin_)
                        {
                            vertical_height = curr_pos.y + child_size.height + vertical_margin_;
                            height_changed = true;
                        }

                        break;
                    }

                    curr_pos.y = child_pos.y + child_size.height;
                }
                
                prev_pos = child_pos;

                (*it).setPosition(child_pos);
            }

            setContentSize(CCSizeMake(size.width, vertical_height));

            if (height_changed)
            {
                requestLayout();
            }
        }
    }