TLayout - Layout Manager

Source: source/classes/tlayout.prg

TLayout inherits from TPanel and provides automatic arrangement of child controls in horizontal or vertical layouts. When the parent window is resized, TLayout repositions its children according to the defined layout rules. The class maintains arrays of horizontal and vertical layout definitions (aHLayout, aVLayout) and fires the bOnResize codeblock when the layout is recalculated.

Inheritance

classDiagram TPanel <|-- TLayout class TLayout { +bOnResize +aHLayout +aVLayout +New(oWnd) +addHLayout(nW) +addVLayout(nH) +onResized(nType, nW, nH) }

DATA Members

DATATypeDescription
bOnResizeCodeblockCodeblock evaluated when the layout is recalculated after a resize
aHLayoutArrayArray of horizontal layout pane definitions (width ratios or fixed sizes)
aVLayoutArrayArray of vertical layout pane definitions (height ratios or fixed sizes)

Methods

MethodDescription
New( oWnd )Create a TLayout manager associated with window oWnd
addHLayout( nW )Add a horizontal split pane with proportional width nW
addVLayout( nH )Add a vertical split pane with proportional height nH
onResized( nType, nW, nH )Called when the parent window is resized; recalculates child positions

Example: Horizontal Split Layout

#include "FiveWin.ch"

function Main()

   local oWnd, oLayout, oLeft, oRight

   DEFINE WINDOW oWnd TITLE "Layout Demo" ;
      SIZE 800, 600

   oLayout := TLayout():New( oWnd )

   // Define two horizontal panes (left 30%, right 70%)
   oLayout:addHLayout( .3 )
   oLayout:addHLayout( .7 )

   // Create child controls in each pane
   @ 0, 0 SAY oLeft  PROMPT "Left Panel"  ;
      OF oWnd SIZE 240, 600 PIXEL

   @ 0, 0 SAY oRight PROMPT "Right Panel" ;
      OF oWnd SIZE 560, 600 PIXEL

   oLayout:bOnResize := {|nW, nH| ;
      oLeft:nWidth   := Int( nW * .3 ), ;
      oRight:nLeft   := Int( nW * .3 ), ;
      oRight:nWidth  := Int( nW * .7 ) }

   ACTIVATE WINDOW oWnd

return nil

See Also