Related topic for this question is http://www.trichview.com/forums/viewtop ... f=2&t=8709
Now I want to implement SetTableBestFit for the table. As you can see from the source topic, some columns are wider than required and they should be make narrower. So my procedure calcs the content width for each cell in each column (using TCustomRichView.GetItemCoordsEx), puts values into an array of integer (ColsWidth) and then sets BestWidth of all columns to values from the array (Table.Cells[0, c].BestWidth := ColsWidth[c]). And I also set BestWidth to the table:
Code: Select all
Table.BestWidth := SumColsWidth(Table, ColsWidth);
class function TForm1.SumColsWidth(Table: TRVTableItemInfo; ColsWidth:
TIntegerDynArray): Integer;
var
c: Integer;
begin
Result := 0;
for c in ColsWidth do
Result := Result + c;
if Table.ColCount > 0 then
Result := Result + Table.CellBorderWidth * 2 * Table.ColCount;
end;
When I calculate width of cell items I also increase the result by Width := Width + Table.CellHPadding + Table.CellBorderWidth * 2; (remember that this value is going to be set to Table.Cells[0, c].BestWidth as I described above).
Are these correction that I do in SumColsWidth (Result := Result + Table.CellBorderWidth * 2 * Table.ColCount) and in column's width calculation (Width := Width + Table.CellHPadding + Table.CellBorderWidth * 2) neccessary and adequate for values that are going to be set to Cell.BestWidth and Table.BestWidth? Although the table looks good, I might miss something and the table with other settings like border width, paddigns and spacings will not look in the way I want (word breaks will differ)