TLayoutManager

Source: source/classes/Tlayman.prg

Standalone class

TLayoutManager provides resolution-independent layout calculations. It scales positions, sizes, and font sizes based on a reference screen resolution, enabling UIs that adapt to different display sizes. Supports grid-style positioning with configurable margins and spacing.

Key DATA Members

DATATypeDescription
nScreenWidth/HeightNumericCurrent screen resolution
nBaseWidth/HeightNumericReference resolution (e.g., 1280x800)
nSpacingNumericSpacing between controls in grid layout
nMarginTop/Left/Right/BottomNumericMargins around the usable area

Methods

MethodDescription
New( nScreenW, nScreenH, nBaseW, nBaseH, nSpacing, nMarginT, nMarginL, nMarginR, nMarginB )Create a layout manager
CalcSize( nBaseSize )Scale a size using the minimum screen/base factor
CalcPos( nBasePos )Scale a position adding margins
CalcGridPos( nIndex, nItemsPerRow, nBaseW, nBaseH, nBaseTop, nBaseLeft )Grid position for item at index; returns { nTop, nLeft, nWidth, nHeight }
CalcFontSize( nBaseFontSize )Scale a font size proportionally
GetUsableWidth() / GetUsableHeight()Return usable area excluding margins

Example: Grid Layout

#include "FiveWin.ch"
function Main()
   local oLayout, nW, nH, aPos, n
   nW := GetSysMetrics( 0 )
   nH := GetSysMetrics( 1 )
   oLayout := TLayoutManager():New( nW, nH, 1280, 800, 10, 20, 20, 20, 20 )
   for n := 1 to 6
      aPos := oLayout:CalcGridPos( n, 3, 200, 100, 50, 50 )
   next
return nil

Notes

See Also