diff --git a/adjacent.m b/adjacent.m new file mode 100644 index 00000000..5bf80468 --- /dev/null +++ b/adjacent.m @@ -0,0 +1,40 @@ + // now find all horizontally adjacent views and string them together + for (y = 0; y < ycount; y++) + for (x = 0; x < xcount - 1; x++) { + if (gg[y][x] == -1) + continue; + if (gg[y][x + 1] == -1) + continue; + if (gg[y][x] == gg[y][x + 1]) // spanning + continue; + gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; + firstView = [gc view]; + gc = (gridChild *) [self->children objectAtIndex:gg[y][x + 1]]; + c = mkConstraint(firstView, NSLayoutAttributeTrailing, + NSLayoutRelationEqual, + [gc view], NSLayoutAttributeLeading, + 1, -padding, + @"uiGrid inside trailing attribute"); + [self addConstraint:c]; + [self->inBetweens addObject:c]; + } + // and same for vertically adjacent + for (x = 0; x < xcount; x++) + for (y = 0; y < ycount - 1; y++) { + if (gg[y][x] == -1) + continue; + if (gg[y + 1][x] == -1) + continue; + if (gg[y][x] == gg[y + 1][x]) // spanning + continue; + gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; + firstView = [gc view]; + gc = (gridChild *) [self->children objectAtIndex:gg[y + 1][x]]; + c = mkConstraint(firstView, NSLayoutAttributeBottom, + NSLayoutRelationEqual, + [gc view], NSLayoutAttributeTop, + 1, -padding, + @"uiGrid inside bottom attribute"); + [self addConstraint:c]; + [self->inBetweens addObject:c]; + } diff --git a/reduce.m b/reduce.m new file mode 100644 index 00000000..e3c9b676 --- /dev/null +++ b/reduce.m @@ -0,0 +1,30 @@ + // if a row or column only contains emptys and spanning cells of a opposite-direction spannings, remove it by duplicating the previous row or column + BOOL onlyEmptyAndSpanning; + for (y = 0; y < ycount; y++) { + onlyEmptyAndSpanning = YES; + for (x = 0; x < xcount; x++) + if (gg[y][x] != -1) { + gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; + if (gc.yspan == 1 || gc.top - ymin == y) { + onlyEmptyAndSpanning = NO; + break; + } + } + if (onlyEmptyAndSpanning) + for (x = 0; x < xcount; x++) + gg[y][x] = gg[y - 1][x]; + } + for (x = 0; x < xcount; x++) { + onlyEmptyAndSpanning = YES; + for (y = 0; y < ycount; y++) + if (gg[y][x] != -1) { + gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; + if (gc.xspan == 1 || gc.left - xmin == x) { + onlyEmptyAndSpanning = NO; + break; + } + } + if (onlyEmptyAndSpanning) + for (y = 0; y < ycount; y++) + gg[y][x] = gg[y][x - 1]; + }