Page 1 of 1

Autosize/autofit TTree objects- any solution yet?

Posted: Mon Mar 24, 2008 10:18 am
by 10545670
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

Posted: Mon Mar 31, 2008 6:32 pm
by Tom
Hi Keith,

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

Thanks,
Tom.

Posted: Tue Apr 01, 2008 12:20 pm
by 10545670
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

Posted: Thu Apr 03, 2008 7:03 am
by 9237935
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

Posted: Wed Apr 23, 2008 6:01 pm
by 10545670
Hi Markus,

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



Regards,

Keith Blows