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
| DATA | Type | Description |
|---|---|---|
nScreenWidth/Height | Numeric | Current screen resolution |
nBaseWidth/Height | Numeric | Reference resolution (e.g., 1280x800) |
nSpacing | Numeric | Spacing between controls in grid layout |
nMarginTop/Left/Right/Bottom | Numeric | Margins around the usable area |
Methods
| Method | Description |
|---|---|
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
- Scaling uses
Min( screen / base )to maintain aspect ratio. CalcGridPosreturns{ nTop, nLeft, nWidth, nHeight }for direct control positioning.- All positions are computed relative to margins, inside the usable area.