TMetroPanel

Source: source/classes/metropnl.prg

Inherits from: TPanel

TMetroPanel implements a Windows 8-style Metro start panel with tile groups that scroll horizontally. It arranges TMetroBtn tiles into groups and rows, providing a touch-friendly interface with drag-to-scroll, mouse-wheel support, and a custom scrollbar. Each tile can be a large or small button with an image, caption, and action. TMetroBtn (child class from TBtnBmp) represents an individual Metro tile with configurable alignment, text overlay, and group membership.

Key DATA Members

DATATypeDescription
aButtonsArrayArray of TMetroBtn tile objects
nOffsetNumericCurrent horizontal scroll offset in pixels
nBtnSizeNumericBase tile size in pixels (default 132)
nMetroRowsNumericNumber of tile rows based on screen height
nGroupsNumericNumber of tile groups (auto-calculated from buttons)
nScrollRangeNumericMaximum horizontal scroll extent
nScrollRatioNumericRatio for thumb-to-content scroll mapping
cTitleCharacterPanel title displayed at the top
lDesignModeLogicalEnable design-time interaction
lArrangedLogicalWhether tiles have been positioned
nClrScrollNumericScrollbar track color
nClrThumbNumericScrollbar thumb color

TMetroBtn Class (Child of TMetroPanel)

DATATypeDescription
nGroupNumericGroup index to which this tile belongs (default 1)
lLargeLogicalIf .T., tile spans 2 column widths (double-wide)
cCaptionCharacterMain caption displayed on the tile
cTextCharacterSecondary text displayed below the caption
nCapAlignNumericCaption text alignment (default DT_TOP + DT_RIGHT)
nBmpAlignNumericBitmap alignment (default DT_BOTTOM + DT_LEFT)
nClrCaptionNumericCaption text color
bOnMoveBlockCode block executed when tile is moved

Methods

MethodDescription
New( oWnd, cTitle, nClrText, nClrPane, bLClicked, nBtnSize, nClrThumb, nClrScroll )Create a new Metro panel
AddButton( lLarge, nGroup, cCaption, bAction, nClrText, nClrPane, cImgName, oFont, nAlign, nBmpAlign, nBmpW, nBmpH, cText, nTextAlign, oTextFont, oSubMetro, cBackImage, cAction, cSub )Add a TMetroBtn tile to the panel. Returns the button object.
Arrange( lReArrange )Position all tiles into rows and groups. Set lReArrange=.T. to force re-layout.
Slide( nPixels )Slide the panel horizontally by nPixels. Negative values scroll right.
SwitchTo( oNext )Animate switch to a different Metro panel
MoveBtn( oBtnDrag, oBtnOver )Move a tile from one position to another within the panel
ProgramCode( lShow )Generate source code for the current panel design
MouseWheel( nKey, nDelta, nXPos, nYPos )Handle mouse wheel scrolling

Example: Metro Panel with Two Groups

#include "FiveWin.ch"

function Main()

   local oWnd, oMetro

   DEFINE WINDOW oWnd TITLE "Metro Panel" SIZE 800, 600

   DEFINE METROPANEL oMetro OF oWnd TITLE "Start" ;
      COLOR CLR_WHITE, RGB( 30, 30, 120 ) ;
      ON CLICK oWnd:End()

   // Group 1: Communication tiles
   oMetro:AddButton( .T., 1, "Email", { || MsgInfo( "Email" ) }, ;
                     CLR_WHITE, RGB( 0, 120, 200 ),, , , , 64, 64 )

   oMetro:AddButton( .F., 1, "Calendar", { || MsgInfo( "Calendar" ) }, ;
                     CLR_WHITE, RGB( 200, 50, 50 ) )

   // Group 2: Productivity tiles
   oMetro:AddButton( .T., 2, "Documents", { || MsgInfo( "Docs" ) }, ;
                     CLR_WHITE, RGB( 50, 150, 50 ),, , , , 64, 64 )

   oMetro:AddButton( .F., 2, "Settings", { || MsgInfo( "Settings" ) }, ;
                     CLR_WHITE, RGB( 80, 80, 80 ) )

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

Notes

See Also