Skip to content

Content size includes an extra amount of padding #2

Description

@adamlwgriffiths

Content size is currently calculated like this (for vertical alignment).

float width = 0.0;
float height = 0.0;

// calculate contentSize,
CCMenuItem *item = nil;
CCARRAY_FOREACH(children_, item)
{
    height += item.contentSize.height * item.scaleY + padding;
    width = MAX(item.contentSize.width * item.scaleX, width);
}

This includes 1 padding per item.
But the last padding should always be removed.
A better method is as follows:

float width = 0.0;
float height = 0.0;

// remove 1 amount of padding
int itemCount = [children_ count];
if ( itemCount > 0 )
{
    height -= padding;
}

// calculate contentSize,
CCMenuItem *item = nil;
CCARRAY_FOREACH(children_, item)
{
    height += item.contentSize.height * item.scaleY + padding;
    width = MAX(item.contentSize.width * item.scaleX, width);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions