Skip to content. | Skip to navigation

Personal tools

Sections

calcHConstraint:

-(void) calcHConstraint: (NSLayoutConstraint*)hConstraint vConstraint: (NSLayoutConstraint*) vConstraint forIndex: (NSUInteger) index {
    
    NSUInteger itemsPerLine = self.itemsPerLine;
    
    NSUInteger widthMargin = _justify ? (self.bounds.size.width - 2.0*self.outlineMargin - (itemsPerLine * _tileWidth)) / (itemsPerLine-1) : _tileMargin;

    NSUInteger lineNumber = floorf((float)index/(float)itemsPerLine);
    
    NSInteger hOffset = self.outlineMargin + (_tileWidth + widthMargin) * (index - lineNumber*itemsPerLine);
    
    NSInteger vOffset = (lineNumber==0 && _showOutline) ? self.outlineMargin : lineNumber*(_tileWidth+_tileMargin);

#pragma message "TODO: fix constraint limits to ? hardware?"
    if (vOffset < 0) {
        NSAssert(YES, @"Constraint out of range");
    }
    hOffset = hOffset < 0 ? 0 : hOffset;
    vOffset = vOffset < 0 ? 0 : vOffset;
    hOffset = hOffset > 1024 ? 1024 : hOffset;
    vOffset = vOffset > 1024 ? 1024 : vOffset;
    
    hConstraint.constant = hOffset;
    vConstraint.constant = vOffset;
}