cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

CCTableView does not react to touches if contentSizeType = normalized

Open LearnCocos2D opened this issue 10 years ago • 3 comments
trafficstars

When cells are created like this, touches are not registered (block does not run):

    CCTableViewCell* cell = [CCTableViewCell node];
    cell.contentSizeType = CCSizeTypeNormalized;
    cell.contentSize = CGSizeMake(1, 1);

Simply commenting the contentSizeType line and assigning the cell's content node's contentSize to the contentSize of the cell makes it touchable again.

LearnCocos2D avatar Feb 11 '15 18:02 LearnCocos2D

This is probably the new input culling code. I assume the table draws fine in both cases?

I'm guessing setting the normalized content size results in a [cell contentSizeInPoints] of zero? Perhaps the parent is a zero size node?

I should add some more tests for this.

andykorth avatar Feb 11 '15 18:02 andykorth

Correct, drawing is fine.

Indeed, I get: cell size; {0, 0} when logging this:

-(CCTableViewCell*) tableView:(CCTableView*)tableView nodeForRowAtIndex:(NSUInteger)index
{
    // use the same seed so that the random colors don't change when scrolling
    srandom(index);

    CCSprite* icon = [CCSprite spriteWithImageNamed:@"Settings.png"];
    icon.color = [CCColor colorWithRed:CCRANDOM_0_1() green:CCRANDOM_0_1() blue:CCRANDOM_0_1()];
    icon.anchorPoint = CGPointZero;

    CCTableViewCell* cell = [CCTableViewCell node];
    cell.contentSize = icon.contentSize;
    [cell addChild:icon];

    _rowHeight = cell.contentSize.height;

    cell.contentSizeType = CCSizeTypeNormalized;
    cell.contentSize = CGSizeMake(1, 1);
    NSLog(@"cell size; %@", NSStringFromCGSize(cell.contentSizeInPoints));

    return cell;
}

Maybe I'm just assuming that the cell's contentSize will span that of all of its children. I don't think it works downwards in the hierarchy but rather the cell looks for its parent's size. Probably this actually works as intended?

LearnCocos2D avatar Feb 11 '15 18:02 LearnCocos2D

Yeah, even if it's working as intended, it might not be working in a useful way, haha.

Unfortunately, I think it's common to end up with zero size nodes somewhere in your hierarchy, and that messes with any children using relative content sizes. In this case, cell doesn't even have a parent yet. But once it's added to the hierarchy, it presumably still has a real contentSize of zero.

Maybe this is fixable with sensible defaults in CCTableView/CCScrollView/CCViewportNode and their camera/contentNodes. Not sure at what point in that chain the fix should be applied. There are lots of input tests inside CCViewportNode, but I don't think there's any specifically for CCScrollView (as in, tapping things inside a scrollview)

andykorth avatar Feb 11 '15 18:02 andykorth