4

I want to find the "best way" to zoom-in /zoom-out a TVirtualStringTree.
"Zoom-in" means mimic a magnifying glass.
"best way" must be understood by using, in priority, properties /methods that are devoted to this in the TVirtualStringTree control. If no methods exist, then propose the simpliest way, avoiding low level API's.

As to better explain this question,
Here is a screenshot of the TVirtualStringTree in its initial state: initial state http://didier.cabale.free.fr/temp/VST1.jpg.
.. and here is a screenshot of the TVirtualStringTree in its wanted state: wanted state http://didier.cabale.free.fr/temp/VST2.jpg

Didier Cabalé
  • 385
  • 3
  • 10
  • off-topic here, but may I ask the moderator why my question has been downvoted. Anyway, it could help to improve the interest of my future requests. Thanks – Didier Cabalé Mar 28 '16 at 09:15

1 Answers1

5

Dear Didier (my idem ego),

here is what I did:
Important note: this is what I did, but I'm not sure this is the optimal solution, thus any new ideas are more than welcome!!

A. In a same event Handler (eg Edit's OnChange).

  1. set the Font.Size of the TVirtualStringTree Header:

    VirtualStringTree1.Header.Font.Size := UpDown1.Position;
    
  2. set the Font.Size of the TVirtualStringTree nodes:

    VirtualStringTree1.Font.Size := UpDown1.Position;
    
  3. set the Height of the TVirtualStringTree Header:

    VirtualStringTree1.Header.Height := Round(VirtualStringTree1.Header.Height * Delta);
    
  4. set the column's Width of the TVirtualStringTree Header:

    for i := 0 to VirtualStringTree1.Header.Columns.Count -1 do
      VirtualStringTree1.Header.Columns.Items[i].Width := Round(VirtualStringTree1.Header.Columns.Items[i].Width * Delta);
    

B. On TVirtualStringTree's OnMeasureTextHeight event Handler, set its NodeHeight[Node] property:

  Sender.NodeHeight[Node] := Round(Extent * 1.1);

C. set TVirtualStringTree's toAutoChangeScale to false in Object Inspector.

All put together, it gives:

procedure TForm1.Edit3Change(Sender: TObject);
var
  Delta: Double;
  i: byte;
begin
  Delta := UpDown1.Position / VirtualStringTree1.Font.Size;
  VirtualStringTree1.BeginUpdate();
  try
  VirtualStringTree1.Font.Size        := UpDown1.Position;
  VirtualStringTree1.Header.Font.Size := UpDown1.Position;
  VirtualStringTree1.Header.Height := Round(VirtualStringTree1.Header.Height * Delta);
  for i := 0 to VirtualStringTree1.Header.Columns.Count -1 do
    VirtualStringTree1.Header.Columns.Items[i].Width := Round(VirtualStringTree1.Header.Columns.Items[i].Width * Delta);
  finally
    VirtualStringTree1.EndUpdate();
  end;
end;

procedure TForm1.VirtualStringTree1MeasureTextHeight(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  const Text: string; var Extent: Integer);
begin
  Sender.NodeHeight[Node] := Round(Extent * 1.1);
end;
Didier Cabalé
  • 385
  • 3
  • 10