Autosize/autofit TTree objects- any solution yet?

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
keithblo
Newbie
Newbie
Posts: 12
Joined: Mon Jun 25, 2007 12:00 am

Autosize/autofit TTree objects- any solution yet?

Post by keithblo » Mon Mar 24, 2008 10:18 am

Support,

Is there any way to automatically re-size all shapes within a TTree proportionately, to ensure they are visible and fit within within the TTree control bounds without scrolling, when the TTree control is resized at runtime?


Kind Regards,

Keith

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Mon Mar 31, 2008 6:32 pm

Hi Keith,

Do you mean zoom/unzoom the panel or really re-sizing all shapes?

Thanks,
Tom.

keithblo
Newbie
Newbie
Posts: 12
Joined: Mon Jun 25, 2007 12:00 am

Post by keithblo » Tue Apr 01, 2008 12:20 pm

Hi Tom,

On the user resizing the panel, I want the panel to resize all controls within the panel proportionately. All controls should 'autofit' within the panel's new dimensions.


Regards,

Keith

iamjoosy
Newbie
Newbie
Posts: 3
Joined: Thu Aug 04, 2005 4:00 am
Location: Germany

Post by iamjoosy » Thu Apr 03, 2008 7:03 am

Hi Keith and Tom,

since I was struggling with this for quite some time, here is the solution which works sufficiently well for us:

in the onResize handler of a TTree add the follwing code:

Code: Select all

if not calcContentSize then
      begin
        // the content size is independent of the zoom factor
        hCont:=getTreeContentHeight;
        wCont:=getTreeContentWidth;
      end else
      begin
        bound:=Rect(high(integer), high(integer), low(integer), low(integer));
        for i:=0 to FTree.Roots.Count-1 do
        begin
          bound.Left:=min(bound.Left, FTree.Roots[i].X0);
          bound.Top:=min(bound.Top, FTree.Roots[i].Y0);
          bound.Right:=max(bound.Right, FTree.Roots[i].X0+FTree.Roots[i].Width);
          bound.Bottom:=max(bound.Bottom, FTree.Roots[i].Y0+FTree.Roots[i].Height);
        end;
        if bound.Right<>low(integer) then
          wCont:=bound.Right;
        if bound.Bottom<>low(integer) then
          hCont:=bound.Bottom;
      end;

      if abs(hCont)+abs(wCont)=0 then
        exit;
      FTree.BeginUpdate;
      try
        z1:=FTree.height/hCont*100;
        z2:=FTree.width/wCont*100;
        zoom:=min(z1,z2);
        FTree.View3DOptions.Zoom:=trunc(zoom);

        FTree.View3DOptions.HorizOffset:=round((FTree.Width/2-wCont/2)*FTree.View3DOptions.Zoom*0.01);
        FTree.View3DOptions.VertOffset:=round((FTree.Height/2-hCont/2)*FTree.View3DOptions.Zoom*0.01);
      finally
        FTree.EndUpdate;
      end;

function getTreeContentWidth:integer;
begin
  result:=FTree.TotalBounds.Right-FTree.TotalBounds.Left;
end;

function getTreeContentHeight:integer;
begin
  result:=FTree.TotalBounds.Bottom-FTree.TotalBounds.Top;
end;
Sorry, if that code is a bit out of context, but it is part of some larger code ... you should get the idea, if not let me know.

Best

Markus

keithblo
Newbie
Newbie
Posts: 12
Joined: Mon Jun 25, 2007 12:00 am

Post by keithblo » Wed Apr 23, 2008 6:01 pm

Hi Markus,

Thank you very much for your code- it works beautifully!



Regards,

Keith Blows

Post Reply