FIgured out that we need to ignore spanning cells; added support for that. Not yet perfect; still need to do a bit more...
This commit is contained in:
parent
7908972d34
commit
0ce4fd6efd
|
@ -142,9 +142,11 @@ struct uiGrid {
|
||||||
BOOL first;
|
BOOL first;
|
||||||
int **gg;
|
int **gg;
|
||||||
NSView ***gv;
|
NSView ***gv;
|
||||||
|
BOOL **gspan;
|
||||||
intmax_t x, y;
|
intmax_t x, y;
|
||||||
int i;
|
int i;
|
||||||
NSLayoutConstraint *c;
|
NSLayoutConstraint *c;
|
||||||
|
intmax_t firstx, firsty;
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
if ([self->children count] == 0)
|
if ([self->children count] == 0)
|
||||||
|
@ -175,17 +177,23 @@ struct uiGrid {
|
||||||
ycount = ymax - ymin;
|
ycount = ymax - ymin;
|
||||||
|
|
||||||
// now build a topological map of the grid gg[y][x]
|
// now build a topological map of the grid gg[y][x]
|
||||||
|
// also figure out which cells contain spanned views so they can be ignored later
|
||||||
gg = (int **) uiAlloc(ycount * sizeof (int *), "int[][]");
|
gg = (int **) uiAlloc(ycount * sizeof (int *), "int[][]");
|
||||||
|
gspan = (BOOL **) uiAlloc(ycount * sizeof (BOOL *), "BOOL[][]");
|
||||||
for (y = 0; y < ycount; y++) {
|
for (y = 0; y < ycount; y++) {
|
||||||
gg[y] = (int *) uiAlloc(xcount * sizeof (int), "int[]");
|
gg[y] = (int *) uiAlloc(xcount * sizeof (int), "int[]");
|
||||||
|
gspan[y] = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]");
|
||||||
for (x = 0; x < xcount; x++)
|
for (x = 0; x < xcount; x++)
|
||||||
gg[y][x] = -1; // empty
|
gg[y][x] = -1; // empty
|
||||||
}
|
}
|
||||||
for (i = 0; i < [self->children count]; i++) {
|
for (i = 0; i < [self->children count]; i++) {
|
||||||
gc = (gridChild *) [self->children objectAtIndex:i];
|
gc = (gridChild *) [self->children objectAtIndex:i];
|
||||||
for (y = gc.top; y < gc.top + gc.yspan; y++)
|
for (y = gc.top; y < gc.top + gc.yspan; y++)
|
||||||
for (x = gc.left; x < gc.left + gc.xspan; x++)
|
for (x = gc.left; x < gc.left + gc.xspan; x++) {
|
||||||
gg[y - ymin][x - xmin] = i;
|
gg[y - ymin][x - xmin] = i;
|
||||||
|
if (x != gc.left || y != gc.top)
|
||||||
|
gspan[y - ymin][x - xmin] = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now build a topological map of the grid's views gv[y][x]
|
// now build a topological map of the grid's views gv[y][x]
|
||||||
|
@ -241,9 +249,16 @@ struct uiGrid {
|
||||||
}
|
}
|
||||||
|
|
||||||
// now align leading and top edges
|
// now align leading and top edges
|
||||||
for (x = 0; x < xcount; x++)
|
// do NOT align spanning cells!
|
||||||
for (y = 1; y < ycount; y++) {
|
for (x = 0; x < xcount; x++) {
|
||||||
c = mkConstraint(gv[0][x], NSLayoutAttributeLeading,
|
for (y = 0; y < ycount; y++)
|
||||||
|
if (!gspan[y][x])
|
||||||
|
break;
|
||||||
|
firsty = y;
|
||||||
|
for (y++; y < ycount; y++) {
|
||||||
|
if (gspan[y][x])
|
||||||
|
continue;
|
||||||
|
c = mkConstraint(gv[firsty][x], NSLayoutAttributeLeading,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
gv[y][x], NSLayoutAttributeLeading,
|
gv[y][x], NSLayoutAttributeLeading,
|
||||||
1, 0,
|
1, 0,
|
||||||
|
@ -251,9 +266,16 @@ struct uiGrid {
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->edges addObject:c];
|
[self->edges addObject:c];
|
||||||
}
|
}
|
||||||
for (y = 0; y < ycount; y++)
|
}
|
||||||
for (x = 1; x < xcount; x++) {
|
for (y = 0; y < ycount; y++) {
|
||||||
c = mkConstraint(gv[y][0], NSLayoutAttributeTop,
|
for (x = 0; x < xcount; x++)
|
||||||
|
if (!gspan[y][x])
|
||||||
|
break;
|
||||||
|
firstx = x;
|
||||||
|
for (x++; x < xcount; x++) {
|
||||||
|
if (gspan[y][x])
|
||||||
|
continue;
|
||||||
|
c = mkConstraint(gv[y][firstx], NSLayoutAttributeTop,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
gv[y][x], NSLayoutAttributeTop,
|
gv[y][x], NSLayoutAttributeTop,
|
||||||
1, 0,
|
1, 0,
|
||||||
|
@ -261,6 +283,7 @@ struct uiGrid {
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->edges addObject:c];
|
[self->edges addObject:c];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// now string adjacent views together
|
// now string adjacent views together
|
||||||
for (y = 0; y < ycount; y++)
|
for (y = 0; y < ycount; y++)
|
||||||
|
@ -292,9 +315,11 @@ struct uiGrid {
|
||||||
for (y = 0; y < ycount; y++) {
|
for (y = 0; y < ycount; y++) {
|
||||||
uiFree(gg[y]);
|
uiFree(gg[y]);
|
||||||
uiFree(gv[y]);
|
uiFree(gv[y]);
|
||||||
|
uiFree(gspan[y]);
|
||||||
}
|
}
|
||||||
uiFree(gg);
|
uiFree(gg);
|
||||||
uiFree(gv);
|
uiFree(gv);
|
||||||
|
uiFree(gspan);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)append:(gridChild *)gc
|
- (void)append:(gridChild *)gc
|
||||||
|
|
Loading…
Reference in New Issue