Skip to content

Commit 4ce827b

Browse files
committed
fix: auto fit columns in search-on-server results, taking the header caption into account
1 parent ac095e4 commit 4ce827b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

source/lazaruscompat.pas

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
interface
66

77
uses
8-
Classes, SysUtils, SynEdit, SynEditKeyCmds, SynEditHighlighter, laz.VirtualTrees;
8+
Classes, SysUtils, SynEdit, SynEditKeyCmds, SynEditHighlighter, laz.VirtualTrees,
9+
Graphics;
910

1011
type
1112

@@ -27,6 +28,12 @@ TSynHighlighterAttributesHelper = class helper for TSynHighlighterAttributes
2728
procedure AssignColorAndStyle(Source: TSynHighlighterAttributes);
2829
end;
2930

31+
TVTHeaderHelper = class helper for TVTHeader
32+
public
33+
// AutoFitColumns version which takes the header caption into account
34+
procedure AutoFitColumnsWithHeaderMin;
35+
end;
36+
3037
TStringsHelper = class helper for TStrings
3138
public
3239
function Contains(const S: String): Boolean;
@@ -218,6 +225,27 @@ procedure TSynHighlighterAttributesHelper.AssignColorAndStyle(Source: TSynHighli
218225
Changed;
219226
end;
220227

228+
procedure TVTHeaderHelper.AutoFitColumnsWithHeaderMin;
229+
var
230+
cnv: TCanvas;
231+
c: Integer;
232+
CapWidth: Integer;
233+
ws: String;
234+
ExtraPad: Integer;
235+
begin
236+
cnv := Treeview.Canvas;
237+
ExtraPad := 5;
238+
for c:=0 to Columns.Count - 1 do begin
239+
ws := Columns[c].Text;
240+
if ws <> '' then begin
241+
CapWidth := cnv.TextWidth(ws);
242+
Columns[c].MinWidth := CapWidth + (Columns[c].Margin * 2) + ExtraPad;
243+
end;
244+
end;
245+
// now let VST auto-fit using node content, but not below header-based MinWidth
246+
AutoFitColumns(False);
247+
end;
248+
221249
function TStringsHelper.Contains(const S: String): Boolean;
222250
begin
223251
Result := IndexOf(S) >= 0;

source/tabletools.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ procedure TfrmTableTools.UpdateResultGrid;
14541454
f_('%s%% done', [FormatNumber(Percent, 1)]) + '.';
14551455
MainForm.SetProgressPosition(Round(Percent));
14561456
MainForm.ShowStatusMsg(Format(StatusMsg, [tabsTools.ActivePage.Caption, FormatTimeNumber((GetTickCount64-FStartTimeAll)/1000, True)]));
1457-
ResultGrid.Header.AutoFitColumns(False);
1457+
ResultGrid.Header.AutoFitColumnsWithHeaderMin;
14581458
Application.ProcessMessages;
14591459
end;
14601460

0 commit comments

Comments
 (0)