Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 2438

Summary: Change Percent width calculation to use remainder of the total width instead of full width
Product: TeeGrid for Delphi Reporter: dean.mustakinov
Component: GridAssignee: david berneda <david>
Status: UNCONFIRMED ---    
Severity: enhancement    
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Chart Series: --- Delphi / C++ Builder RAD IDE Version:

Description dean.mustakinov 2021-06-25 00:11:28 EDT
When grid calculates the width of the column that is using the Percent then it calculates the width as percent of total available width.
If there are fixed or auto calculated width columns mixed with Percent width columns this can cause total width to be greater than max width of the grid.
Percent calculation should happen on the remainder of total width after all of the fixed and auto width columns have been calculated.
This is going to useful when there are one or two percent columns that should take up the remainder of available width.

I have made this change in Tee.Grid.RowGroup.pas (my changes are commented with // DM CHANGE):
procedure TRowGroup.CheckColumnsWidth(const APainter:TPainter; const Forced:Boolean;
                                      const AWidth:Single);

  // Collection of columns
  function Check(const AColumns:TColumns):Single;
  var TotWidth: Single; // DM CHANGE

    // Single column
    procedure Calculate(const AColumn:TColumn);
    begin
      if AColumn.Width.Automatic then
      begin
        if AColumn.HasItems then
        begin
          TColumnWidthAccess(AColumn.Width).IPixels:=Check(AColumn.Items); // <-- recursive
          AColumn.ValidWidth:=True;
        end
        else
        if Forced or (not AColumn.ValidWidth) then
           DoCalcWidth(APainter,AColumn,TotWidth); // DM CHANGE
      end
      else
      if AColumn.Width.Units=TSizeUnits.Percent then
         DoCalcWidth(APainter,AColumn,TotWidth); // DM CHANGE
    end;

  var t : Integer;
      tmp : TColumn;
  begin
    result:=0;

    // DM CHANGE START
    TotWidth := AWidth;
    for t:=0 to AColumns.Count-1 do
    begin
      tmp:=AColumns[t];

      if tmp.Visible and (tmp.Width.Units=TSizeUnits.Pixels) then // DM CHANGE
      begin
        Calculate(tmp);

        result:=result+tmp.Width.Pixels;
      end;
    end;

    // // DM CHANGE - calc percent width on remainder
    TotWidth := AWidth - result;
    for t:=0 to AColumns.Count-1 do
    begin
      tmp:=AColumns[t];

      if tmp.Visible and (tmp.Width.Units=TSizeUnits.Percent) then
      begin
        Calculate(tmp);

        result:=result+tmp.Width.Pixels;
      end;
    end;
    // DM CHANGE END
  end;

begin
  Check(Columns);
  Columns.ValidWidth:=True;
end;