Fixed sizeToFit

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11347 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2001-11-08 22:48:58 +00:00
parent 611005755b
commit fdb1fa74af

View file

@ -1638,34 +1638,50 @@ static SEL getSel;
newSize.height = nr * (_cellSize.height + _intercell.height) - _intercell.height; newSize.height = nr * (_cellSize.height + _intercell.height) - _intercell.height;
[self setFrameSize: newSize]; [self setFrameSize: newSize];
} }
- (void) sizeToFit - (void) sizeToFit
{ {
/*
* A simple explanation of the logic behind this method.
*
* Example of when you would like to use this method:
* you have a matrix containing radio buttons. Say that you have the
* following radio buttons -
*
* * First option
* * Second option
* * Third option
* * No thanks, no option for me
*
* this method should size the matrix so that it can comfortably
* show all the cells it contains. To do it, we must consider that
* all the cells should be given the same size, yet some cells need
* more space than the others to show their contents, so we need to
* choose the cell size as to be enough to display every cell. We
* loop on all cells, call cellSize on each (which returns the
* *minimum* comfortable size to display that cell), and choose a
* final cellSize which is enough big to be bigger than all these
* cellSizes. We resize the matrix to have that cellSize, and
* that's it. */
NSSize newSize = NSZeroSize; NSSize newSize = NSZeroSize;
/*
* FIXME : Maybe this code be enabled in debug mode ?
* it would detect if all the cells have the same size
* or not
NSSize tmpSize;
int i, j; int i, j;
for (i = 0; i < _numRows; i++) for (i = 0; i < _numRows; i++)
{ {
for (j = 0; j < _numCols; j++) for (j = 0; j < _numCols; j++)
{ {
tmpSize = [_cells[i][j] cellSize]; NSSize tempSize = [_cells[i][j] cellSize];
if (tmpSize.width > newSize.width) if (tempSize.width > newSize.width)
newSize.width = tmpSize.width; {
if (tmpSize.height > newSize.height) newSize.width = tempSize.width;
newSize.height = tmpSize.height; }
if (tempSize.height > newSize.height)
{
newSize.height = tempSize.height;
}
} }
} }
*/
if (_numRows > 0 && _numCols > 0)
newSize = [_cells[0][0] cellSize];
[self setCellSize: newSize]; [self setCellSize: newSize];
} }