fit() public method

Fits the added cells into the given maximum total width with the given number of columns.
public fit ( integer $maxTotalWidth, integer $nbColumns, Webmozart\Console\Api\Formatter\Formatter $formatter )
$maxTotalWidth integer The maximum total width of the columns.
$nbColumns integer The number of columns to use.
$formatter Webmozart\Console\Api\Formatter\Formatter The formatter used to remove style tags.
Example #1
0
 private function getCellWrapper(Formatter $formatter, $screenWidth, $excessColumnWidth, $indentation)
 {
     $borderStyle = $this->style->getBorderStyle();
     $borderWidth = StringUtil::getLength($borderStyle->getLineVLChar()) + ($this->nbColumns - 1) * StringUtil::getLength($borderStyle->getLineVCChar()) + StringUtil::getLength($borderStyle->getLineVRChar());
     $availableWidth = $screenWidth - $indentation - $borderWidth - $this->nbColumns * $excessColumnWidth;
     $wrapper = new CellWrapper();
     foreach ($this->headerRow as $headerCell) {
         $wrapper->addCell($headerCell);
     }
     foreach ($this->rows as $row) {
         foreach ($row as $cell) {
             $wrapper->addCell($cell);
         }
     }
     $wrapper->fit($availableWidth, $this->nbColumns, $formatter);
     return $wrapper;
 }
Example #2
0
 private function getCellWrapper(Formatter $formatter, $screenWidth, $excessColumnWidth, $indentation)
 {
     $borderStyle = $this->style->getBorderStyle();
     $wrapper = new CellWrapper();
     foreach ($this->cells as $cell) {
         $wrapper->addCell($cell);
     }
     $nbColumns = min($this->maxNbColumns, $wrapper->getEstimatedNbColumns($screenWidth));
     do {
         $borderWidth = StringUtil::getLength($borderStyle->getLineVLChar()) + ($nbColumns - 1) * StringUtil::getLength($borderStyle->getLineVCChar()) + StringUtil::getLength($borderStyle->getLineVRChar());
         $availableWidth = $screenWidth - $indentation - $borderWidth - $nbColumns * $excessColumnWidth;
         $wrapper->fit($availableWidth, $nbColumns, $formatter);
         --$nbColumns;
     } while ($wrapper->hasWordCuts() && $nbColumns >= $this->minNbColumns);
     return $wrapper;
 }